2016-04-12 13 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

のために

私はアンドロイドとjava上で新しいです。このエラーを取り除くために私を助けてください。ありがとうございました。

+0

テーマを設定し、あなたのstyle.xmlを投稿してくださいあなたはV7サポートlibに存在しているアプリのコンパクトなテーマを使用していないようです。 – dex

+0

あなたのMenu.javaアクティビティファイルも投稿してください。 – dex

+0

AndroidManifest.xmlファイルのアプリケーションタグにアンドロイド:theme = "@ style/Theme.AppCompat.Light"を変更します – dex

答えて

0

あなたのstyle.xml(v21)を編集してみてください。あなたのAndroidManifest.xmlに比べ

<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> 

に「@スタイル/ AppThemeMaterial」

+0

に2つのエラーがあります...エラー:(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)に行き、親= "here"に "@ style/Theme.AppCompat.Light" – Asama

関連する問題