2011-10-28 89 views
2

搜索我發現,有些手機(如Galaxy S的)是由一個奇怪的錯誤或什麼導致此錯誤的影響後:

      java.lang.RuntimeException: An error occured while executing doInBackground() 
       at android.os.AsyncTask$3.done(AsyncTask.java:200) 
       at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) 
       at java.util.concurrent.FutureTask.setException(FutureTask.java:125) 
       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) 
       at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
       at java.lang.Thread.run(Thread.java:1019) 
      Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. 
       at android.view.ViewRoot.checkThread(ViewRoot.java:2934) 
       at android.view.ViewRoot.invalidateChild(ViewRoot.java:643) 
       at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:669) 
       at android.view.ViewGroup.invalidateChild(ViewGroup.java:2511) 
       at android.view.View.invalidate(View.java:5279) 
       at android.webkit.WebView.selectionDone(WebView.java:4470) 
       at android.webkit.WebView.clearHelpers(WebView.java:1295) 
       at android.webkit.WebView.loadDataWithBaseURL(WebView.java:1714) 
       at c.a(Unknown Source) 
       at c.doInBackground(Unknown Source) 
       at android.os.AsyncTask$2.call(AsyncTask.java:185) 
       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
       ... 4 more 
      android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. 
       at android.view.ViewRoot.checkThread(ViewRoot.java:2934) 
       at android.view.ViewRoot.invalidateChild(ViewRoot.java:643) 
       at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:669) 
       at android.view.ViewGroup.invalidateChild(ViewGroup.java:2511) 
       at android.view.View.invalidate(View.java:5279) 
       at android.webkit.WebView.selectionDone(WebView.java:4470) 
       at android.webkit.WebView.clearHelpers(WebView.java:1295) 
       at android.webkit.WebView.loadDataWithBaseURL(WebView.java:1714) 
       at c.a(Unknown Source) 
       at c.doInBackground(Unknown Source) 
       at android.os.AsyncTask$2.call(AsyncTask.java:185) 
       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
       at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
       at java.lang.Thread.run(Thread.java:1019) 

這是logcat的如果需要的話,從這裏看來,是刷卡功能的問題:

  10-27 19:19:20.329 I/InputReader( 166): dispatchTouch::touch event's action is 1 
      10-27 19:19:20.329 I/InputDispatcher( 166): Delivering touch to current input target: action: 1, channel '4096f5c8 ***PACKEGE_NAME***/***PACKEGE_NAME***.Game (server)' 
      10-27 19:19:20.749 I/InputReader( 166): dispatchTouch::touch event's action is 0 
      10-27 19:19:20.749 I/InputDispatcher( 166): Delivering touch to current input target: action: 0, channel '4096f5c8 ***PACKEGE_NAME***/***PACKEGE_NAME***.Game (server)' 
      10-27 19:19:21.689 I/InputReader( 166): dispatchTouch::touch event's action is 1 
      10-27 19:19:21.689 I/InputDispatcher( 166): Delivering touch to current input target: action: 1, channel '4096f5c8 ***PACKEGE_NAME***/***PACKEGE_NAME***.Game (server)' 
      10-27 19:19:21.689 W/webview (1125): Miss a drag as we are waiting for WebCore's response for touch down. 
      10-27 19:19:21.989 I/InputReader( 166): dispatchTouch::touch event's action is 0 
      10-27 19:19:21.989 I/InputDispatcher( 166): Delivering touch to current input target: action: 0, channel '4096f5c8 ***PACKEGE_NAME***/***PACKEGE_NAME***.Game (server)' 
      10-27 19:19:22.159 I/Ads  (1125): Refreshing ad. 
      10-27 19:19:22.169 I/webclipboard(1125): clipservice: [email protected] 
      10-27 19:19:22.259 I/Ads  (1125): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":15,"u_sd":1.0,"u_w":320,"slotname":"a14e098781b871d","msid":"***PACKEGE_NAME***","js":"afma-sdk-a-v4.0.4","isu":"F1B8EEEA64C5716BA996D22689C17557","format":"320x50_mb","net":"wi","app_name":"4.0.4.android.***PACKEGE_NAME***","hl":"pt","u_h":480,"u_so":"p","u_audio":1,"prl":792});</script></head><body></body></html> 
      10-27 19:19:22.449 I/InputReader( 166): dispatchTouch::touch event's action is 1 
      10-27 19:19:22.449 I/InputDispatcher( 166): Delivering touch to current input target: action: 1, channel '4096f5c8 ***PACKEGE_NAME***/***PACKEGE_NAME***.Game (server)' 
      10-27 19:19:22.449 W/webview (1125): Miss a drag as we are waiting for WebCore's response for touch down. 
      10-27 19:19:22.599 I/Ads  (1125): Received ad url: <"url": "http://googleads.g.doubleclick.net:80/mads/gma?preqs=15&u_sd=1&u_w=320&slotname=a14e098781b871d&msid=***PACKEGE_NAME***&js=afma-sdk-a-v4.0.4&isu=F1B8EEEA64C5716BA996D22689C17557&format=320x50_mb&net=wi&app_name=4.0.4.android.***PACKEGE_NAME***&hl=pt&u_h=480&u_so=p&u_audio=1&prl=792&output=html&region=mobile_app&u_tz=240&ex=1&client_sdk=1&askip=0", "afmaNotifyDt": "null"> 
      10-27 19:19:22.609 I/InputReader( 166): dispatchTouch::touch event's action is 0 
      10-27 19:19:22.609 I/InputDispatcher( 166): Delivering touch to current input target: action: 0, channel '4096f5c8 ***PACKEGE_NAME***/***PACKEGE_NAME***.Game (server)' 
      10-27 19:19:23.339 W/dalvikvm(1125): threadid=11: thread exiting with uncaught exception (group=0x40018578) 
      10-27 19:19:23.339 E/ACRA (1125): ACRA caught a RuntimeException exception for ***PACKEGE_NAME***. Building report. 
      10-27 19:19:23.339 D/ACRA (1125): Retrieve application default SharedPreferences. 
      10-27 19:19:23.349 V/webview (1125): ZoomScale 3 mPreserveZoom: false 
      10-27 19:19:23.489 I/ACRA (1125): READ_LOGS granted! ACRA can include LogCat and DropBox data. 
      10-27 19:19:23.519 D/ACRA (1125): Retrieving logcat output... 

