web-dev-qa-db-ja.com

android.view.InflateException:バイナリXMLファイルの行#2:クラス<unknown>の拡張エラー

シンプルなアプリを開発しています。ホーム画面が完成しました。方向が2回を超えて変化する場合、エラーがスローされ、アプリケーションは強制的に閉じられます。

私の活動コード:

public class PasswordActivity extends Activity implements OnClickListener {
Button login;  
Button forgot;
Button register;  

private static final String PREFERENCES = "prefs";
private static final String PREFERENCES_NAME = "pref_name"; 
SharedPreferences settings;
private Cursor c;

@Override 
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main); 
    login=(Button)findViewById(R.id.login_login);
    login.setOnClickListener(this);
    register=(Button)findViewById(R.id.login_register);
    register.setOnClickListener(this);

}
public void onClick(View v) {
}

}

私のXmlコード:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:orientation="vertical"    
Android:background="@drawable/listpic"
>

<LinearLayout 
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:orientation="horizontal"
Android:paddingTop="5dp"
Android:paddingLeft="3dp"
Android:paddingRight="3dp"
>  
<TextView 
 Android:layout_width="fill_parent"
 Android:layout_weight="0.75"
 Android:layout_height="wrap_content"
 Android:text="@string/login_user_name"
 Android:textStyle="bold"
 />
<EditText 
 Android:layout_width="fill_parent"
 Android:layout_height="wrap_content"
 Android:layout_weight="0.25"
 Android:id="@+id/login_user_name"
 Android:inputType="text"
 />
</LinearLayout>
<LinearLayout 
  Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:orientation="horizontal"
Android:paddingLeft="3dp"
Android:paddingRight="3dp"
  >  
<TextView 
 Android:layout_width="fill_parent"
 Android:layout_weight="0.75"
 Android:layout_height="wrap_content"
 Android:text="@string/login_password"
 Android:textStyle="bold"
 />
<EditText 
 Android:layout_width="fill_parent"
 Android:layout_height="wrap_content"
 Android:layout_weight="0.25"
 Android:inputType="textPassword"
 Android:id="@+id/login_password"
 />
</LinearLayout>

<LinearLayout 
  Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:orientation="horizontal"
Android:paddingLeft="3dp"
Android:paddingRight="3dp"
  >  
<Button 
 style="@style/left_button"
 Android:text="@string/login_submit"
 Android:id="@+id/login_login"
 />

<Button 
  style="@style/right_button"
  Android:id="@+id/login_register"
  Android:text="@string/register"

    />

</LinearLayout>
</LinearLayout>

ログ猫の詳細:

