ダイアログボックスのアクティビティを表示するコードは次のとおりです。このインテントを開こうとすると、アプリが強制的に閉じられます。コードの間違いを教えてください。これがlogcatです。
03-28 12:11:36.851: E/AndroidRuntime(681): 致命的な例外: メイン 03-28 12:11:36.851: E/AndroidRuntime(681): java.lang.RuntimeException: アクティビティ ComponentInfo{com を開始できません。 neelrazin.noteit/com.neelrazin.noteit.Password}: java.lang.NullPointerException 03-28 12:11:36.851: E/AndroidRuntime(681): android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 03 -28 12:11:36.851: E/AndroidRuntime(681): android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 03-28 12:11:36.851: E/AndroidRuntime(681): android.app で.ActivityThread.access$1500(ActivityThread.java:117) 03-28 12:11:36.851: E/AndroidRuntime(681): android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 03-28 12: 11:36.851: E/AndroidRuntime(681): android.os.Handler.dispatchMessage(Handler.java:99) 03-28 12:11:36.851: E/AndroidRuntime(681): android.os.Looper.loop(Looper.java:123) 03-28 12:11:36.851: E/AndroidRuntime(681): at android.app.ActivityThread.main(ActivityThread.java:3683) 03-28 12:11:36.851: E/AndroidRuntime(681): java.lang.reflect.Method.invokeNative(ネイティブ メソッド) 03-28 12:11 で:36.851: E/AndroidRuntime(681): java.lang.reflect.Method.invoke(Method.java:507) 03-28 12:11:36.851: E/AndroidRuntime(681): com.android.internal. os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 03-28 12:11:36.851: E/AndroidRuntime(681): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 03 -28 12:11:36.851: E/AndroidRuntime(681): dalvik.system.NativeStart.main(Native Method) 03-28 12:11:36.851: E/AndroidRuntime(681): 原因: java.lang. NullPointerException 03-28 12:11:36。851: E/AndroidRuntime(681): com.neelrazin.noteit.Password.onCreate(Password.java:57) 03-28 12:11:36.851: E/AndroidRuntime(681): android.app.Instrumentation.callActivityOnCreate で(Instrumentation.java:1047) 03-28 12:11:36.851: E/AndroidRuntime(681): android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) で
public class Password extends Activity {
final Context context = this;
public Long mRowId;
private NotesDbAdapter mDbHelper;
String password;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//setContentView(R.layout.password);
mRowId = (savedInstanceState == null) ? null :
(Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
: null;
}
mDbHelper = new NotesDbAdapter(this);
mDbHelper.open();
Cursor notesC = mDbHelper. fetchNote( mRowId);
startManagingCursor(notesC);
final String pass = notesC.getString( notesC.getColumnIndex("passw") );
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.password);
dialog.setTitle("Enter Password");
final EditText enterpass = (EditText) dialog.findViewById(R.id.edtext);
Button ok=(Button)findViewById(R.id.dialogButtonOK);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
password= enterpass.getText().toString();
if(password.equals(pass.toString())){
Intent i= new Intent(getBaseContext(),NoteEditor.class);
i.putExtra(NotesDbAdapter.KEY_ROWID,mRowId);
startActivity(i);
}
}
});
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonCANCEL);
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
dialog.show();
}