尝试模拟App时出现Java.Lang.RunTimeException错误

时间:2019-04-20 16:02:47

标签: android xamarin.forms xamarin.android

为Xamarin.Android项目构建启动画面。我的错误如下:

com.shaneckeney.spikeballsampleapp:drawable/splash_background_revised with resource ID #0x7f02012c ---> 
Android.Content.Res.Resources+NotFoundException: Drawable com.shaneckeney.spikeballsampleapp:drawable/splash_background_revised with resource ID #0x7f02012c ---> 
Android.Content.Res.Resources+NotFoundException: File res/drawable/splash_background_revised.xml from drawable resource ID #0x7f02012c ---> 
Android.Views.InflateException: Class not found RelativeLayout ---> 
Java.Lang.ClassNotFoundException: Didn't find class "RelativeLayout" on path: DexPathList[[zip file "/data/app/com.shaneckeney.spikeballsampleapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.shaneckeney.spikeballsampleapp-1/lib/x86, /data/app/com.shaneckeney.spikeballsampleapp-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]
  at java.lang.ClassNotFoundException: Didn't find class "RelativeLayout" on path: DexPathList[[zip file "/data/app/com.shaneckeney.spikeballsampleapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.shaneckeney.spikeballsampleapp-1/lib/x86, /data/app/com.shaneckeney.spikeballsampleapp-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]
  at at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
  at at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
  at at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
  at at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:187)
  at at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:128)
  at at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)
  at at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200)
  at at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715)
  at at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
  at at android.content.res.Resources.getDrawable(Resources.java:771)
  at at android.content.Context.getDrawable(Context.java:525)
  at at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2577)
  at at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2627)
  at at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2047)
  at at android.app.ActivityTransitionState.setEnterActivityOptions(ActivityTransitionState.java:158)
  at at android.app.Activity.performCreateCommon(Activity.java:6674)
  at at android.app.Activity.performCreate(Activity.java:6681)
  at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
  at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
  at at android.app.ActivityThread.-wrap12(ActivityThread.java)
  at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
  at at android.os.Handler.dispatchMessage(Handler.java:102)
  at at android.os.Looper.loop(Looper.java:154)
  at at android.app.ActivityThread.main(ActivityThread.java:6119)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  --- End of inner exception stack trace ---
  at android.view.InflateException: Class not found RelativeLayout
  at at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:206)
  at at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:128)
  at at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)
  at at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200)
  at at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715)
  at at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
  at at android.content.res.Resources.getDrawable(Resources.java:771)
  at at android.content.Context.getDrawable(Context.java:525)
  at at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2577)
  at at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2627)
  at at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2047)
  at at android.app.ActivityTransitionState.setEnterActivityOptions(ActivityTransitionState.java:158)
  at at android.app.Activity.performCreateCommon(Activity.java:6674)
  at at android.app.Activity.performCreate(Activity.java:6681)
  at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
  at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
  at at android.app.ActivityThread.-wrap12(ActivityThread.java)
  at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
  at at android.os.Handler.dispatchMessage(Handler.java:102)
  at at android.os.Looper.loop(Looper.java:154)
  at at android.app.ActivityThread.main(ActivityThread.java:6119)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  at Caused by: java.lang.ClassNotFoundException: Didn't find class "RelativeLayout" on path: DexPathList[[zip file "/data/app/com.shaneckeney.spikeballsampleapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.shaneckeney.spikeballsampleapp-1/lib/x86, /data/app/com.shaneckeney.spikeballsampleapp-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]
  at at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
  at at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
  at at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
  at at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:187)
  at ... 24 more
  --- End of inner exception stack trace ---
  at android.content.res.Resources$NotFoundException: File res/drawable/splash_background_revised.xml from drawable resource ID #0x7f02012c
  at at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:725)
  at at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
  at at android.content.res.Resources.getDrawable(Resources.java:771)
  at at android.content.Context.getDrawable(Context.java:525)
  at at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2577)
  at at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2627)
  at at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2047)
  at at android.app.ActivityTransitionState.setEnterActivityOptions(ActivityTransitionState.java:158)
  at at android.app.Activity.performCreateCommon(Activity.java:6674)
  at at android.app.Activity.performCreate(Activity.java:6681)
  at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
  at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
  at at android.app.ActivityThread.-wrap12(ActivityThread.java)
  at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
  at at android.os.Handler.dispatchMessage(Handler.java:102)
  at at android.os.Looper.loop(Looper.java:154)
  at at android.app.ActivityThread.main(ActivityThread.java:6119)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  at Caused by: android.view.InflateException: Class not found RelativeLayout
  at at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:206)
  at at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:128)
  at at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)
  at at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200)
  at at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715)
  at ... 20 more
  at Caused by: java.lang.ClassNotFoundException: Didn't find class "RelativeLayout" on path: DexPathList[[zip file "/data/app/com.shaneckeney.spikeballsampleapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.shaneckeney.spikeballsampleapp-1/lib/x86, /data/app/com.shaneckeney.spikeballsampleapp-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]
  at at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
  at at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
  at at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
  at at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:187)
  at ... 24 more
  --- End of inner exception stack trace ---
  at android.content.res.Resources$NotFoundException: Drawable com.shaneckeney.spikeballsampleapp:drawable/splash_background_revised with resource ID #0x7f02012c
  at Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_background_revised.xml from drawable resource ID #0x7f02012c
  at at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:725)
  at at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
  at at android.content.res.Resources.getDrawable(Resources.java:771)
  at at android.content.Context.getDrawable(Context.java:525)
  at at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2577)
  at at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2627)
  at at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2047)
  at at android.app.ActivityTransitionState.setEnterActivityOptions(ActivityTransitionState.java:158)
  at at android.app.Activity.performCreateCommon(Activity.java:6674)
  at at android.app.Activity.performCreate(Activity.java:6681)
  at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
  at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
  at at android.app.ActivityThread.-wrap12(ActivityThread.java)
  at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
  at at android.os.Handler.dispatchMessage(Handler.java:102)
  at at android.os.Looper.loop(Looper.java:154)
  at at android.app.ActivityThread.main(ActivityThread.java:6119)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  at Caused by: android.view.InflateException: Class not found RelativeLayout
  at at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:206)
  at at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:128)
  at at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)
  at at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200)
  at at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715)
  at ... 20 more
  at Caused by: java.lang.ClassNotFoundException: Didn't find class "RelativeLayout" on path: DexPathList[[zip file "/data/app/com.shaneckeney.spikeballsampleapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.shaneckeney.spikeballsampleapp-1/lib/x86, /data/app/com.shaneckeney.spikeballsampleapp-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]
  at at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
  at at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
  at at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
  at at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:187)
  at ... 24 more
  --- End of inner exception stack trace ---
  at java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shaneckeney.spikeballsampleapp/md53db0ce6492013f19d1c303097dfcfb72.SplashActivity}: android.content.res.Resources$NotFoundException: Drawable com.shaneckeney.spikeballsampleapp:drawable/splash_background_revised with resource ID #0x7f02012c
  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
  at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
  at at android.app.ActivityThread.-wrap12(ActivityThread.java)
  at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
  at at android.os.Handler.dispatchMessage(Handler.java:102)
  at at android.os.Looper.loop(Looper.java:154)
  at at android.app.ActivityThread.main(ActivityThread.java:6119)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  at Caused by: android.content.res.Resources$NotFoundException: Drawable com.shaneckeney.spikeballsampleapp:drawable/splash_background_revised with resource ID #0x7f02012c
  at Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_background_revised.xml from drawable resource ID #0x7f02012c
  at at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:725)
  at at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
  at at android.content.res.Resources.getDrawable(Resources.java:771)
  at at android.content.Context.getDrawable(Context.java:525)
  at at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2577)
  at at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2627)
  at at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2047)
  at at android.app.ActivityTransitionState.setEnterActivityOptions(ActivityTransitionState.java:158)
  at at android.app.Activity.performCreateCommon(Activity.java:6674)
  at at android.app.Activity.performCreate(Activity.java:6681)
  at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
  at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
  at at android.app.ActivityThread.-wrap12(ActivityThread.java)
  at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
  at at android.os.Handler.dispatchMessage(Handler.java:102)
  at at android.os.Looper.loop(Looper.java:154)
  at at android.app.ActivityThread.main(ActivityThread.java:6119)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  at Caused by: android.view.InflateException: Class not found RelativeLayout
  at at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:206)
  at at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:128)
  at at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)
  at at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200)
  at at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715)
  at ... 20 more
  at Caused by: java.lang.ClassNotFoundException: Didn't find class "RelativeLayout" on path: DexPathList[[zip file "/data/app/com.shaneckeney.spikeballsampleapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.shaneckeney.spikeballsampleapp-1/lib/x86, /data/app/com.shaneckeney.spikeballsampleapp-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]
  at at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
  at at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
  at at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
  at at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:187)
  at ... 24 more

