为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作为我正在使用的图像的容器,以便我可以缩放它以更好地适应屏幕。
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并正在构建一个示例移动应用程序进行练习,但似乎无法在此处找到答案。
您可以尝试删除项目中的bin
和obj
文件夹。然后重新构建你的项目。这个例子将消失。