程序停止运行,提示错误为空指针导致,可是怎么也找不到错在哪儿了,Manifest文件也没配错,附代码和错误日志,求HELP,调了好久了
package com.abner.listviewdemo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
private ListView listView;
private ArrayAdapter<String> arr_adapter;
private SimpleAdapter sim_adapter;
private List<Map<String, Object>>datalist;
private int i;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
listView = (ListView) findViewById(R.id.listView);
String[] arr_data = { "测试1", "测试2", "测试3" };
arr_adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, arr_data);
sim_adapter = new SimpleAdapter(this, getData(),R.layout.item, new String[]{"pic","text"}, new int[]{R.id.pic,R.id.text});
listView.setAdapter(sim_adapter);
}
private List<Map<String, Object>> getData()
{
for(i=0;i<20;i++)
{
Map<String,Object>map = new HashMap<String, Object>();
map.put("pic", R.drawable.ic_launcher);
map.put("text", "测试 "+ i);
}
return datalist;
}
}
/*错误日志
-11 02:10:05.531: E/AndroidRuntime(1030): FATAL EXCEPTION: main
04-11 02:10:05.531: E/AndroidRuntime(1030): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abner.listviewdemo/com.abner.listviewdemo.MainActivity}: java.lang.NullPointerException
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.app.ActivityThread.access$600(ActivityThread.java:122)
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.os.Looper.loop(Looper.java:137)
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.app.ActivityThread.main(ActivityThread.java:4340)
04-11 02:10:05.531: E/AndroidRuntime(1030): at java.lang.reflect.Method.invokeNative(Native Method)
04-11 02:10:05.531: E/AndroidRuntime(1030): at java.lang.reflect.Method.invoke(Method.java:511)
04-11 02:10:05.531: E/AndroidRuntime(1030): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-11 02:10:05.531: E/AndroidRuntime(1030): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-11 02:10:05.531: E/AndroidRuntime(1030): at dalvik.system.NativeStart.main(Native Method)
04-11 02:10:05.531: E/AndroidRuntime(1030): Caused by: java.lang.NullPointerException
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.widget.SimpleAdapter.getCount(SimpleAdapter.java:93)
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.widget.ListView.setAdapter(ListView.java:460)
04-11 02:10:05.531: E/AndroidRuntime(1030): at com.abner.listviewdemo.MainActivity.onCreate(MainActivity.java:37)
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.app.Activity.performCreate(Activity.java:4465)
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-11 02:10:05.531: E/AndroidRuntime(1030): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
04-11 02:10:05.531: E/AndroidRuntime(1030): ... 11 more
04-11 02:10:09.581: I/Process(1030): Sending signal. PID: 1030 SIG: 9
*/