2016-03-25 54 views
1

使我的第一個應用。剛創建後,我試着讓它全屏。它說:「不幸的是你的應用程序已經停止。」android manifest全屏導致我的應用崩潰

Android清單文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.nirmal.projectfullscreen"> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".MainActivity" 
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
      android:screenOrientation="landscape"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

MainActiviy.java

package com.example.nirmal.projectfullscreen; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 
} 

logcat的

03-25 22:05:14.257 5289-5289/com.example.nirmal.projectfullscreen E/Trace: error opening trace file: No such file or directory (2) 
03-25 22:05:14.427 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;) 
03-25 22:05:14.427 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: VFY: unable to resolve interface method 15038: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z 
03-25 22:05:14.427 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: VFY: unable to resolve interface method 15042: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode; 
03-25 22:05:14.437 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41f3c600) 
03-25 22:05:14.437 5289-5289/com.example.nirmal.projectfullscreen E/AndroidRuntime: FATAL EXCEPTION: main 
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nirmal.projectfullscreen/com.example.nirmal.projectfullscreen.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391) 
    at android.app.ActivityThread.access$600(ActivityThread.java:151) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:155) 
    at android.app.ActivityThread.main(ActivityThread.java:5578) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841) 
    at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
    at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:340) 
    at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:309) 
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:273) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
    at com.example.nirmal.projectfullscreen.MainActivity.onCreate(MainActivity.java:11) 
    at android.app.Activity.performCreate(Activity.java:5066) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391) 
    at android.app.ActivityThread.access$600(ActivityThread.java:151) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:155) 
    at android.app.ActivityThread.main(ActivityThread.java:5578) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841) 
    at dalvik.system.NativeStart.main(Native Method) 
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: killProcess, pid=5289 
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: dalvik.system.VMStack.getThreadStackTrace(Native Method) 
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: java.lang.Thread.getStackTrace(Thread.java:599) 
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: android.os.Process.killProcess(Process.java:956) 
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:108) 
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693) 
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690) 
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: dalvik.system.NativeStart.main(Native Method) 
+1

使用logcat的檢查與碰撞相關的Java堆棧跟蹤:https://stackoverflow.com/questions/23353173 /不幸-myapp-has-stopped-how-can-i-solve-this我的猜測是,你得到一個錯誤,AppCompatActivity需要'Theme.AppCompat'或另一個繼承的主題從那。如果是這樣,您需要查看是否存在可以使用的'Theme.AppCompat'的全屏變體,或者移除'appcompat-v7'並使用本機操作欄。 – CommonsWare

+0

全屏幕的另一種方式是將appcompatactivity更改爲Mainactivity類中的Activity。 –

+0

對不起,我無法格式化logcat消息。 – Nirmal

回答

0

您正在使用AppCompatActivity,因此你的主題應該繼承Theme.AppCompat

您需要在此活動中使用Theme.AppCompat主題(或後代)。

使用這個主題:

<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
<item name="android:windowNoTitle">true</item> 
<item name="android:windowActionBar">false</item> 
<item name="android:windowFullscreen">true</item> 
<item name="android:windowContentOverlay">@null</item> 

在您的清單:

android:theme="@style/AppFullScreenTheme"