0

I'm trying to setText on a TextView, I get an error on the phone, and in the LogCat all I get is tag: androidruntime, text: at com.examp... onPostExecute (AsyncSomething.java). Here is my pseudo code:

    TextView display_car_tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        display_name_tv = (TextView) findViewById(R.id.display_name_tv);
.....
     setContentView(R.layout...);
}

I have a button that affected to the methode that does only:

new AsyncSomething(this,display_car_tv).execute();

The code of AsyncSomething:

private Context context;
    private TextView tv;
    public AsyncSomethin(Context context, TextView tv){
        this.context=context;
        this.tv=tv;
    }

    protected String doInBackground(String...arg0){
            //some code that works
            return sb.toString();
    }

    protected void onPreExecute() {}
    @Override
    protected void onPostExecute(String result){
        this.tv.append(result);
    }

What do I do wrong? How can I get more information from LogCat?

PS : sorry for not giving the entire code, but it is not relevant.

3
  • Post full stack trace. Jul 19, 2015 at 16:43
  • Thank you for the -1, I can't post the full trace, and I'm sure that for 6.5 lines of code, there are some people who will be able to help me
    – Upsilon42
    Jul 19, 2015 at 16:45
  • Your logcat should always have the full stack trace if your phone is locally connected and you actually do "adb logcat" in a terminal instead of using android studio / eclipse. You're welcome to the -1. If this is a remote crash and you haven't reproduced it you're going to have to reproduce it to make sure you fixed it. Jul 19, 2015 at 16:52

1 Answer 1

2

from the code you posted the only mistake I can see, probably leading your app to crash for NullPointerException, is that you are using findViewById before setContentView. You have always to call setContentView before every findViewByIds otherwise you will not have any widgets to find

1
  • Thank you, actually it happens to me all the time to forget this. I'll finish my app in the year 2525 x), anyway, solved.
    – Upsilon42
    Jul 19, 2015 at 16:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.