,可能會導致此錯誤的唯一的事情就是我在遊戲中的意圖應用程序中使用定時器,我試圖建立一個處理程序,但我看到了很多崩潰在我的ACRA日誌中。

這是我的意圖的內容,我希望有人應該幫助我:)

  startB.setOnClickListener(new View.OnClickListener() { 
         public void onClick(View view) { 

          startB.setEnabled(false); 
          partiColTempo(tempox); 
         } 
        }); 

         } 


       private void displayText(final String text){ 
         this.runOnUiThread(new Runnable(){ 
          //@Override 
          public void run() { 
           tempo.setText(text); 

           if (text.equals("Finished")){ 
            eseguiSuono();      
            assegnaPunti();  
            startB.setEnabled(true); 
            //elapsed=0; 
            tempo.setText("Waiting"); 
           } 
          }}); 
        } 

       private void partiColTempo(int tempox) { 
        TIMEOUT=tempox*1000; 
        Log.w("tempo timer", ""+tempox); 
        elapsed=INTERVAL; 
        TimerTask task=new TimerTask(){ 
         @Override 
         public void run() { 
          elapsed+=INTERVAL; 
          if(elapsed>TIMEOUT){ 
           this.cancel(); 
           displayText("Finished"); 

           return; 
          } 
          //if(some other conditions) 
          // this.cancel(); 
          displayText(getString(R.string.tempo_rim)+" " + (TIMEOUT-elapsed)/1000); 
         } 
        }; 
        Timer timer = new Timer(); 
        timer.scheduleAtFixedRate(task, INTERVAL, INTERVAL); 

是問題嗎?因爲當我打電話給asynctask時,我找不到其他地方。

+0

從你的logcat文章看來,這個問題是在AsyncTask中的某個地方 - 你是否正在使用這樣的一個,如果可以的話,你能否也發佈代碼? – kaspermoerch

+0

從logcat看來,你使主線程外部的某些視圖無效,而這在Android中是不允許的。 – Huang

+0

所以這不是定時器的問題?我必須搜索一個AsyncTask?我的應用程序中使用的唯一「任務」是該計時器。 – Toleno

回答

0

您明確正在從AsyncTask.doInBackground()開始使用UI(即查看派生對象)。這是不允許的,只有UI線程可以觸摸UI對象。

如果您需要在背景/ AsyncTask運行時更新UI,您必須調用publishProgress(),這將導致onProgressUpdate在UI線程上運行。您也可以實現onPostExecute(),一旦後臺線程完成,它也將在UI線程上運行。

+0

所以它不是計時器(與相對節奏的TextView)?我找不到它在哪裏,有沒有找到它的方法? – Toleno

+0

根據您的logcat,錯誤位於混淆的組件中,即它在「在c.a(未知源),c.doInBackground(未知源)」中說的地方。你還使用了其他什麼庫? –

+0

也許我找到了解決方案,我有一個老的admob庫,我試着用一個新的。 – Toleno

0

這種情況通常發生在AsyncTask線程正在 背景中工作,但同時UI活動類被破壞。所以 在AsyncTask完成後我們試着執行一些UI任務, 上面的Exception就會拋出。