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)打印时,我得到一个NULLPOINTEREXCEPTION
答案 0 :(得分:1)
试试这个
if(tv1!=NULL)
tv1.setText(""+amt);
else
Log.e("WHOA, this is NULL!!!");
看看它是否打印了else日志。如果是这样,这意味着您的tv1视图未正确初始化。如果没有,将会看到我们能做些什么。