レイアウトに追加したばかりのImageButtonがありますが、レイアウトでsetContentViewを呼び出すと、プログラムがクラッシュします。logcatを見ると、このImageButtonを作成しようとするとNullPointerExceptionが発生するようです。ic_menu_send.pngは、適切な描画可能なフォルダーにあります。ImageButtonのxmlは次のとおりです。
<ImageButton
android:id="@+id/imageButton1"
android:src="@drawable/ic_menu_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/enterPassword2"
android:layout_alignRight="@id/enterPassword1"
android:layout_alignTop="@id/enterPassword2"
android:background="@style/AppTheme"
android:contentDescription="@string/submit_button" />
そして、これがこのアクティビティのonCreateです。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_time); // causes nullpointerexception
EditText enterPassword1 = (EditText)findViewById(R.id.enterPassword1);
enterPassword1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return onEditAction(v);
}
});
EditText enterPassword2 = (EditText)findViewById(R.id.enterPassword2);
enterPassword2.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return onEditAction(v);
}
});
/*ImageButton submit1 = (ImageButton)findViewById(R.id.imageButton1);
submit1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText enterPassword1 = (EditText)findViewById(R.id.enterPassword1);
onEditAction(enterPassword1);
}
});*/
コードのImageButton部分はテストのためにコメントアウトされただけですが、プログラムはずっと早くクラッシュします。誰かがこれを引き起こしている可能性があるものの考えを持っていますか?ご協力いただきありがとうございます。
編集:logcatログは次のとおりです。
01-27 15:52:11.264: E/AndroidRuntime(31195): FATAL EXCEPTION: main
01-27 15:52:11.264: E/AndroidRuntime(31195): java.lang.RuntimeException: Unable to start activity ComponentInfo{us.securecow.nearfieldunlock/us.securecow.nearfieldunlock.FirstTimeActivity}: android.view.InflateException: Binary XML file line #50: Error inflating class android.widget.ImageButton
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.os.Handler.dispatchMessage(Handler.java:99)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.os.Looper.loop(Looper.java:137)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-27 15:52:11.264: E/AndroidRuntime(31195): at java.lang.reflect.Method.invokeNative(Native Method)
01-27 15:52:11.264: E/AndroidRuntime(31195): at java.lang.reflect.Method.invoke(Method.java:511)
01-27 15:52:11.264: E/AndroidRuntime(31195): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-27 15:52:11.264: E/AndroidRuntime(31195): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-27 15:52:11.264: E/AndroidRuntime(31195): at dalvik.system.NativeStart.main(Native Method)
01-27 15:52:11.264: E/AndroidRuntime(31195): Caused by: android.view.InflateException: Binary XML file line #50: Error inflating class android.widget.ImageButton
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
01-27 15:52:11.264: E/AndroidRuntime(31195): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-27 15:52:11.264: E/AndroidRuntime(31195): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.app.Activity.setContentView(Activity.java:1881)
01-27 15:52:11.264: E/AndroidRuntime(31195): at us.securecow.nearfieldunlock.FirstTimeActivity.onCreate(FirstTimeActivity.java:19)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.app.Activity.performCreate(Activity.java:5104)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-27 15:52:11.264: E/AndroidRuntime(31195): ... 11 more
01-27 15:52:11.264: E/AndroidRuntime(31195): Caused by: java.lang.reflect.InvocationTargetException
01-27 15:52:11.264: E/AndroidRuntime(31195): at java.lang.reflect.Constructor.constructNative(Native Method)
01-27 15:52:11.264: E/AndroidRuntime(31195): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
01-27 15:52:11.264: E/AndroidRuntime(31195): ... 24 more
01-27 15:52:11.264: E/AndroidRuntime(31195): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f050001 a=-1 r=0x7f050001}
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.content.res.Resources.loadDrawable(Resources.java:1927)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.view.View.<init>(View.java:3328)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.widget.ImageView.<init>(ImageView.java:114)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.widget.ImageButton.<init>(ImageButton.java:87)
01-27 15:52:11.264: E/AndroidRuntime(31195): at android.widget.ImageButton.<init>(ImageButton.java:83)
01-27 15:52:11.264: E/AndroidRuntime(31195): ... 27 more