Android 我的申请突然停止了

Android 我的申请突然停止了,android,Android,我的应用程序突然停止。我添加了一个tabhost,并在其中添加了一个对话框。因此,当我运行我的应用程序时,它会在重定向到我创建tab host的活动时突然停止。我的日志中有一个错误,有人能帮我找到解决方案吗 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 t

我的应用程序突然停止。我添加了一个tabhost,并在其中添加了一个对话框。因此,当我运行我的应用程序时,它会在重定向到我创建tab host的活动时突然停止。我的日志中有一个错误,有人能帮我找到解决方案吗

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);
    }
    }

在定义
意图时,您似乎将
活动
命名错误

该行:

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

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

尝试将生成器的构造函数更改为:

新建AlertDialog.Builder(此)


将您的上下文更改为ActivityName.this或getApplicationContext()


我已经在上面发布了,请检查一下。哪一行是Friends。java:57?不要使用
getBaseContext
getApplicationContext()
来创建对话框。使用
活动名称。此
AlertDialog.Builder alertDialogBuilder=new AlertDialog.Builder(getBaseContext());