简体   繁体   English

使用system.out.println打印包含int值的数组

[英]Printing an array containing int values with system.out.println

I am trying to display an array using System.out.println , but I constantly get an warning message when Eclipse is trying to run the code: 我正在尝试使用System.out.println显示数组,但是当Eclipse尝试运行代码时,我不断收到警告消息:

"An internal error has occured", and under "Details": -java.lang.NullPointerException “发生内部错误”,在“详细信息”下:-java.lang.NullPointerException

Here is the code: 这是代码:

import java.util.Arrays;

public class testerArray {
    public static void main(String[] args) {
        int [] test = {-1, -1, -1, -1};     
        System.out.println(java.util.Arrays.toString(test));
    }
}

I have searched many solutions on this site, but I must have become blind, because I can´t see what I do different from the examples used on the answers on this site. 我已经在该站点上搜索了许多解决方案,但是我一定已经变得盲目了,因为我看不出自己所做的工作与该站点的答案所使用的示例有所不同。 What do I do wrong? 我做错了什么?

Here is the stacktrace: 这是堆栈跟踪:

java.lang.NullPointerException
at org.eclipse.ui.part.PageBookView.showPageRec(PageBookView.java:1000)
atorg.eclipse.ui.internal.console.ConsoleView.showPageRec(ConsoleView.ava:171)
at org.eclipse.ui.part.PageBookView.partActivated(PageBookView.java:779)
at org.eclipse.ui.internal.console.ConsoleView.display(ConsoleView.java:531)
at org.eclipse.ui.internal.console.ConsoleManager$ShowConsoleViewJob.runInUIThread(ConsoleManager.java:313)
at org.eclipse.ui.progress.UIJob$1.run(UIJob.java:97)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:136)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3983)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3660)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:236)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.lang.NullPointerException
at org.eclipse.ui.part.PageBookView.showPageRec(PageBookView.java:1000)
at org.eclipse.ui.internal.console.ConsoleView.showPageRec(ConsoleView.java:171)
at org.eclipse.ui.part.PageBookView.partActivated(PageBookView.java:779)
at org.eclipse.ui.internal.console.ConsoleView.display(ConsoleView.java:531)
at org.eclipse.ui.internal.console.ConsoleManager$ShowConsoleViewJob.runInUIThread(ConsoleManager.java:313)
at org.eclipse.ui.progress.UIJob$1.run(UIJob.java:97)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:136)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3983)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3660)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:236)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)

That looks more like an Eclipse problem than a code problem(in the stacktrace, you will see that the origin from the problem is in Eclipse classes). 这看起来更像是Eclipse问题,而不是代码问题(在stacktrace中,您将看到问题的根源在Eclipse类中)。 Why don't you try to run this file without Eclipse? 您为什么不尝试在没有Eclipse的情况下运行此文件? http://www.cs.swarthmore.edu/~newhall/unixhelp/debuggingtips_Java.html#compiling http://www.cs.swarthmore.edu/~newhall/unixhelp/debuggingtips_Java.html#compiling

In that way,if it works, you will know that it is an Eclipse problem. 这样,如果它起作用了,您将知道这是一个Eclipse问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM