浏览视图时出错

时间:2017-06-20 19:44:21

标签: java android android-layout

尝试使用Android studio运行我的应用时遇到错误 我试图更改Image并且它正常运行但是当我放置我的图像时它不会运行。

出现错误的图片:

enter image description here

这是我的代码布局:

    

这是我的活动:

public class AppActivity extends ActivityBase {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app);         
    }
}

这是我得到的错误:

  AndroidRuntime: FATAL EXCEPTION: main
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.ifsoft.qachat/ru.ifsoft.qachat.AppActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class ImageView
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
                      at android.app.ActivityThread.access$600(ActivityThread.java:128)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
                      at android.os.Handler.dispatchMessage(Handler.java:99)
                      at android.os.Looper.loop(Looper.java:137)
                      at android.app.ActivityThread.main(ActivityThread.java:4517)
                      at java.lang.reflect.Method.invokeNative(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:511)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
                      at dalvik.system.NativeStart.main(Native Method)
                   Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class ImageView
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                      at ru.ifsoft.qachat.AppActivity.onCreate(AppActivity.java:39)
                      at android.app.Activity.performCreate(Activity.java:4470)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995) 
                      at android.app.ActivityThread.access$600(ActivityThread.java:128) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161) 
                      at android.os.Handler.dispatchMessage(Handler.java:99) 
                      at android.os.Looper.loop(Looper.java:137) 
                      at android.app.ActivityThread.main(ActivityThread.java:4517) 
                      at java.lang.reflect.Method.invokeNative(Native Method) 
                      at java.lang.reflect.Method.invoke(Method.java:511) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760) 
                      at dalvik.system.NativeStart.main(Native Method) 
                   Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f020426 a=-1 r=0x7f020426}
                      at android.content.res.Resources.loadDrawable(Resources.java:1960)
                      at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
                      at android.widget.ImageView.<init>(ImageView.java:119)
                      at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:60)
                      at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:56)
                      at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
                      at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1021)
                      at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1080)
                      at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:668)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:739) 
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:742) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288) 
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                      at ru.ifsoft.qachat.AppActivity.onCreate(AppActivity.java:39) 
                      at android.app.Activity.performCreate(Activity.java:4470) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995) 
                      at android.app.ActivityThread.access$600(ActivityThread.java:128) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161) 
                      at android.os.Handler.dispatchMessage(Handler.java:99) 
                      at android.os.Looper.loop(Looper.java:137) 
                      at android.app.ActivityThread.main(ActivityThread.java:4517) 
                      at java.lang.reflect.Method.invokeNative(Native Method) 
                      at java.lang.reflect.Method.invoke(Method.java:511)

1 个答案:

答案 0 :(得分:0)

你的设备不是hdpi所以当android运行它时,它会查找相应文件夹中的图像并崩溃,因为它无法找到它。你可以

  1. 将图像放入所有可绘制文件夹ldpi,hdpi,xhdpi,mdpi,xxhdpi和xxxhdpi。

  2. 或者,你只能把它放在&#34; drawable&#34;夹

    folder structure