美好的一天。 我在模拟器中启动程序时遇到问题。 有一个代码:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
程序已成功构建,但在此之后出现异常
java.lang.NullPointerException
at java.util.Arrays$ArrayList.<init>(Arrays.java:2842)
at java.util.Arrays.asList(Arrays.java:2828)
at com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings.addRecognizedFeatures(ParserConfigurationSettings.java:115)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.<init>(SAXParserImpl.java:189)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl.newSAXParser(SAXParserFactoryImpl.java:81)
at com.android.sdklib.devices.DeviceParser.getParser(DeviceParser.java:371)
at com.android.sdklib.devices.DeviceParser.parse(DeviceParser.java:355)
at com.android.sdklib.devices.DeviceManager.loadDevices(DeviceManager.java:419)
at com.android.sdklib.devices.DeviceManager.getVendorDevices(DeviceManager.java:215)
at com.android.sdklib.devices.DeviceManager.getDevices(DeviceManager.java:167)
at com.android.sdklib.devices.DeviceManager.getDevice(DeviceManager.java:147)
at com.android.sdklib.devices.DeviceManager.getDeviceStatus(DeviceManager.java:136)
at com.android.sdklib.internal.avd.AvdManager.parseAvdInfo(AvdManager.java:1413)
at com.android.sdklib.internal.avd.AvdManager.buildAvdList(AvdManager.java:1325)
at com.android.sdklib.internal.avd.AvdManager.<init>(AvdManager.java:286)
at com.android.sdklib.internal.avd.AvdManager.getInstance(AvdManager.java:296)
at org.netbeans.modules.android.project.launch.AndroidLauncherImpl.configAvd(AndroidLauncherImpl.java:130)
at org.netbeans.modules.android.project.launch.AndroidLauncherImpl.launch(AndroidLauncherImpl.java:79)
at org.netbeans.modules.android.project.LaunchExecutor$1.taskFinished(LaunchExecutor.java:92)
at org.openide.util.Task.notifyFinished(Task.java:236)
at org.openide.util.Task.run(Task.java:256)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1452) [catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2032)
你能帮我解决这个问题吗? 感谢。
P.S。仿真器可以通过AVD管理器启动,但不能通过Netbeans启动。
答案 0 :(得分:0)
评论中有错误报告here和解决方法:
解决。我安装了Java 1.7u11 Rel 1.7.0_11,现在模拟器启动良好。
答案 1 :(得分:-1)
你的东西有点乱。您在创建布局项目之前抓取它们。
从:
setContentView(R.layout.main);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
为:
setContentView(R.layout.main);
setContentView(tv);
TextView tv = new TextView(this);
tv.setText("Hello, Android");