0-04 15:15:36.218: E/AndroidRuntime(5176): FATAL EXCEPTION: main
10-04 15:15:36.218: E/AndroidRuntime(5176): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.solar/com.solar.SetupInfoActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
10-04 15:15:36.218: E/AndroidRuntime(5176): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
10-04 15:15:36.218: E/AndroidRuntime(5176): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-04 15:15:36.218: E/AndroidRuntime(5176): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-04 15:15:36.218: E/AndroidRuntime(5176): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-04 15:15:36.218: E/AndroidRuntime(5176): at android.os.Handler.dispatchMessage(Handler.java:99)
10-04 15:15:36.218: E/AndroidRuntime(5176): at android.os.Looper.loop(Looper.java:130)
10-04 15:15:36.218: E/AndroidRuntime(5176): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-04 15:15:36.218: E/AndroidRuntime(5176): at java.lang.reflect.Method.invokeNative(Native Method)
10-04 15:15:36.218: E/AndroidRuntime(5176): at java.lang.reflect.Method.invoke(Method.java:507)
10-04 15:15:36.218: E/AndroidRuntime(5176): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-04 15:15:36.218: E/AndroidRuntime(5176): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-04 15:15:36.218: E/AndroidRuntime(5176): at dalvik.system.NativeStart.main(Native Method)
10-04 15:15:36.218: E/AndroidRuntime(5176): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
10-04 15:15:36.218: E/AndroidRuntime(5176): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:181)
10-04 15:15:36.218: E/AndroidRuntime(5176): at android.app.Activity.requestWindowFeature(Activity.java:2729)
10-04 15:15:36.218: E/AndroidRuntime(5176): at com.solar.BaseActivity.onCreate(BaseActivity.java:20)
10-04 15:15:36.218: E/AndroidRuntime(5176): at com.solar.SetupInfoActivity.onCreate(SetupInfoActivity.java:53)
10-04 15:15:36.218: E/AndroidRuntime(5176): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-04 15:15:36.218: E/AndroidRuntime(5176): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-04 15:15:36.218: E/AndroidRuntime(5176): ... 11 more
错误提示见红字部分
![](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
1 protected void onCreate(Bundle savedInstanceState) { 2 this.setContentView(R.layout.setup_info_page); 3 this.requestWindowFeature(Window.FEATURE_NO_TITLE);// Activity去掉标题 4 super.onCreate(savedInstanceState); 5 }
这里 this.setContentView(R.layout.setup_info_page)比
this.requestWindowFeature(Window.FEATURE_NO_TITLE)方法调用更早,所以报错 了。
只需要保证setContentView方法在requestWindowFeature方法之后执行就可以了。
作者:kissazi2
出处:http://www.cnblogs.com/kissazi2/
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
转载:http://www.cnblogs.com/kissazi2/archive/2012/10/04/2711479.html