04-12 23:12:43.412 2953-2953 /? E / AndroidRuntime:在writeCrashedAppName中,pkgName:com.example.firstapp

时间:2016-04-12 17:59:20

标签: java android debugging android-activity android-manifest

我在运行项目时遇到了一些错误。 logcat中显示的错误如下:

04-12 23:12:43.412 2953-2953/? E/AndroidRuntime: in writeCrashedAppName, pkgName :com.example.firstapp
04-12 23:12:43.412 2953-2953/? D/AndroidRuntime: file written successfully with content: com.example.firstapp StringBuffer : ;com.example.firstapp
04-12 23:12:43.412 2953-2953/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.example.firstapp, PID: 2953
                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.firstapp/com.example.firstapp.Menu}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
                                                     at android.app.ActivityThread.access$800(ActivityThread.java:135)
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                     at android.os.Looper.loop(Looper.java:136)
                                                     at android.app.ActivityThread.main(ActivityThread.java:5021)
                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                     at java.lang.reflect.Method.invoke(Method.java:515)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
                                                     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:310)
                                                     at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:279)
                                                     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:253)
                                                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
                                                     at com.example.firstapp.Menu.onCreate(Menu.java:25)
                                                     at android.app.Activity.performCreate(Activity.java:5231)
                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090)
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
                                                     at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                     at android.os.Looper.loop(Looper.java:136) 
                                                     at android.app.ActivityThread.main(ActivityThread.java:5021) 
                                                     at java.lang.reflect.Method.invokeNative(Native Method) 
                                                     at java.lang.reflect.Method.invoke(Method.java:515) 
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827) 
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643) 
                                                     at dalvik.system.NativeStart.main(Native Method) 

我的应用程序的Style.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
  

我的应用程序的style.xml(v21)

<resources>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
</resources>
  

Menu.java

import android.app.ListActivity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;


public class Menu extends AppCompatActivity{


     ListView lv;

    private static  String[] menu_list={"Programs","Tutorials","Year Question"};


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


    public void listview()
    {
        lv=(ListView)findViewById(R.id.lv_Menu_List);
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.list_layout,menu_list);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                        //String value =(String)lv.getItemAtPosition(position);

                        if(position==0){
                        //Toast.makeText(Menu.this, "Position : " + position + " Value : " , Toast.LENGTH_LONG).show();

                            Intent intent=new Intent(Menu.this,Programs.class);
                            startActivity(intent);

                         }
                        else {
                            if (position == 1) {
                                Intent intent = new Intent(Menu.this, Tutorials.class);
                                startActivity(intent);

                            } else if (position == 2) {
                                Intent intent = new Intent(Menu.this, YearQuestion.class);
                                startActivity(intent);
                            }
                        }



                    }
                }
        );

    }




}
  

的AndroidManifest.xml

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

    <application>
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light">

        <activity android:name=".Menu">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Programs"
            android:label="Programs">
            <intent-filter>
                <action android:name="android.intent.action.Programs" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".Tutorials">
            <intent-filter>
                <action android:name="android.intent.action.Tutorials" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".YearQuestion">
            <intent-filter>
                <action android:name="android.intent.action.YearQuestion" />

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

  </application>

</manifest>

我是android和java的新手..请帮我摆脱这个错误。谢谢你提前。

1 个答案:

答案 0 :(得分:0)

尝试编辑style.xml(v21)。

<resources> 
<style name="AppThemeMaterial" parent="@style/Theme.AppCompact.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item> 
<item name="android:windowDrawsSystemBarBackgrounds">true</item> 
<item name="android:statusBarColor">@android:color/transparent</item> 
</style> 
</resources> 

在AndroidManifest.xml中将主题设置为&#34; @ style / AppThemeMaterial&#34;