11-06 07:09:07.638 24338-24338/? E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{jukay.com.myapplication/jukay.com.myapplication.MainActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2233) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283) at android.app.ActivityThread.access$600(ActivityThread.java:147) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5160) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:227) at android.app.Activity.requestWindowFeature(Activity.java:3264) at jukay.com.myapplication.MainActivity.onCreate(MainActivity.java:19) at android.app.Activity.performCreate(Activity.java:5133) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283) at android.app.ActivityThread.access$600(ActivityThread.java:147) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5160) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)
出现这样的错误,网上大多数说是下面的代码写反了
requestWindowFeature(Window.FEATURE_NO_TITLE);// 隐藏了标题栏 setContentView(R.layout.activity_main);
事实上代码没有写反的时候也有可能出现这样的问题,
如果是继承Activity就没有问题
时间: 2024-10-26 18:15:31