10-21 12:05:59.982: D/dalvikvm(622): GC_EXTERNAL_ALLOC freed 774 objects / 56240 bytes in 61ms
10-21 12:06:15.031: D/dalvikvm(622): GC_EXTERNAL_ALLOC freed 737 objects / 30992 bytes in 59ms
10-21 12:06:18.022: E/dalvikvm-heap(622): 7596000-byte external allocation too large for this process.
10-21 12:06:18.022: E/GraphicsJNI(622): VM won't let us allocate 7596000 bytes
10-21 12:06:18.043: D/AndroidRuntime(622): Shutting down VM
10-21 12:06:18.043: W/dalvikvm(622): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
10-21 12:06:18.092: E/AndroidRuntime(622): FATAL EXCEPTION: main
10-21 12:06:18.092: E/AndroidRuntime(622): Java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ravi.password/com.ravi.password.PasswordActivity}: Android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2663)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.app.ActivityThread.main(ActivityThread.Java:4627)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Java.lang.reflect.Method.invokeNative(Native Method)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Java.lang.reflect.Method.invoke(Method.Java:521)
10-21 12:06:18.092: E/AndroidRuntime(622):  at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:868)
10-21 12:06:18.092: E/AndroidRuntime(622):  at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:626)
10-21 12:06:18.092: E/AndroidRuntime(622):  at dalvik.system.NativeStart.main(Native Method)
10-21 12:06:18.092: E/AndroidRuntime(622): Caused by: Android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.view.LayoutInflater.createView(LayoutInflater.Java:513)
10-21 12:06:18.092: E/AndroidRuntime(622):  at com.Android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.Java:56)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:563)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.view.LayoutInflater.inflate(LayoutInflater.Java:385)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.view.LayoutInflater.inflate(LayoutInflater.Java:320)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.view.LayoutInflater.inflate(LayoutInflater.Java:276)
10-21 12:06:18.092: E/AndroidRuntime(622):  at com.Android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.Java:198)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.app.Activity.setContentView(Activity.Java:1647)
10-21 12:06:18.092: E/AndroidRuntime(622):  at com.ravi.password.PasswordActivity.onCreate(PasswordActivity.Java:34)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.app.Instrumentation.callActivityOnCreate(Instrumentation.Java:1047)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2627)
10-21 12:06:18.092: E/AndroidRuntime(622):  ... 12 more
10-21 12:06:18.092: E/AndroidRuntime(622): Caused by: Java.lang.reflect.InvocationTargetException
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.widget.LinearLayout.<init>(LinearLayout.Java:115)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Java.lang.reflect.Constructor.constructNative(Native Method)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Java.lang.reflect.Constructor.newInstance(Constructor.Java:446)
 10-21 12:06:18.092: E/AndroidRuntime(622):     at Android.view.LayoutInflater.createView(LayoutInflater.Java:500)
 10-21 12:06:18.092: E/AndroidRuntime(622):     ... 22 more
 10-21 12:06:18.092: E/AndroidRuntime(622): Caused by: Java.lang.OutOfMemoryError: bitmap size exceeds VM budget
 10-21 12:06:18.092: E/AndroidRuntime(622):     at Android.graphics.Bitmap.nativeCreate(Native Method)
 10-21 12:06:18.092: E/AndroidRuntime(622):     at Android.graphics.Bitmap.createBitmap(Bitmap.Java:468)
 10-21 12:06:18.092: E/AndroidRuntime(622):     at Android.graphics.Bitmap.createBitmap(Bitmap.Java:435)
 10-21 12:06:18.092: E/AndroidRuntime(622):     at Android.graphics.Bitmap.createScaledBitmap(Bitmap.Java:340)
 10-21 12:06:18.092: E/AndroidRuntime(622):     at Android.graphics.BitmapFactory.finishDecode(BitmapFactory.Java:488)
 10-21 12:06:18.092: E/AndroidRuntime(622):     at Android.graphics.BitmapFactory.decodeStream(BitmapFactory.Java:462)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.Java:323)
10-21 12:06:18.092: E/AndroidRuntime(622):  at Android.view.ViewGroup.<init>(ViewGroup.Java:285)
10-21 12:06:18.092: E/AndroidRuntime(622):  ... 26 more 

画像のサイズは約5kbです。

22
Ravindra

実行時に、Android必要に応じて(画面のサイズと解像度に基づいて)画像のサイズを変更します。内部的にサイズ変更を行うためにビットマップを使用します。このような問題を修正する簡単な方法の1つは、すべての描画可能ファイルをdrawable-ldpi、mdpi、hdpiフォルダーにコピーすることです。この方法Androidはこれらのフォルダーからファイルを取得するサイズを変更しません。

そのランダムな種類の例外、修正する本当の痛み。

67
Siddharth

背景画像のサイズに従ってください

対応デバイス用

LDPI:
Portrait: 200x320px
Landscape: 320x200px
MDPI:
Portrait: 320x480px
Landscape: 480x320px
HDPI:
Portrait: 480x800px
Landscape: 800x480px
XHDPI:
Portrait: 720px1280px
Landscape: 1280x720px
3
Mahadev Dalavi