1

我创建了一个ProgressDialog来显示用户单击按钮的时间。

顺便说一句,我的活动是在一个Tabgroup

这是我的代码ProgressDialog

final ProgressDialog myPd_ring=ProgressDialog.show(MainActivity.this, "Please wait", "Loading please wait..", true);
        myPd_ring.setCancelable(false);
        new Thread(new Runnable() {  
              public void run() {
                    // TODO Auto-generated method stub
                    try 
                    { 
                         //Some data binding here....
                    }catch(Exception e){

                    } 
                    myPd_ring.dismiss();
                    Intent edit = new Intent(getDialogContext(), MerchantActivity.class);
                    TabGroupActivity parentsActivity = (TabGroupActivity)getParent();
                    parentsActivity.startChildActivity("MerchantActivity", edit);
              }
        }).start();

现在一切正常,直到我使用意图。我收到一个错误

这是我的 LogCat:

10-17 16:35:21.429: E/AndroidRuntime(11604): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mobileoptima.perxclub/com.mobileoptima.perxclub.MerchantActivity}: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1491)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at com.mobileoptima.perxclub.TabGroupActivity.startChildActivity(TabGroupActivity.java:55)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at com.mobileoptima.perxclub.CardsActivity$2.run(CardsActivity.java:318)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at java.lang.Thread.run(Thread.java:1019)
10-17 16:35:21.429: E/AndroidRuntime(11604): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.os.Handler.<init>(Handler.java:121)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.Activity.<init>(Activity.java:680)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at com.mobileoptima.perxclub.MerchantActivity.<init>(MerchantActivity.java:63)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at java.lang.Class.newInstanceImpl(Native Method)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at java.lang.Class.newInstance(Class.java:1409)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
10-17 16:35:21.429: E/AndroidRuntime(11604): 
... 6 more

为什么我会收到这个错误?就我而言,我打电话给父母。请帮忙??

4

2 回答 2

1

尝试parentsActivity.startChildActivity("MerchantActivity", edit);在主 UI 线程上运行。像这样的东西:

runOnUiThread(new Runnable() {
    public void run() {
        parentsActivity.startChildActivity("MerchantActivity", edit);
    }
});

顺便说一句,你将不得不声明TabGroupActivity parentsActivityIntent edit至于final这一点。

于 2012-10-17T08:31:05.910 回答
0

没关系,我找到了我正在寻找的答案。我只是添加它就像魅力一样

                runOnUiThread(new Runnable() {
                              public void run() {
                               // Toast.makeText(activity, "Hello", Toast.LENGTH_SHORT).show();
                                Intent edit = new Intent(getParent(), MerchantActivity.class);
                                TabGroupActivity parentsActivity = (TabGroupActivity)getParent();
                                parentsActivity.startChildActivity("MerchantActivity", edit);
                              }
                            });
于 2012-10-17T08:31:33.477 回答