2012-03-18 10 views
0

ここで私が最初にやろうとしていることがあります。私はMapViewを起動しようとしています。MapViewはユーザーの場所を把握し、ユーザーの場所に基づいて変更されたデータでオーバーレイを読み込みます。ハンドラから作成されたaSyncTask

コードの概要: 作成時に現在のユーザーの場所を取得するMapViewがあります。私が最初に修正上のコールアウトのRunnableを使用してい locationOverlay:このRunnableを

locationOverlay.runOnFirstFix(centerAroundFix); 

は、centerAroundFixは、aSyncTaskを開始します。私は「新しいaSyncTask」と呼ぶとすぐに、このエラーがスローされます。

Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 

asynctaskの仕事は、データをフェッチオーバーレイを作成し、オーバーレイを追加することです。 asynctaskの作成と実行は、Runnableの外側でうまく動作します。

答えて

0

私はすでにこれを見ていないかわからない...

Can't create handler inside thread which has not called Looper.prepare()

は、私は、これは重複して質問ですかなり確信しています。

編集:動作します。ここに私のコードです。包まれたupdateLocation() "mHandler.post" と呼ん:

private Handler mHandler = new Handler(Looper.getMainLooper()); 

private Runnable centerAroundFix = new Runnable() { 
    public void run() { 
     /* Jump to current location and set zoom accordingly */ 
     map.getController().animateTo(locationOverlay.getMyLocation()); 
     map.getController().setZoom(12); 
     /* This is a different thread. I need to call this from a thread that has a 'Looper' prepared. */ 
     mHandler.post(new Runnable() { 
      public void run() { 
       updateLocation(); 
      } 
     }); 
    } 
}; 
0

あなたはUIThreadでハンドラを作成する必要があります。たとえば、クラスメンバーとして:

public class Activity extends Activity{ 
    private Handler handler = new Handler();   
} 
関連する問題