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

here i am trying to get a value from an edittext i am able to see the value in the logcat but when i try to print the same with a settext(TextView) i get a NULLPOINTEREXCEPTION

4
  • 1
    If amt is not null, then tv1 must be null. Commented Aug 7, 2012 at 20:26
  • @JesusFreke sir i am getting the value i entered in the edittext in the logcat Commented Aug 7, 2012 at 20:28
  • Right, so when you try to dereference tv1, you get the NullPointerException. The value of amt isn't the problem. Commented Aug 7, 2012 at 20:29
  • @Argyle thanks sir the porblem was with the textview Commented Aug 7, 2012 at 20:37

1 Answer 1

1

Try this

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

And see if it prints the else log. If it does, that means your tv1 view is not getting initialized correctly. If not, will see what we can do.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.