2012-08-07 68 views
0
String sel="SELECT "+stdb.sid+"," +stdb.amt+", "+stdb.details+" FROM "+stdb.tname; 
     Cursor c=dobj.rawQuery(sel, null); 
     while(c.moveToNext()){ 
      int id=c.getInt(c.getColumnIndex(stdb.sid)); 
      int amt=c.getInt(c.getColumnIndex(stdb.amt)); 
      String printdetail=c.getString(c.getColumnIndex(stdb.details)); 
      TextView tv1=(TextView)findViewById(R.id.textView1); 

     Log.e("gg",""+amt); //the value of amt comes in logcat 
     tv1.setText(""+amt);//this gives nullpointer exception 

在這裏,我想從一個EditText,我能夠看到logcat的價值,但值當我嘗試打印相同的用的setText(TextView的)我得到一個NullPointerExceptionsqlite的空指針異常

+1

如果amt不爲null,則tv1必須爲null。 – JesusFreke 2012-08-07 20:26:23

+0

@JesusFreke先生我得到了我在logcat中的edittext中輸入的值 – dreamer1989 2012-08-07 20:28:00

+0

正確的,所以當你嘗試解除引用'tv1'時,你會得到'NullPointerException'。 'amt'的價值不是問題。 – Argyle 2012-08-07 20:29:31

回答

1

試試這個

if(tv1!=NULL) 
    tv1.setText(""+amt); 
else 
    Log.e("WHOA, this is NULL!!!"); 

,看看它是否打印其他日誌。如果是這樣,那意味着您的tv1視圖沒有正確初始化。如果不是,將會看到我們能做些什麼。

+0

謝謝先生tv1是問題的根源 – dreamer1989 2012-08-07 20:38:13