我的Android應用程序使用英語,我也必須爲用戶提供阿拉伯語版本。我做了以下,Android:在嘗試向我的應用程序中添加另一種語言後出現膨脹異常
- 添加了一個佈局ar文件夾,並把我的佈局文件在那裏。
- 添加了一個drawable-ar文件夾,並將圖像放在那裏。
- 增加了一個值-AR文件夾和翻譯我的字符串資源的strings.xml
- 我在模擬器改變了語言設置爲阿拉伯語測試
雖然我的應用程序的英文版本工作正常,我阿拉伯語版本現在用以下日誌跟蹤
06-20 10:08:13.153: E/AndroidRuntime(623): FATAL EXCEPTION: main
06-20 10:08:13.153: E/AndroidRuntime(623): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.digitalhealthagency.elaj.gui/org.digitalhealthagency.elaj.gui.SplashScreen}: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.ImageView
06-20 10:08:13.153: E/AndroidRuntime(623): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.os.Looper.loop(Looper.java:137)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-20 10:08:13.153: E/AndroidRuntime(623): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 10:08:13.153: E/AndroidRuntime(623): at java.lang.reflect.Method.invoke(Method.java:511)
06-20 10:08:13.153: E/AndroidRuntime(623): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-20 10:08:13.153: E/AndroidRuntime(623): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-20 10:08:13.153: E/AndroidRuntime(623): at dalvik.system.NativeStart.main(Native Method)
06-20 10:08:13.153: E/AndroidRuntime(623): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.ImageView
06-20 10:08:13.153: E/AndroidRuntime(623): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
06-20 10:08:13.153: E/AndroidRuntime(623): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-20 10:08:13.153: E/AndroidRuntime(623): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.app.Activity.setContentView(Activity.java:1835)
06-20 10:08:13.153: E/AndroidRuntime(623): at org.digitalhealthagency.elaj.gui.SplashScreen.onCreate(SplashScreen.java:16)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.app.Activity.performCreate(Activity.java:4465)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-20 10:08:13.153: E/AndroidRuntime(623): ... 11 more
06-20 10:08:13.153: E/AndroidRuntime(623): Caused by: java.lang.reflect.InvocationTargetException
06-20 10:08:13.153: E/AndroidRuntime(623): at java.lang.reflect.Constructor.constructNative(Native Method)
06-20 10:08:13.153: E/AndroidRuntime(623): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
06-20 10:08:13.153: E/AndroidRuntime(623): ... 24 more
06-20 10:08:13.153: E/AndroidRuntime(623): Caused by: java.lang.OutOfMemoryError
06-20 10:08:13.153: E/AndroidRuntime(623): at android.graphics.Bitmap.nativeCreate(Native Method)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.content.res.Resources.loadDrawable(Resources.java:1935)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.widget.ImageView.<init>(ImageView.java:119)
06-20 10:08:13.153: E/AndroidRuntime(623): at android.widget.ImageView.<init>(ImageView.java:109)
06-20 10:08:13.153: E/AndroidRuntime(623): ... 27 more
錯誤日誌是指在其中設置內容視圖我閃屏的java文件到第16行崩潰setContentView(R.layout.splash_screen);
而且我splash_screen.xml文件如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/splash_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@drawable/splash_screen" />
</LinearLayout>
,這個問題很類似地雷Android: How to track down the origin of a InflateException?但固定的風格不解決問題。
預先感謝您!
EDIT
減小圖像的大小由阿萊克斯G作爲建議之後,圖像正常加載,但現在我在不同的地方得到一個類似的錯誤。 88
06-20 14:27:22.157: E/AndroidRuntime(623): FATAL EXCEPTION: main
06-20 14:27:22.157: E/AndroidRuntime(623): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.digitalhealthagency.elaj.gui/org.digitalhealthagency.elaj.gui.AppointmentReservationActivity}: android.view.InflateException: Binary XML file line #99: Error inflating class <unknown>
06-20 14:27:22.157: E/AndroidRuntime(623): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.os.Looper.loop(Looper.java:137)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-20 14:27:22.157: E/AndroidRuntime(623): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 14:27:22.157: E/AndroidRuntime(623): at java.lang.reflect.Method.invoke(Method.java:511)
06-20 14:27:22.157: E/AndroidRuntime(623): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-20 14:27:22.157: E/AndroidRuntime(623): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-20 14:27:22.157: E/AndroidRuntime(623): at dalvik.system.NativeStart.main(Native Method)
06-20 14:27:22.157: E/AndroidRuntime(623): Caused by: android.view.InflateException: Binary XML file line #99: Error inflating class <unknown>
06-20 14:27:22.157: E/AndroidRuntime(623): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
06-20 14:27:22.157: E/AndroidRuntime(623): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-20 14:27:22.157: E/AndroidRuntime(623): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.app.Activity.setContentView(Activity.java:1835)
06-20 14:27:22.157: E/AndroidRuntime(623): at org.digitalhealthagency.elaj.gui.AppointmentReservationActivity.onCreate(AppointmentReservationActivity.java:88)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.app.Activity.performCreate(Activity.java:4465)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-20 14:27:22.157: E/AndroidRuntime(623): ... 11 more
06-20 14:27:22.157: E/AndroidRuntime(623): Caused by: java.lang.reflect.InvocationTargetException
06-20 14:27:22.157: E/AndroidRuntime(623): at java.lang.reflect.Constructor.constructNative(Native Method)
06-20 14:27:22.157: E/AndroidRuntime(623): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
06-20 14:27:22.157: E/AndroidRuntime(623): ... 24 more
06-20 14:27:22.157: E/AndroidRuntime(623): Caused by: java.lang.OutOfMemoryError
06-20 14:27:22.157: E/AndroidRuntime(623): at android.graphics.Bitmap.nativeCreate(Native Method)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.content.res.Resources.loadDrawable(Resources.java:1935)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.content.res.Resources.getDrawable(Resources.java:664)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:867)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:804)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.content.res.Resources.loadDrawable(Resources.java:1920)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.view.View.<init>(View.java:2785)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.widget.TextView.<init>(TextView.java:449)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.widget.Button.<init>(Button.java:108)
06-20 14:27:22.157: E/AndroidRuntime(623): at android.widget.Button.<init>(Button.java:104)
06-20 14:27:22.157: E/AndroidRuntime(623): ... 27 more
行日誌跟蹤指的是
setContentView(R.layout.appointment_reservation);
和線路#99 appointment_reservation.xml是
<Button android:id="@+id/reserve_button"
android:text="@string/reserve_button"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:paddingRight="15dp"
android:layout_gravity="left"
style="@style/buttonStyle"
android:background="@drawable/button_selector" />
我給按鈕,放置在button_selector xml文件在我的可繪製文件夾中。選擇器在兩張圖像之間切換(總大小爲6kb)。
預先感謝您!
謝謝您的回覆。您能否澄清一下您的圖像對於kb而言意味着什麼含義太大?我的原始圖像是550 kb,當我將它縮小到175 kb時,圖像終於出現在模擬器上。但是我仍然得到了應該出現的第二個xml佈局的非常類似的錯誤日誌跟蹤。我的英文和阿拉伯文版本的圖像尺寸完全相同。 –
現在它給了我一個android.view.InflateException:二進制XML文件行#2:錯誤膨脹類,而不是像它以前那樣反對imageView。 –
@NouranH「圖像大小」不是圖像文件的大小,而是解碼位圖的大小。你可以有一個175KB的png文件,當解碼成RAW位圖時,這個文件將超過5MB。 –