当我想要输入从SQL获取详细信息的listview活动时,请帮助解决我的问题,应用程序崩溃。
09-09 18:25:06.698: E/AndroidRuntime(19913): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.raingp.jungle/com.raingp.jungle.FirstActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
FirstActivity.class
public class FirstActivity extends Activity {
private ListView name_view;
SQLiteDatabase sqdb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name_view = (ListView)findViewById(R.id.listView1);
DBHelper mydbhelper = new DBHelper(this);
try {
mydbhelper.createDataBase();
} catch (IOException e) {
throw new Error("error");
}
try {
mydbhelper.openDataBase();
} catch (SQLException sql) {
throw sql;
}
sqdb = mydbhelper.getReadableDatabase();
Cursor c =mydbhelper.readName();
c.moveToFirst();
Adapter myAdapter = new Adapter(this, c);
name_view.setAdapter(myAdapter);
}
我不知道如何修复它。
答案 0 :(得分:0)
根据您提供的少量信息,您可能正在尝试在null对象中设置适配器。在您listview.setAdapter(adapter)
中,您的listview
对象为空。