2016-04-12 29 views
0

当我运行我的项目时出现了一些错误。在logcat中显示的错误是如下: -04-12 23:12:43.412 2953-2953 /? E/AndroidRuntime:在writeCrashedAppName,pkgName:com.example.firstapp

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) for my application

<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 ..请帮我摆脱这个错误。先谢谢了。

+0

请发表您的style.xml看来你是不使用App紧凑的主题,这是目前在V7支持库。 – dex

+0

请发布您的Menu.java活动文件。 – dex

+0

将android:theme =“@ style/Theme.AppCompat.Light”更改为AndroidManifest.xml文件中的应用程序标记 – dex

回答

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中设置主题,以“@风格/ AppThemeMaterial”

+0

得到了两个错误...错误:(4)检索项目的父项时出错:找不到与给定名称'Theme.AppCompact.Light'匹配的资源。错误:任务':app:processDebugResources'的执行失败。 > com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令'C:\ Users \ Newson \ AppData \ Local \ Android \ sdk \ build-tools \ 23.0.1 \ aapt.exe''以非零退出值完成1 – Student

+0

好吧,现在转到您的style.xml(v21),并在父=“这里”把“@ style/Theme.AppCompat.Light” – Asama

相关问题