启动时崩溃:"在添加内容之前必须调用requestFeature()"

时间:2015-01-02 18:02:04

标签: java android eclipse

Android Eclipse App在启动时崩溃

我是开发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>

感谢。

1 个答案:

答案 0 :(得分:1)

logcat说:

  

引起:android.util.AndroidRuntimeException:requestFeature()必须   在添加内容之前调用

换句话说,在requestFeature()中调用setContentView()后,您正在呼叫Activity。但这是不可能的。在致电requestFeature()之前,您必须致电setContentView()。您还没有发布任何代码,因此我无法给您更具体的答案。