我的XML代码如下:

splash_background_revised.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/splashlogo" />

</RelativeLayout>

如果我更改XML代码以使用以下代码,则可以解决该错误,但是我想对正在使用的图像容器使用ImageView,以便可以缩放它以使其更适合屏幕。 / p>

splash_background.xml

  <item>
    <color android:color="#FF000000"/>
  </item>
  <item>   
    <bitmap
        android:src="@drawable/splashlogo"
        android:gravity="center"/>
  </item>
</layer-list>

下面列出了我的styles.xml,我可以简单地将android:windowBackground属性更改为splash_background.xml或splash_background_revised.xml,第一个可以正常工作,第二个可以使Java.Lang.RunTimeException开头。

<resources>

    <style name="MainTheme" parent="MainTheme.Base">
    </style>
    <!-- Base theme applied no matter what API -->
    <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
        <item name="windowNoTitle">true</item>
        <!--We will be using the toolbar so no need to show ActionBar-->
        <item name="windowActionBar">false</item>
        <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
        <!-- colorPrimary is used for the default action bar background -->
        <item name="colorPrimary">#2196F3</item>
        <!-- colorPrimaryDark is used for the status bar -->
        <item name="colorPrimaryDark">#1976D2</item>
        <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
        <item name="colorAccent">#FF4081</item>
        <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. -->
        <item name="windowActionModeOverlay">true</item>
        <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
    </style>
    <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">#FF4081</item>
    </style>

  <style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_background_revised</item>
    <item name="android:windowNoTitle">true</item>
  </style>

</resources>

这是我第一次使用Xamarin,并且正在构建示例移动应用程序进行练习,但似乎无法在此找到答案。

1 个答案:

答案 0 :(得分:1)

您可以尝试删除项目中的binobj文件夹。然后重新构建您的项目。这种想法会消失。