2

我试图这样做,on scrolling load more但它根本不起作用我使用了以下代码:

错误:

04-29 15:55:22.682: E/AndroidRuntime(311): FATAL EXCEPTION: AsyncTask #2
04-29 15:55:22.682: E/AndroidRuntime(311): java.lang.RuntimeException: An error occured while executing doInBackground()
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.lang.Thread.run(Thread.java:1096)
04-29 15:55:22.682: E/AndroidRuntime(311): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.os.Handler.<init>(Handler.java:121)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.Dialog.<init>(Dialog.java:101)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.AlertDialog.<init>(AlertDialog.java:63)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.ProgressDialog.<init>(ProgressDialog.java:80)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.ProgressDialog.<init>(ProgressDialog.java:76)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.ProgressDialog.show(ProgressDialog.java:101)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.ProgressDialog.show(ProgressDialog.java:90)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.app.ProgressDialog.show(ProgressDialog.java:85)
04-29 15:55:22.682: E/AndroidRuntime(311):  at com.example.know.FirstActivity.Callpagedetails(FirstActivity.java:176)
04-29 15:55:22.682: E/AndroidRuntime(311):  at com.example.know.FirstActivity$LoadDataTask.doInBackground(FirstActivity.java:320)
04-29 15:55:22.682: E/AndroidRuntime(311):  at com.example.know.FirstActivity$LoadDataTask.doInBackground(FirstActivity.java:1)
04-29 15:55:22.682: E/AndroidRuntime(311):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-29 15:55:22.682: E/AndroidRuntime(311):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-29 15:55:22.682: E/AndroidRuntime(311):  ... 4 more

当我滚动时,我得到的页数正在增加,但我没有得到数据,有人可以帮助我解决这个问题吗?

在android中使用了以下库加载更多

4

2 回答 2

0

异常消息“无法在未调用 Looper.prepare() 的线程内创建处理程序”非常清楚。

如果你需要一个 Handler 实例,那么你必须在 GUI Thread 中创建这个对象。您活动的 onCreate() 方法是一个非常好的地方

class MyActivity implements Activity {

    ...
    private Handler handler;

    onCreate(...) {
       ....
       handler=new Handler();
于 2013-04-30T07:14:06.530 回答
0

尝试:

private void refreshList() {    
Thread threadLoadMore = new Thread(new Runnable() {
   public void run() {  

       //Here refresh your arraylist 

    runOnUiThread(new Runnable() {
      public void run() {       
           //Here refresh your list view
           yourAdapter.notifyDataSetChanged();
        }
      });
    }
  });
  threadLoadMore .start();  
}
于 2013-04-30T18:34:49.813 回答