运行安卓程序报错android.view.InflateException: Binary XML file line #11: Error inflating class ImageView

先上代码

布局代码

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"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:columnCount="3"android:rowCount="6"tools:context=".MainActivity"><ImageViewandroid:id="@+id/imageQQ"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/qqimage"android:layout_rowSpan="6"></ImageView><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="用户名"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /><EditTextandroid:layout_width="85dp"android:id="@+id/username"></EditText><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="密码"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /><EditTextandroid:layout_width="85dp"android:id="@+id/password"android:inputType="textPassword"></EditText><RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_columnSpan="2"android:id="@+id/rg"><RadioButtonandroid:text="男"android:checked="true"android:layout_height="wrap_content"android:layout_width="wrap_content"></RadioButton><RadioButton android:text="女"android:layout_height="wrap_content"android:layout_width="wrap_content"></RadioButton></RadioGroup><CheckBoxandroid:id="@+id/savepassword"android:text="记住密码"></CheckBox><CheckBoxandroid:id="@+id/autologin"android:text="自动登录"></CheckBox><Buttonandroid:text="注册"android:id="@+id/register"></Button><Buttonandroid:text="登录"android:id="@+id/login"></Button><TextView android:id="@+id/show"android:text=""android:layout_columnSpan="2"></TextView>
</GridLayout>

java代码

public class MainActivity extends AppCompatActivity {EditText userName;EditText passWord;RadioGroup rg;CheckBox savePassword;CheckBox autoLogin;TextView show;Button loginButton;@Overrideprotected void onCreate(final Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);userName = (EditText) findViewById(R.id.username);passWord = (EditText) findViewById(R.id.password);rg = (RadioGroup) findViewById(R.id.rg);savePassword = (CheckBox) findViewById(R.id.savepassword);autoLogin = (CheckBox) findViewById(R.id.autologin);show = (TextView) findViewById(R.id.show);loginButton = (Button) findViewById(R.id.login);loginButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {String username = userName.getText().toString();String password = passWord.getText().toString();String sex = null;boolean savepassword = savePassword.isChecked();boolean autologin = autoLogin.isChecked();for (int i = 0; i < rg.getChildCount(); i++) {RadioButton rb = (RadioButton) rg.getChildAt(i);if (rb.isChecked()) {sex = (String) rb.getText();break;}}show.setText("用户名:" + username + "\n" +"密码:" + password + "\n" +"性别" + sex + "\n" +"记住密码" + savepassword + "\n" +"自动登录" + autologin);}});}
}

问题

上午经历过软测比赛的挫败,感觉只能无奈写写安卓实验。边看B站教程边看书边敲代码,总算布局搞定了,组件搞定了,监听器内容也搞定了。 在满心期待的心情下点下了run去运行虚拟机,结果app打开后立马弹出一个框。


我:wtf这什么情况???

好吧,作为一个成熟的准程序员,是不可能被bug给打败的,程序员的工作不就是改 (写) bug吗,我怎么可能就此止步,于是开始了我剩余三个小时的debug之旅。网上各种查技术博客与论坛,有人说是代码写错了,而且还是不会报错的那种。
好吧,成熟的准程序员不可能被打败。又花了一个小时看代码,没错啊。
我:玩我???

又翻了一会博客,在我即将放弃做一名成熟的准程序员时,我发现了营救我职业的曙光。

问题及解决方法

在logcat我发现在这个报错:android.view.InflateException: Binary XML file line #11: Error inflating class ImageView,说明ImageView出错了,这部分代码不多,于是上网对这上面搜了下。

自己在开发过程中一般习惯都在Android模式下,res目录下文件夹只有几个。切换到在Project模式下,res目录下除了drawable文件夹、还有drawable-v24文件夹,发现自己的图片竟然是放在drawable-v24下,导致在低分辨率手机上无法找到图片而报错,可能问题就出在这里。



再加上我的SDK虽然是Android 29(安卓9),但是我的运行环境是安卓5.0,默认去寻找drawable文件夹下的资源,这样就造成了在运行时找不到这个资源。

