在我的应用程序中,我必须将 5 个编辑文本值从 1 个屏幕传递到其他屏幕。我把它放进去putextra
,getextra
但是我得到了null pointer exception
。我不知道我做错了什么。帮助我。
这是我的代码:
过关画面:
long id=0;
db.open();
// id=db.insertSpinTitle(group1.getText().toString(), group2.getText().toString(), group3.getText().toString(), group4.getText().toString(), group5.getText().toString());
Intent spin=new Intent(getApplicationContext(),DBadapter.class);
spin.putExtra("grp1val", group1.getText().toString());
spin.putExtra("grp2val", group2.getText().toString());
spin.putExtra("grp3val", group3.getText().toString());
spin.putExtra("grp4val", group4.getText().toString());
spin.putExtra("grp5val", group5.getText().toString());
// setResult(1,spin);
db.updateSpinTitle();
startActivity(spin);
finish();
获取画面:
public long updateSpinTitle()
{
System.out.println("Inside update");
ContentValues initialValues = new ContentValues();
for(int i=1;i<=6;i++)
{
System.out.println("inside for");
Intent intent=getIntent();
System.out.println("subbu=");
if(i==1) initialValues.put(KEY_SPIN, intent.getStringExtra("grp1val"));
if(i==2) initialValues.put(KEY_SPIN, intent.getStringExtra("grp2val"));
if(i==3) initialValues.put(KEY_SPIN, intent.getStringExtra("grp3val"));
if(i==4) initialValues.put(KEY_SPIN, intent.getStringExtra("grp4val"));
if(i==5) initialValues.put(KEY_SPIN, intent.getStringExtra("grp5val"));
if(i==6) initialValues.put(KEY_SPIN, "Edit");
db.update(DATABASE_TABLESPIN, initialValues, KEY_ROWID + "=" + i, null);
}
return 0 ;
}
这是我的日志:
07-18 09:55:02.324: D/AndroidRuntime(435): Shutting down VM
07-18 09:55:02.324: W/dalvikvm(435): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
07-18 09:55:02.324: E/AndroidRuntime(435): Uncaught handler: thread main exiting due to uncaught exception
07-18 09:55:02.344: E/AndroidRuntime(435): java.lang.NullPointerException
07-18 09:55:02.344: E/AndroidRuntime(435): at com.budget1.DBadapter.updateSpinTitle(DBadapter.java:128)
07-18 09:55:02.344: E/AndroidRuntime(435): at com.budget1.SpinnerEdit$1.onClick(SpinnerEdit.java:58)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.view.View.performClick(View.java:2364)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.view.View.onTouchEvent(View.java:4179)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.widget.TextView.onTouchEvent(TextView.java:6541)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.view.View.dispatchTouchEvent(View.java:3709)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-18 09:55:02.344: E/AndroidRuntime(435): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
07-18 09:55:02.344: E/AndroidRuntime(435): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
07-18 09:55:02.344: E/AndroidRuntime(435): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.os.Looper.loop(Looper.java:123)
07-18 09:55:02.344: E/AndroidRuntime(435): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-18 09:55:02.344: E/AndroidRuntime(435): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 09:55:02.344: E/AndroidRuntime(435): at java.lang.reflect.Method.invoke(Method.java:521)
07-18 09:55:02.344: E/AndroidRuntime(435): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-18 09:55:02.344: E/AndroidRuntime(435): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-18 09:55:02.344: E/AndroidRuntime(435): at dalvik.system.NativeStart.main(Native Method)
07-18 09:55:02.366: I/dalvikvm(435): threadid=7: reacting to signal 3
07-18 09:55:02.366: E/dalvikvm(435): Unable to open stack trace file '/data/anr/traces.txt': Permission denied