androidで自作ダイアログ表示時に端末回転でシステムが強制停止してしまいます。
解決策わかる方教えて下さい。
inputname_dailog.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <AutoCompleteTextView android:id="@+id/dialog_edittext" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:scrollHorizontally="true" android:hint="なまえを入力してください" android:autoText="false" android:capitalize="none" android:gravity="fill_horizontal" android:text="" android:textAppearance="?android:attr/textAppearanceLarge" /> </LinearLayout>
SY_Activity.java
public void tyoku() { LayoutInflater factory = LayoutInflater.from(SY_Activity.this); final View inputView = factory.inflate(R.layout.inputname_dailog, null); // ダイアログの作成(AlertDialog.Builder) new AlertDialog.Builder(SY_Activity.this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle("コードを入力してください") .setView(inputView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { EditText editNaiyo = (EditText) inputView.findViewById(R.id.dialog_edittext); String N_CODE = editNaiyo.getText().toString();//String型に変更 syb(N_CODE, 0, null); } }) .setNegativeButton("キャンセル", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // キャンセル処理 } }).create().show(); }
エラー内容
E/AndroidRuntime: FATAL EXCEPTION: main E/AndroidRuntime: Process: com.name.test.test, PID: 19081 E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.name.test.test/com.name.test.test.SY_Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) E/AndroidRuntime: at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3912) E/AndroidRuntime: at android.app.ActivityThread.access$900(ActivityThread.java:144) E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284) E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135) E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5221) E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference E/AndroidRuntime: at com.name.test.test.SY_Activity.onRestoreInstanceState(SY_Activity.java:947) E/AndroidRuntime: at android.app.Activity.performRestoreInstanceState(Activity.java:977) E/AndroidRuntime: at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1161) E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2271) E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) E/AndroidRuntime: at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3912) E/AndroidRuntime: at android.app.ActivityThread.access$900(ActivityThread.java:144) E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284) E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135) E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5221) E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。