从Android API 24(安卓7.0)开始,自定义Drawables类可以最终在XML中使用,不同的drawable文件夹用于为设备兼容性和不同的Android版本提供不同的屏幕密度。

解决方法很简单,把你的资源放进drawable文件夹,不要放在drawable-v24文件夹下,否则安卓找不到资源,就会认为你写错了。

多多点赞关注谢谢各位大佬

运行安卓程序报错android.view.InflateException: Binary XML file line #11: Error inflating class ImageView相关推荐

  1. 报错android.view.InflateException: Binary XML file line #11: Attempt to invoke virtual method 'boolean

    出现这种问题,打开Android monitor的调试信息发现是 android.view.InflateException: Binary XML file line #11: Attempt to ...

  2. Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class lzl.edu.c

    在自定义view中常常会出现这么一个错误 Caused by: android.view.InflateException: Binary XML file line #12: Error infla ...

  3. android.view.InflateException: Binary XML file line #34: Error inflating class

    问题一般出在xml的第三方View的全类名,你可能是直接粘贴过来的,没有改成自己项目的全类名. 转载于:https://www.cnblogs.com/libuyi/p/5940182.html

  4. android.view.InflateException: Binary XML file line #10: Error inflating class com.android.xiong.han

    自定定义控件   缺少构造器 public DrawView(Context context, AttributeSet paramAttributeSe) {super(context, param ...

  5. android.view.inflateexception binary xml file line 异常的解决方法

    有时候一个很简单的xml布局文件,运行却抛出以下异常: 07-25 10:40:50.966: D/AndroidRuntime(31570): Shutting down VM 07-25 10:4 ...

  6. Android stuido 解决Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file

    Android stuido 解决Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file ...

  7. android.view.InflateException: Binary XML file line #7: Binary XML file line #7

    错误如下 11-21 08:19:44.040 3608-3608/com.leon.oldrecyclerview E/AndroidRuntime: FATAL EXCEPTION: main   ...

  8. Android运行时候报错:android.view.InflateException: Binary XML file line #19: Binary XML file lin

    Android运行时候报错:android.view.InflateException: Binary XML file line #19: Binary XML file lin 这个问题自己大致在 ...

  9. android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating

    android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating cla ...

最新文章

  1. webspere php,Project Zero、WebSphere sMash、PHP和JAVA的整合
  2. 洛谷P3357:最长k可重线段集问题(网络流)
  3. datagrid底部显示水平滚动_看完《惊奇队长》等彩蛋,我想到了一个制作PPT滚动字幕的方法...
  4. 单主机Docker容器VLAN划分
  5. 电子书下载:Construct Game Development Beginner's Guide
  6. php 跨域解决方案
  7. 软件测试项目案例.pdf,【精选】最经典软件测试案例.pdf
  8. Disunity_V0.5.0 提取Unity生成的Apk的资源
  9. 《Using OpenRefine》翻译~17
  10. john破解kali密码
  11. cruzer php sandisk 闪迪u盘量产工具_SanDisk Cruzer CZ36闪迪U盘 怎么量产
  12. LeetCode 520. Detect Capital
  13. 玩转NFT夏季:这份工具宝典值得收藏
  14. 香港马市、田忌赛马?这款游戏 IP 碉堡了
  15. 新建的web项目为什么默认访问index.jsp
  16. 备份恢复Lesson 09. Diagnosing Failures
  17. STM32单片机扫雷游戏TFT触摸操作单片机小游戏
  18. 反射型XSS实战演练
  19. 信息无障碍 - 改造指南
  20. Python序列类型及操作

热门文章

  1. 医程通 服务器维护,启用医程通,妇幼版“抢车位”有望缓解
  2. 导入matlab某两列数据,将文本文件中的数据导入到matlab中一例(wwh)
  3. 2015年,我买了台i7 4790k主机
  4. 新学期如何学好java?
  5. Kooboo完全介绍二:创建第一个Kooboo站点
  6. 换个你喜欢的微信头像吧
  7. JavaScript之 刷雨课堂PPT
  8. Android弧形SeekBar的设计与实现
  9. udp user datagram protocol
  10. win10防火墙, 导致其他主机ping不通它