2012-02-03 3 views
1

내 응용 프로그램에 AsyncTask을 구현하려고합니다. 문제는 다른 스레드에서 만들어 실행 되었기 때문에 예외가 발생했습니다. 나는 앞으로 나아가서 AsyncTask를 만들고 실행할 작은 runnable을 구현한다. 나는 runOnUIThread() 방법이 실행 가능한 실행,하지만 여전히 AsyncTask 생성자와 라인에, 내 실행 가능한 생성자에서이 오류가 발생했습니다 :루프의 AsyncTask?

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

어떤 아이디어 무엇을?

코드가 필요하십니까?

myLocationOverlay.runOnFirstFix(new Runnable() { 

      @Override 
      public void run() { 
       fillMap(); 
      } 
     }); 

public void fillMap(){ 
      runOnUiThread(new AsyncTaskRunner()); 
} 

private class AsyncTaskRunner implements Runnable { 
     DownloadDataTask task; 

     public AsyncTaskRunner(double latitude, double longitude, int radius) { 
      super(); 

      this.task = new DownloadDataTask(latitude, longitude, radius); 
     } 

     @Override 
     public void run() { 
      task.execute(); 
     } 
    } 
+0

DownloadDataTask 란 무엇입니까? – aromero

+0

DownloadDataTask는 AsyncTask 클래스를 확장 한 클래스입니다. – Seraphis

+0

왜 Looper.prepare() 메소드를 호출하지 않았습니까? –

답변

1

AsyncTask의 생성자는 여전히 비 UI 스레드에서 호출됩니다. AsyncTask의 생성을 메서드를 옮길 수 있습니까?

private class AsyncTaskRunner implements Runnable { 
    double latitude; 
    double longitude; 
    int radius; 

    public AsyncTaskRunner(double latitude, double longitude, int radius) { 
     super(); 
     this.latitude = latitude; 
     this.longitude = longitude; 
     this.radius = radius; 
    } 

    @Override 
    public void run() { 
     new DownloadDataTask(latitude, longitude, radius).execute(); 
    } 
} 
+0

어, 어리석은 .. .. 너무 분명해 .. 고마워 !! – Seraphis