Dar*_*ony 16 android android-resources
一位 Android 用户在 Nexus 5X 设备上发生了崩溃,并报告如下:
Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{package.MainActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class ImageView
android.app.ActivityThread.performLaunchActivity
Caused by android.view.InflateException
Binary XML file line #8: Binary XML file line #8: Error inflating class ImageView
Caused by android.view.InflateException
Binary XML file line #8: Error inflating class ImageView
Caused by android.content.res.Resources$NotFoundException
Drawable (missing name) with resource ID #0x7f0700b8
Caused by android.content.res.Resources$NotFoundException
Unable to find resource ID #0x7f0700b8
Run Code Online (Sandbox Code Playgroud)
指向Mainactivity中的第61行:MainActivity.onCreate(MainActivity.java:61),也就是这一行:
this.setContentView(R.layout.activity_main);
Run Code Online (Sandbox Code Playgroud)
我发现资源 ID #0x7f0700b8 指向我的图像 logo.png,它存在于所有可绘制文件夹(drawable、hdpi、ldpi、mdpi、xhdpi、xxhdpi、xxxhdpi)中,所以我不明白为什么可绘制是没有找到或者是什么问题。
XML 中的图像视图如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bgmain">
<ImageView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:contentDescription="@string/hrady_a_zamky"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:paddingTop="0dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/logo" />
Run Code Online (Sandbox Code Playgroud)
和主要活动:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Locale locale = new Locale(lng);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
this.getResources().updateConfiguration(config, this.getResources().getDisplayMetrics());
this.setContentView(R.layout.activity_main);
ImageView language = findViewById(R.id.lang);
ImageView logo = findViewById(R.id.logo);
ImageView award = findViewById(R.id.award);
if (lng.equals("sk")) {
language.setImageResource(R.drawable.en);
logo.setImageResource(R.drawable.logo);
}
else { language.setImageResource(R.drawable.sk);
logo.setImageResource(R.drawable.logoen);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1421 次 |
| 最近记录: |