This question already has answers here:
requestFeature() must be called before adding content
(8个答案)
5年前关闭。
Android Eclipse应用在启动时崩溃
我是Android开发新手,无法启动项目。每当我启动它时,它就会崩溃
这是LogCat的输出:
如果需要,这是我的AndroidManifest.xml:
谢谢。
(8个答案)
5年前关闭。
Android Eclipse应用在启动时崩溃
我是Android开发新手,无法启动项目。每当我启动它时,它就会崩溃
这是LogCat的输出:
01-02 17:31:45.803: E/Trace(1788): error opening trace file: No such file or directory (2)
01-02 17:31:56.222: E/AndroidRuntime(1788): FATAL EXCEPTION: main
01-02 17:31:56.222: E/AndroidRuntime(1788): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gonga.ShootingParrots/com.gonga.ShootingParrots.Game}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
01-02 17:31:56.222: E/AndroidRuntime(1788): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-02 17:31:56.222: E/AndroidRuntime(1788): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-02 17:31:56.222: E/AndroidRuntime(1788): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-02 17:31:56.222: E/AndroidRuntime(1788): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-02 17:31:56.222: E/AndroidRuntime(1788): at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 17:31:56.222: E/AndroidRuntime(1788): at android.os.Looper.loop(Looper.java:137)
01-02 17:31:56.222: E/AndroidRuntime(1788): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-02 17:31:56.222: E/AndroidRuntime(1788): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 17:31:56.222: E/AndroidRuntime(1788): at java.lang.reflect.Method.invoke(Method.java:511)
01-02 17:31:56.222: E/AndroidRuntime(1788): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-02 17:31:56.222: E/AndroidRuntime(1788): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-02 17:31:56.222: E/AndroidRuntime(1788): at dalvik.system.NativeStart.main(Native Method)
01-02 17:31:56.222: E/AndroidRuntime(1788): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
01-02 17:31:56.222: E/AndroidRuntime(1788): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:229)
01-02 17:31:56.222: E/AndroidRuntime(1788): at org.anddev.andengine.util.ActivityUtils.requestFullscreen(ActivityUtils.java:54)
01-02 17:31:56.222: E/AndroidRuntime(1788): at org.anddev.andengine.ui.activity.BaseGameActivity.applyEngineOptions(BaseGameActivity.java:228)
01-02 17:31:56.222: E/AndroidRuntime(1788): at org.anddev.andengine.ui.activity.BaseGameActivity.onCreate(BaseGameActivity.java:65)
01-02 17:31:56.222: E/AndroidRuntime(1788): at android.app.Activity.performCreate(Activity.java:5104)
01-02 17:31:56.222: E/AndroidRuntime(1788): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-02 17:31:56.222: E/AndroidRuntime(1788): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-02 17:31:56.222: E/AndroidRuntime(1788): ... 11 more
如果需要,这是我的AndroidManifest.xml:
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="14"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application android:icon="@drawable/icone" android:installLocation="auto" android:label="@string/app" android:launchMode="singleInstance">
<activity android:configChanges="keyboard|keyboardHidden|orientation" android:name=".Game" android:screenOrientation="portrait" android:theme="@style/Theme.NoBackground">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Amazon Ads -->
<activity android:name="com.amazon.device.ads.AdActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<!-- Admob Ads -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
谢谢。
最佳答案
日志说:
原因:android.util.AndroidRuntimeException:requestFeature()必须
在添加内容之前被调用
换句话说,您已经在requestFeature()
中调用setContentView()
之后调用了Activity
。但这是不可能的。呼叫requestFeature()
之前必须先呼叫setContentView()
。您尚未发布任何代码,因此我无法真正为您提供更具体的答案。
关于java - 启动时崩溃:“添加内容之前必须先调用requestFeature()” ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27746476/
10-10 20:27