public class MainActivity extends Activity {
private ListView listV;
private List<Map<String, Object>> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listV = (ListView) findViewById(R.id.listView1);
SimpleAdapter simpAdapter = new SimpleAdapter(this, getData(), R.layout.item, new String[] {"text", "image"}, new int[] {R.id.textView1, R.id.imageView1});
listV.setAdapter(simpAdapter);
}
private List<Map<String, Object>> getData() {
list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("text", "java");
map.put("image", R.drawable.ic_launcher);
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("text", "C++");
map2.put("image", R.drawable.ic_launcher);
Map<String, Object> map3 = new HashMap<String, Object>();
map3.put("text", "JavaScript");
map3.put("image", R.drawable.ic_launcher);
Map<String, Object> map4 = new HashMap<String, Object>();
map4.put("text", "Php");
map4.put("image", R.drawable.ic_launcher);
Map<String, Object> map5 = new HashMap<String, Object>();
map5.put("text", "Python2");
map5.put("image", R.drawable.ic_launcher);
list.add(map);
list.add(map2);
list.add(map3);
list.add(map4);
list.add(map5);
return list;
}
}错误日志03-04 03:17:52.032: D/AndroidRuntime(1912): Shutting down VM03-04 03:17:52.032: W/dalvikvm(1912): threadid=1: thread exiting with uncaught exception (group=0xb4b03ba8)03-04 03:17:52.052: E/AndroidRuntime(1912): FATAL EXCEPTION: main03-04 03:17:52.052: E/AndroidRuntime(1912): Process: com.example.adaptertt, PID: 191203-04 03:17:52.052: E/AndroidRuntime(1912): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.adaptertt/com.example.adaptertt.MainActivity}: java.lang.NullPointerException03-04 03:17:52.052: E/AndroidRuntime(1912): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)03-04 03:17:52.052: E/AndroidRuntime(1912): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)03-04 03:17:52.052: E/AndroidRuntime(1912): at android.app.ActivityThread.access$800(ActivityThread.java:135)03-04 03:17:52.052: E/AndroidRuntime(1912): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)03-04 03:17:52.052: E/AndroidRuntime(1912): at android.os.Handler.dispatchMessage(Handler.java:102)03-04 03:17:52.052: E/AndroidRuntime(1912): at android.os.Looper.loop(Looper.java:136)03-04 03:17:52.052: E/AndroidRuntime(1912): at android.app.ActivityThread.main(ActivityThread.java:5017)03-04 03:17:52.052: E/AndroidRuntime(1912): at java.lang.reflect.Method.invokeNative(Native Method)03-04 03:17:52.052: E/AndroidRuntime(1912): at java.lang.reflect.Method.invoke(Method.java:515)03-04 03:17:52.052: E/AndroidRuntime(1912): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)03-04 03:17:52.052: E/AndroidRuntime(1912): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)03-04 03:17:52.052: E/AndroidRuntime(1912): at dalvik.system.NativeStart.main(Native Method)03-04 03:17:52.052: E/AndroidRuntime(1912): Caused by: java.lang.NullPointerException03-04 03:17:52.052: E/AndroidRuntime(1912): at com.example.adaptertt.MainActivity.onCreate(MainActivity.java:35)03-04 03:17:52.052: E/AndroidRuntime(1912): at android.app.Activity.performCreate(Activity.java:5231)03-04 03:17:52.052: E/AndroidRuntime(1912): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)03-04 03:17:52.052: E/AndroidRuntime(1912): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)03-04 03:17:52.052: E/AndroidRuntime(1912): ... 11 more
添加回答
举报
0/150
提交
取消