0
請幫助我的問題,當我想進入listview活動,從SQL的細節,應用程序只是崩潰。SQLite到列表活動logcat錯誤
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);
}
,我不知道如何解決它。
添加一些代碼... –
在設置「Adapter」之前,您很可能不會初始化您的'ListView'。 –
也是'activity_main'的代碼 –