public class workmemo extends Activity{
EditText editTextWorkmemo1;
EditText editTextWorkmemo2;
String q1;
String q2;
Button ButtonWorkMemo1 ;
WorkmemoDatabaseHelper dbh2 = new WorkmemoDatabaseHelper(workmemo.this);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.workmemo);
q1=editTextWorkmemo1.getText().toString();
String currentDateTimeString = DateFormat.getDateTimeInstance().format(
new Date());
editTextWorkmemo2=(EditText)findViewById(R.id.editTextWorkmemo2);
editTextWorkmemo2.setText(currentDateTimeString);
q2=currentDateTimeString;
ButtonWorkMemo1 = (Button) findViewById(R.id.ButtonWorkMemo1);
ButtonWorkMemo1.setOnClickListener(new clicker());
}
class clicker implements Button.OnClickListener{
public void onClick(View v) {
if(v== ButtonWorkMemo1) {
//addEvent(q1,q2);
Intent viewDataIntent = new Intent(workmemo.this, Database.class);
startActivity(viewDataIntent);
}
}
}
public void addEvent ( String q1,String q) {
SQLiteDatabase db = dbh2.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(WorkmemoDatabaseHelper.memo, q1);
values.put(WorkmemoDatabaseHelper.date, q2);
db.insert(WorkmemoDatabaseHelper.TABLE_NAME, null, values);
}
}
您好,我正在尝试启动一个活动,当 android 尝试启动上述活动(workmemo)时,它失败了。这是我的错误日志。有任何想法吗?
04-24 12:46:06.955: W/dalvikvm(548): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-24 12:46:06.984: E/AndroidRuntime(548): FATAL EXCEPTION: main
04-24 12:46:06.984: E/AndroidRuntime(548): java.lang.RuntimeException: Unable to start activity ComponentInfo{nidhin.organizer/nidhin.organizer.workmemo}: java.lang.NullPointerException
04-24 12:46:06.984: E/AndroidRuntime(548): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-24 12:46:06.984: E/AndroidRuntime(548): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-24 12:46:06.984: E/AndroidRuntime(548): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-24 12:46:06.984: E/AndroidRuntime(548): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-24 12:46:06.984: E/AndroidRuntime(548): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 12:46:06.984: E/AndroidRuntime(548): at android.os.Looper.loop(Looper.java:137)
04-24 12:46:06.984: E/AndroidRuntime(548): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-24 12:46:06.984: E/AndroidRuntime(548): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 12:46:06.984: E/AndroidRuntime(548): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 12:46:06.984: E/AndroidRuntime(548): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-24 12:46:06.984: E/AndroidRuntime(548): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-24 12:46:06.984: E/AndroidRuntime(548): at dalvik.system.NativeStart.main(Native Method)
04-24 12:46:06.984: E/AndroidRuntime(548): Caused by: java.lang.NullPointerException
04-24 12:46:06.984: E/AndroidRuntime(548): at nidhin.organizer.workmemo.onCreate(workmemo.java:32)
04-24 12:46:06.984: E/AndroidRuntime(548): at android.app.Activity.performCreate(Activity.java:4465)
04-24 12:46:06.984: E/AndroidRuntime(548): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-24 12:46:06.984: E/AndroidRuntime(548): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-24 12:46:06.984: E/AndroidRuntime(548): ... 11 more