AndroidRuntime: did not call through to super.onCreate()

本文探讨了Android开发中遇到的SuperNotCalledException异常,通过修改Activity类的onCreate方法来解决该问题,并提供了源代码对比分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

android.app.SuperNotCalledException: Activity {com.example.myrelativelayoutproject/com.example.myrelativelayoutproject.Test_TabHost} did not call through to super.onCreate()

初学android 开发 今天遇到该异常苦恼很久 查了资料


源代码: 运行时异常

public class Test_TabHost extends Activity {


   
TabHost mTabHost=null;
@Override
   public void onCreate(Bundle savedInstanceState) {
// mTabHost定义在Activity的属性
this.setContentView(R.layout.tabhost);
mTabHost = (TabHost) this.findViewById(R.id.tabhost);  
       mTabHost.setup();  
 
       TabHost.TabSpec tabWeight = mTabHost.newTabSpec("tab_weight");  
       tabWeight.setContent(R.id.relativeLayout_weight);  
       tabWeight.setIndicator(getResources().getString(R.string.weight));  
       mTabHost.addTab(tabWeight);  
   }
}


修改后 :运行正常

public class Test_TabHost extends Activity {


   
TabHost mTabHost=null;
@Override
   public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
 
// mTabHost定义在Activity的属性
this.setContentView(R.layout.tabhost);
mTabHost = (TabHost) this.findViewById(R.id.tabhost);  
       mTabHost.setup();  
 
       TabHost.TabSpec tabWeight = mTabHost.newTabSpec("tab_weight");  
       tabWeight.setContent(R.id.relativeLayout_weight);  
       tabWeight.setIndicator(getResources().getString(R.string.weight));  
       mTabHost.addTab(tabWeight);  
   }


}



07-20 19:57:40.672 5131 5131 D AndroidRuntime: Shutting down VM --------- beginning of crash 07-20 19:57:40.673 5131 5131 E AndroidRuntime: FATAL EXCEPTION: main 07-20 19:57:40.673 5131 5131 E AndroidRuntime: Process: com.adayo.aaop_deviceservice, PID: 5131 07-20 19:57:40.673 5131 5131 E AndroidRuntime: java.lang.RuntimeException: Unable to create service com.adayo.aaop_deviceservice.service.BurialPointService: android.view.WindowManager$InvalidDisplayException: Unable to add window android.view.ViewRootImpl$W@e6477e5 -- the specified display can not be found 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.app.ActivityThread.handleCreateService(ActivityThread.java:4221) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.app.ActivityThread.access$1600(ActivityThread.java:238) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1955) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.os.Looper.loop(Looper.java:223) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7731) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: Caused by: android.view.WindowManager$InvalidDisplayException: Unable to add window android.view.ViewRootImpl$W@e6477e5 -- the specified display can not be found 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.view.ViewRootImpl.setView(ViewRootImpl.java:1099) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:409) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:109) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.app.Dialog.show(Dialog.java:342) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.app.Presentation.show(Presentation.java:257) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at com.adayo.aaop_deviceservice.service.BurialPointService.x(Unknown Source:77) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at com.adayo.aaop_deviceservice.service.BurialPointService.A(Unknown Source:50) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at com.adayo.aaop_deviceservice.service.BurialPointService.onCreate(Unknown Source:10) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: at android.app.ActivityThread.handleCreateService(ActivityThread.java:4209) 07-20 19:57:40.673 5131 5131 E AndroidRuntime: ... 8 more 07-20 19:57:40.676 5131 5131 I Process : Sending signal. PID: 5131 SIG: 9 private void createBackgroundToQnx() { DisplayManager displayManager = (DisplayManager)this.getSystemService(Context.DISPLAY_SERVICE); Display[] displays = displayManager.getDisplays(); Log.i(TAG, "createBackgroundToQnx displays = " + Arrays.toString(displays)); for (Display display : displayManager.getDisplays()) { if (display.getDisplayId() == 1) { Presentation presentation = new Presentation(this, displayManager.getDisplay(1)); View view = new View(this); view.setBackgroundColor(Color.BLACK); presentation.setContentView(view); presentation.show(); } } }
最新发布
08-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值