2013-08-06 3 views
0

Мое приложение внезапно становится остановленным. Я добавил табуст и в котором я также добавил диалоговое окно. Поэтому, когда я запускаю свое приложение, он внезапно прекращается, перенаправляя на активность, где у меня есть создал мой узел вкладки. У меня ошибка в моем логарифме, и кто-нибудь может помочь мне найти решение?Мое приложение внезапно останавливается

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

Я отправил его выше, пожалуйста, проверьте его .. – user2656455

+0

Какая линия Friends.java:57? – m0skit0

+0

не используют 'getBaseContext' или' getApplicationContext() 'для создания диалога. используйте 'this' или' ActivityName.this'. –

ответ

0

Похоже, что вы назвали ваше Activity имя неправильно при определении Intent.

Линия:

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

должен быть

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

Попробуйте изменить конструктор Builder для:

новый AlertDialog.Builder (это);

0

изменить ваш контекст ActivityName.this или getApplicationContext() в вашем

AlertDialog.Builder alertDialogBuilder=new AlertDialog.Builder(getBaseContext()); 
Смежные вопросы