我的Android Studio应用程序收到渲染错误。它说“无法解决资源”,后来“无法转换成Drawable”。详情如下:
java.lang.NumberFormatException: Color value '@drawable/breakfast_lto' must start with #
at com.android.layoutlib.bridge.impl.ResourceHelper.getColor(ResourceHelper.java:79)
at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:270)
at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:742)
at android.view.View.<init>(View.java:3948)
at android.widget.ImageView.<init>(ImageView.java:145)
at android.widget.ImageButton.<init>(ImageButton.java:84)
at android.widget.ImageButton.<init>(ImageButton.java:80)
at android.widget.ImageButton.<init>(ImageButton.java:76)
at sun.reflect.GeneratedConstructorAccessor113.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.BridgeInflater.onCreateView(BridgeInflater.java:107)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:149)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:229)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:510)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:498)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498)
at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:610)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:362)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:652)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:80)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:594)
at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:152)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:137)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:589)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:351)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
drawable是.png图像,但它似乎是将其作为颜色值读取。可能是什么问题。
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:gravity="center">
<LinearLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="midamcorp.com.burgerkingapp.breakfastHome"
tools:showIn="@layout/activity_breakfast_home">
<TextView android:text="Breakfast" android:id="@+id/headerText" android:textColor="@color/colorAccent" android:textSize="48dp" android:textAlignment="center" android:layout_marginBottom="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"/>
<ImageButton android:background="@drawable/breakfast_lto" android:id="@+id/breakfastLTOButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="50dp"
android:id="@+id/breakfastListContainer"
></ListView>
<ImageButton android:background="@drawable/breakfast_standard" android:id="@+id/breakfastStandardButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/viewLunchButton"
android:background="@drawable/lunch_icon"
android:layout_gravity="right"/>
</LinearLayout>
</ScrollView>
谢谢!
答案 0 :(得分:3)
尝试更换
android:background="@drawable/breakfast_lto"
用这个
android:src="@drawable/breakfast_lto" />
答案 1 :(得分:2)
android:background 属性需要一种颜色。
请尝试使用 android:src 属性。
答案 2 :(得分:0)
关闭你的项目并重新启动它。我不知道为什么,但对于我的项目,它可以解决问题。
答案 3 :(得分:0)
我遇到了同样的问题。我的xml看起来像这样:
<uk.co.senab.photoview.PhotoView
android:id="@+id/transitmap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/mypicture"
android:background="#00FFFFFF"/> // had to add color because of the error, but knocked opacity down to zero
出于某种原因,我仍然收到错误。奇怪的是,重新启动Android Studio会使错误消失,而不会对我进行额外的代码更改。
答案 4 :(得分:0)
有些人提到重启IDE已经有效,但这对我没用。
相反,我发现我必须简单地重命名图像文件,以便它不以数字开头。 Android Developer Icon Pack中的所有图标都以数字开头,我刚刚复制了一个。看来,如果文件以数字开头,则假定它是十六进制颜色值的开头,因此会查找#符号。
使用:Eclipse Juno 3.7.2,Android SDK 21.1&amp;&amp; Android Studio