2015-09-09 26 views
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); 


} 

,我不知道如何解決它。

+0

添加一些代碼... –

+1

在設置「Adapter」之前,您很可能不會初始化您的'ListView'。 –

+0

也是'activity_main'的代碼 –

回答

0

從您提供的很少的信息中,您可能正嘗試將適配器設置爲空對象。在你的listview.setAdapter(adapter)你的listview對象爲空。