Jean Lee
Jean Lee

Reputation: 67

Android ( Textview1.settext ) crashing app

here is my code the code it self works but am trying to add all the data to my Textview1 with new line so it shows in this format

22:22
13:44
33:33
xx:xx
xx:xx

but app crashes because of this Textview1 code something am doing wrong.

private TextView textView1;

oncreate

textView1 = (TextView)findViewById(R.id.textView1);

please tell me why my Textview1 is crashing app ?

            for(int j=0;j<hrefElements.size();j++)
            {
                //System.out.println("Links: "+links[j]);
                System.out.println("Title: "+title[j]);
                textView1.setText("SUBH: "+timee[j] +" \n");
                System.out.println("SUBH: "+timee[j]);
                System.out.println("DUHR: "+timee1[j]);
                System.out.println("ASR: "+timee2[j]);
                System.out.println("MAGHRIB: "+timee3[j]);
                System.out.println("ISHA: "+timee4[j]);








stacktracr error log

    Process: testtt.myapplication, PID: 22819
    java.lang.RuntimeException: An error occured while executing doInBackground()
            at android.os.AsyncTask$3.done(AsyncTask.java:300)
            at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
            at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
            at java.util.concurrent.FutureTask.run(FutureTask.java:242)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)
     Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
            at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6915)
            at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1056)
            at android.view.View.requestLayout(View.java:17321)
            at android.view.View.requestLayout(View.java:17321)
            at android.view.View.requestLayout(View.java:17321)
            at android.view.View.requestLayout(View.java:17321)
            at android.view.View.requestLayout(View.java:17321)
            at android.view.View.requestLayout(View.java:17321)
            at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:352)
            at android.view.View.requestLayout(View.java:17321)
            at android.widget.TextView.checkForRelayout(TextView.java:8009)
            at android.widget.TextView.setText(TextView.java:4841)
            at android.widget.TextView.setText(TextView.java:4673)
            at android.widget.TextView.setText(TextView.java:4648)
            at testtt.myapplication.MainActivity$JsoupAsyncTask.doInBackground(MainActivity.java:102)
            at testtt.myapplication.MainActivity$JsoupAsyncTask.doInBackground(MainActivity.java:64)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)
08-14 03:45:04.741  22819-22819/testtt.myapplication E/ActivityThread﹕ Performing pause of activity that is not resumed: {testtt.myapplication/testtt.myapplication.MainActivity}
    java.lang.RuntimeException: Performing pause of activity that is not resumed: {testtt.myapplication/testtt.myapplication.MainActivity}
            at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3215)
            at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3203)
            at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3181)
            at android.app.ActivityThread.access$1100(ActivityThread.java:161)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
            at dalvik.system.NativeStart.main(Native Method)

Upvotes: 0

Views: 137

Answers (1)

Karakuri
Karakuri

Reputation: 38595

Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original 
        thread that created a view hierarchy can touch its views.

You are setting the text of the textview from a background thread. You have to do it on the main (UI) thread. Change your AsyncTask to simply build the string in doInBackground() and update the textview in onPostExecute() instead.

Upvotes: 1

Related Questions