我的申请突然停止了

时间:2013-08-06 10:58:52

标签: android

我的应用程序突然停止了。我添加了一个tabhost,并且我还添加了一个对话框。所以当我运行我的应用程序时,它会在重定向到我创建我的标签主机的活动时突然停止。我的logcat中有错误,有人可以帮我找一个解决方案吗?

08-06 10:46:34.273: E/AndroidRuntime(1112): FATAL EXCEPTION: main
08-06 10:46:34.273: E/AndroidRuntime(1112): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.neochat/com.neochat.Friends}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.app.ActivityThread.access$600(ActivityThread.java:141)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.os.Handler.dispatchMessage(Handler.java:99)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.os.Looper.loop(Looper.java:137)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.app.ActivityThread.main(ActivityThread.java:5041)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at java.lang.reflect.Method.invokeNative(Native Method)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at java.lang.reflect.Method.invoke(Method.java:511)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at dalvik.system.NativeStart.main(Native Method)

08-06 10:46:34.273: E/AndroidRuntime(1112): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)


08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.app.Dialog.show(Dialog.java:281)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at com.neochat.Friends.onCreate(Friends.java:57)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.app.Activity.performCreate(Activity.java:5104)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)

08-06 10:46:34.273: E/AndroidRuntime(1112):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)

08-06 10:46:34.273: E/AndroidRuntime(1112):     ... 11 more

  import android.app.AlertDialog;
   import android.app.TabActivity;
    import android.content.DialogInterface;
     import android.content.Intent;
      import android.os.Bundle;
       import android.widget.TabHost;
         import android.widget.TabHost.TabSpec;
        import android.widget.Toast;


    @SuppressWarnings("deprecation")
      public class Friends extends TabActivity {

    @Override
     public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    TabHost tabHost = getTabHost();


    TabSpec homespec = tabHost.newTabSpec("Friends");
    // setting Title and Icon for the Tab
   homespec.setIndicator("", getResources().getDrawable(R.drawable.icon_friend_tab));
    Intent FriendsIntent = new Intent(this,Friends_list.class);
    homespec.setContent(FriendsIntent);

    TabSpec inboxspec = tabHost.newTabSpec("Chatroom");
    inboxspec.setIndicator("", getResources().getDrawable(R.drawable.icon_chat_tab));
    Intent ChatIntent = new Intent(this,InboxActivity.class);
    inboxspec.setContent(ChatIntent);

    TabSpec composespec = tabHost.newTabSpec("Trash");        
    composespec.setIndicator("",  
     getResources().getDrawable(R.drawable.icon_trash_tab));

    AlertDialog.Builder alertDialogBuilder=new AlertDialog.Builder(getBaseContext());
    alertDialogBuilder.setMessage("Delete
        Converastion?").setCancelable(false).setPositiveButton("YES", new 
        DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            // TODO Auto-generated method stub

            Toast.makeText(Friends.this, "Conversation Deleted
               !",Toast.LENGTH_SHORT).show();
        }
    }).setNegativeButton("NO",new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            // TODO Auto-generated method stub
            dialog.cancel();
        }
    } );

    AlertDialog alertdialog=alertDialogBuilder.create();
    alertdialog.show();





    //Intent DelIntent = new Intent(this, ComposeActivity.class);
    //composespec.setContent(DelIntent);

    TabSpec morespec =tabHost.newTabSpec("more");
    morespec.setIndicator("",getResources().getDrawable(R.drawable.icon_more_tab));
    Intent moreint=new Intent(this,More.class);
    morespec.setContent(moreint);


    // Adding all TabSpec to TabHost
    tabHost.addTab(homespec); 
    tabHost.addTab(composespec); 
    tabHost.addTab(inboxspec); 
   tabHost.addTab(morespec);
    }
    }

3 个答案:

答案 0 :(得分:0)

在定义Activity时,您似乎将Intent名称命名为错误。

该行:

Intent FriendsIntent = new Intent(this,Friends_list.class);

应该是

Intent FriendsIntent = new Intent(this,Friends.class);

答案 1 :(得分:0)

尝试将Builder的构造函数更改为:

  

new AlertDialog.Builder(this);

答案 2 :(得分:0)

将您的上下文更改为

中的ActivityName.this或getApplicationContext()
AlertDialog.Builder alertDialogBuilder=new AlertDialog.Builder(getBaseContext());
相关问题