所以我有这个来自Android的关于微调器的示例代码,我对其进行了一些修改以显示其中一个微调器中的联系人,并且在模拟器上它工作正常,它显示了我在联系人中添加的5个条目,但是在手机在启动时就崩溃了,我无法理解 LogCat 的任何内容,可能是什么问题?这是代码
// add items into spinner dynamically
public void addItemsOnSpinner2() {
spinner2 = (Spinner) findViewById(R.id.spinner2);
list = new ArrayList<String>();
getContacts(null);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(dataAdapter);
}
private String getContacts(String contact) {
people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (people.moveToNext()) {
int nameFieldColumnIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
contact = people.getString(nameFieldColumnIndex);
list.add(contact);
}
people.close();
return contact;
}
这是在 LogCat 中
07-31 13:35:55.638: I/Process(11956): Sending signal. PID: 11956 SIG: 9
07-31 13:36:06.990: I/Process(12013): Sending signal. PID: 12013 SIG: 9
07-31 13:38:02.463: E/Trace(12130): error opening trace file: No such file or directory (2)
07-31 13:38:02.463: D/ActivityThread(12130): setTargetHeapUtilization:0.25
07-31 13:38:02.463: D/ActivityThread(12130): setTargetHeapIdealFree:8388608
07-31 13:38:02.473: D/ActivityThread(12130): setTargetHeapConcurrentStart:2097152
07-31 13:38:02.584: D/AndroidRuntime(12130): Shutting down VM
07-31 13:38:02.584: W/dalvikvm(12130): threadid=1: thread exiting with uncaught exception (group=0x40d7b450)
07-31 13:38:02.594: E/AndroidRuntime(12130): FATAL EXCEPTION: main
07-31 13:38:02.594: E/AndroidRuntime(12130): java.lang.NullPointerException
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:193)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.widget.Spinner.onMeasure(Spinner.java:440)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.View.measure(View.java:15348)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4924)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1420)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.widget.LinearLayout.measureVertical(LinearLayout.java:697)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.widget.LinearLayout.onMeasure(LinearLayout.java:578)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.View.measure(View.java:15348)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4924)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.widget.FrameLayout.onMeasure(FrameLayout.java:314)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.View.measure(View.java:15348)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.widget.LinearLayout.measureVertical(LinearLayout.java:849)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.widget.LinearLayout.onMeasure(LinearLayout.java:578)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.View.measure(View.java:15348)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4924)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.widget.FrameLayout.onMeasure(FrameLayout.java:314)
07-31 13:38:02.594: E/AndroidRuntime(12130): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2154)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.View.measure(View.java:15348)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1860)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1108)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1281)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1006)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4225)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.Choreographer.doFrame(Choreographer.java:525)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.os.Handler.handleCallback(Handler.java:615)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.os.Handler.dispatchMessage(Handler.java:92)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.os.Looper.loop(Looper.java:213)
07-31 13:38:02.594: E/AndroidRuntime(12130): at android.app.ActivityThread.main(ActivityThread.java:4787)
07-31 13:38:02.594: E/AndroidRuntime(12130): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 13:38:02.594: E/AndroidRuntime(12130): at java.lang.reflect.Method.invoke(Method.java:511)
07-31 13:38:02.594: E/AndroidRuntime(12130): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
07-31 13:38:02.594: E/AndroidRuntime(12130): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
07-31 13:38:02.594: E/AndroidRuntime(12130): at dalvik.system.NativeStart.main(Native Method)