Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android popupmenu使应用程序崩溃,未找到资源异常_Java_Android_Xml_Popupmenu - Fatal编程技术网

Java Android popupmenu使应用程序崩溃,未找到资源异常

Java Android popupmenu使应用程序崩溃,未找到资源异常,java,android,xml,popupmenu,Java,Android,Xml,Popupmenu,因此,我得到以下错误: android.content.res.Resources$NotFoundException: File res/drawable/cox_background.xml from color state list resource ID #0x7f02004d at android.content.res.Resource

因此,我得到以下错误:

android.content.res.Resources$NotFoundException: File res/drawable/cox_background.xml from color state list resource ID #0x7f02004d
                                                                           at android.content.res.Resources.loadColorStateListForCookie(Resources.java:2750)
                                                                           at android.content.res.Resources.loadColorStateList(Resources.java:2699)
                                                                           at android.content.res.TypedArray.getColorStateList(TypedArray.java:485)
                                                                           at android.graphics.drawable.GradientDrawable.updateGradientDrawableSolid(GradientDrawable.java:1320)
                                                                           at android.graphics.drawable.GradientDrawable.applyThemeChildElements(GradientDrawable.java:1148)
                                                                           at android.graphics.drawable.GradientDrawable.applyTheme(GradientDrawable.java:1056)
                                                                           at android.content.res.Resources.loadDrawable(Resources.java:2549)
                                                                           at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
                                                                           at android.widget.PopupWindow.<init>(PopupWindow.java:224)
                                                                           at android.widget.PopupWindow.<init>(PopupWindow.java:210)
                                                                           at android.support.v7.widget.AppCompatPopupWindow.<init>(AppCompatPopupWindow.java:44)
                                                                           at android.support.v7.widget.ListPopupWindow.<init>(ListPopupWindow.java:251)
                                                                           at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:139)
                                                                           at android.support.v7.view.menu.MenuPopupHelper.show(MenuPopupHelper.java:129)
                                                                           at android.support.v7.widget.PopupMenu.show(PopupMenu.java:216)
                                                                           at com.coxauto.forcedroidapp.MainActivity$2.onClick(MainActivity.java:166)
                                                                           at android.view.View.performClick(View.java:5204)
                                                                           at android.view.View$PerformClick.run(View.java:21153)
                                                                           at android.os.Handler.handleCallback(Handler.java:739)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                           at android.os.Looper.loop(Looper.java:148)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                        Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid color state list tag shape
                                                                           at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:217)
                                                                           at android.content.res.ColorStateList.createFromXml(ColorStateList.java:201)
                                                                           at android.content.res.Resources.loadColorStateListForCookie(Resources.java:2746)
                                                                           at android.content.res.Resources.loadColorStateList(Resources.java:2699) 
                                                                           at android.content.res.TypedArray.getColorStateList(TypedArray.java:485) 
                                                                           at android.graphics.drawable.GradientDrawable.updateGradientDrawableSolid(GradientDrawable.java:1320) 
                                                                           at android.graphics.drawable.GradientDrawable.applyThemeChildElements(GradientDrawable.java:1148) 
                                                                           at android.graphics.drawable.GradientDrawable.applyTheme(GradientDrawable.java:1056) 
                                                                           at android.content.res.Resources.loadDrawable(Resources.java:2549) 
                                                                           at android.content.res.TypedArray.getDrawable(TypedArray.java:870) 
                                                                           at android.widget.PopupWindow.<init>(PopupWindow.java:224) 
                                                                           at android.widget.PopupWindow.<init>(PopupWindow.java:210) 
                                                                           at android.support.v7.widget.AppCompatPopupWindow.<init>(AppCompatPopupWindow.java:44) 
                                                                           at android.support.v7.widget.ListPopupWindow.<init>(ListPopupWindow.java:251) 
                                                                           at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:139) 
                                                                           at android.support.v7.view.menu.MenuPopupHelper.show(MenuPopupHelper.java:129) 
                                                                           at android.support.v7.widget.PopupMenu.show(PopupMenu.java:216) 
                                                                           at com.coxauto.forcedroidapp.MainActivity$2.onClick(MainActivity.java:166) 
                                                                           at android.view.View.performClick(View.java:5204) 
                                                                           at android.view.View$PerformClick.run(View.java:21153) 
                                                                           at android.os.Handler.handleCallback(Handler.java:739) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                           at android.os.Looper.loop(Looper.java:148) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
contacts_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:icon="@drawable/call_page1">

<item
    android:id="@+id/sales_rep"
    android:title="@string/sales_rep">

</item>

<item
    android:id="@+id/rewards_cons"
    android:title="@string/rewards_cons">

</item>
</menu>

任何帮助都将不胜感激。这应该是一件简单的事情,但由于某种原因给我带来了很多麻烦。我尝试将anchorview切换到imagebutton的父级,但也没有成功。到目前为止,我有一个预感,这是一个布局问题

编辑:cox_background.xml也是res文件夹中的可绘制文件。这是以防万一

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

<gradient
    android:startColor="#003469"
    android:centerColor="#003C72"
    android:endColor="#0585c8"
    android:angle="315"/>
</shape>

Edit2:cox_background.xml位于res/drawable文件夹中。在运行Marmallow的Google Nexus 5X上进行测试

Edit3:call_page1.png位于可绘制hdpi、可绘制mdpi、可绘制xhdpi、可绘制xxhdpi、可绘制xxxhdpi文件夹中


这些是透明图像。

因此我在这里发现了问题。在styles.xml中,我为整个应用程序定义了一个要遵循的样式(我主要使用主题编辑器创建了这个样式)。我为背景变量指定了一个drawable。我想直到现在,当应用程序尝试使用菜单时,这才给我带来问题

<style name="CoxTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@android:color/transparent</item>
    <!-- This cannot be a drawable. Must be a color-->
    <item name="android:colorBackground">@drawable/cox_background</item>
    <item name="android:textColorPrimary">@color/cox_text_primary</item>
    <item    name="android:textColorSecondary">@color/secondary_text_material_light</item>
    <item name="android:textColorPrimaryInverse">@color/primary_text_material_dark</item>
    <item name="android:screenOrientation">portrait</item>
    <item name="colorAccent">@color/cox_accent</item>
</style>

@android:彩色/透明
@可绘制/考克斯图背景
@颜色/cox\u文本\u主
@颜色/次要\u文本\u材质\u灯光
@颜色/原色\u文字\u材质\u深色
肖像
@颜色/考克斯口音

您是否尝试删除这行代码android:background=“@drawable/cox_background”并测试它是否仍然崩溃?我想这与drawable call_Page1有关,我可以看到drawable吗?Nolly:是的,我尝试删除android:background=“@drawable/cox_background”。这就是以前的情况,我认为将背景设置为drawable会有所帮助。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<gradient
    android:startColor="#003469"
    android:centerColor="#003C72"
    android:endColor="#0585c8"
    android:angle="315"/>
</shape>
<style name="CoxTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@android:color/transparent</item>
    <!-- This cannot be a drawable. Must be a color-->
    <item name="android:colorBackground">@drawable/cox_background</item>
    <item name="android:textColorPrimary">@color/cox_text_primary</item>
    <item    name="android:textColorSecondary">@color/secondary_text_material_light</item>
    <item name="android:textColorPrimaryInverse">@color/primary_text_material_dark</item>
    <item name="android:screenOrientation">portrait</item>
    <item name="colorAccent">@color/cox_accent</item>
</style>