为listView设置adapter,代码如下:
SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems, R.layout.main_item, new String[]{"icon, name, singer"}, new int[]{R.id.icon, R.id.song_name, R.id.singer}); listView.setAdapter(simpleAdapter);
报错如下:
11-20 13:05:11.010: E/BitmapFactory(13847): Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
11-20 13:05:11.010: I/System.out(13847): resolveUri failed on bad bitmap uri:
11-20 13:05:11.010: D/AndroidRuntime(13847): Shutting down VM
11-20 13:05:11.010: W/dalvikvm(13847): threadid=1: thread exiting with uncaught exception (group=0x40bc2930)
11-20 13:05:11.015: E/AndroidRuntime(13847): FATAL EXCEPTION: main
11-20 13:05:11.015: E/AndroidRuntime(13847): java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:160)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.AbsListView.obtainView(AbsListView.java:2308)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.ListView.measureHeightOfChildren(ListView.java:1309)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.ListView.onMeasure(ListView.java:1221)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.View.measure(View.java:15726)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:630)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:441)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.View.measure(View.java:15726)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4854)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.View.measure(View.java:15726)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.View.measure(View.java:15726)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4854)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-20 13:05:11.015: E/AndroidRuntime(13847): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2333)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.View.measure(View.java:15726)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1926)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1098)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1294)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4458)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.Choreographer.doFrame(Choreographer.java:532)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.os.Handler.handleCallback(Handler.java:725)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.os.Handler.dispatchMessage(Handler.java:92)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.os.Looper.loop(Looper.java:137)
11-20 13:05:11.015: E/AndroidRuntime(13847): at android.app.ActivityThread.main(ActivityThread.java:5069)
11-20 13:05:11.015: E/AndroidRuntime(13847): at java.lang.reflect.Method.invokeNative(Native Method)
11-20 13:05:11.015: E/AndroidRuntime(13847): at java.lang.reflect.Method.invoke(Method.java:511)
11-20 13:05:11.015: E/AndroidRuntime(13847): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-20 13:05:11.015: E/AndroidRuntime(13847): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-20 13:05:11.015: E/AndroidRuntime(13847): at dalvik.system.NativeStart.main(Native Method)
原因是提供填充R,layout.mai_item中三个名为icon,song_name, singer组件的组件的内容new String[]{"icon, name, singer"}数量不匹配,当时粗心把双引号写成了一个!