アクティビティの EditText と Spinner の値を別のアクティビティの TextView に渡すのに問題があります。最初のアクティビティを 2 番目のアクティビティにのみリンクできます。値はテキストビューに表示されません。
さらに、NullPointerException を取得しString name = b.getString("name");
、2 番目のアクティビティからのものを指しています。
以下は、最初のアクティビティ コードです (値を 2 番目のアクティビティに渡します) - PersonalInformation:
btnView = (Button) findViewById(R.id.btnView);
btnView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
nameSpinner = (Spinner) findViewById(R.id.nameSpinner);
EditText txtDate = (EditText) findViewById(R.id.txtDate);
EditText txtType = (EditText) findViewById(R.id.txtType);
EditText txtLikes = (EditText) findViewById(R.id.txtLikes);
EditText txtDislikes = (EditText) findViewById(R.id.txtDislikes);
Intent i = new Intent(PersonalInformation.this, SavedInfo.class);
Bundle b = new Bundle();
b.putString("name", nameSpinner.getSelectedItem().toString());
b.putString("date", txtDate.getText().toString());
b.putString("category", txtType.getText().toString());
b.putString("likes", txtLikes.getText().toString());
b.putString("dislikes", txtDislikes.getText().toString());
i.putExtras(b);
startActivity(i);
Intent viewIntent = new Intent(context, SavedInfo.class);
startActivity(viewIntent);
これらは、最初のアクティビティから値を取得するためのコードです - SavedInfo.java
@Override
public void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.saved_info);
Bundle b = this.getIntent().getExtras();
String name = b.getString("name");
String date = b.getString("date");
String category = b.getString("category");
String likes = b.getString("likes");
String dislikes = b.getString("dislikes");
((TextView)findViewById(R.id.textName)).setText(name);
((TextView)findViewById(R.id.textDate)).setText(date);
((TextView)findViewById(R.id.textType)).setText(category);
((TextView)findViewById(R.id.textLikes)).setText(likes);
((TextView)findViewById(R.id.textDislikes)).setText(dislikes);
以下は私のLogCatです
09-03 14:31:49.021: I/dalvikvm(573): threadid=3: reacting to signal 3
09-03 14:31:49.121: I/dalvikvm(573): Wrote stack traces to '/data/anr/traces.txt'
09-03 14:31:49.391: D/gralloc_goldfish(573): Emulator without GPU emulation detected.
09-03 14:31:51.960: D/dalvikvm(573): GC_FOR_ALLOC freed 101K, 3% free 9255K/9479K, paused 47ms
09-03 14:31:55.960: D/AndroidRuntime(573): Shutting down VM
09-03 14:31:55.960: W/dalvikvm(573): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
09-03 14:31:55.980: E/AndroidRuntime(573): FATAL EXCEPTION: main
09-03 14:31:55.980: E/AndroidRuntime(573): java.lang.RuntimeException: Unable to start activity ComponentInfo{main.page/main.page.SavedInfo}: java.lang.NullPointerException
09-03 14:31:55.980: E/AndroidRuntime(573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
09-03 14:31:55.980: E/AndroidRuntime(573): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
09-03 14:31:55.980: E/AndroidRuntime(573): at android.app.ActivityThread.access$600(ActivityThread.java:123)
09-03 14:31:55.980: E/AndroidRuntime(573): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
09-03 14:31:55.980: E/AndroidRuntime(573): at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 14:31:55.980: E/AndroidRuntime(573): at android.os.Looper.loop(Looper.java:137)
09-03 14:31:55.980: E/AndroidRuntime(573): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-03 14:31:55.980: E/AndroidRuntime(573): at java.lang.reflect.Method.invokeNative(Native Method)
09-03 14:31:55.980: E/AndroidRuntime(573): at java.lang.reflect.Method.invoke(Method.java:511)
09-03 14:31:55.980: E/AndroidRuntime(573): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-03 14:31:55.980: E/AndroidRuntime(573): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-03 14:31:55.980: E/AndroidRuntime(573): at dalvik.system.NativeStart.main(Native Method)
09-03 14:31:55.980: E/AndroidRuntime(573): Caused by: java.lang.NullPointerException
09-03 14:31:55.980: E/AndroidRuntime(573): at main.page.SavedInfo.onCreate(SavedInfo.java:19)
09-03 14:31:55.980: E/AndroidRuntime(573): at android.app.Activity.performCreate(Activity.java:4465)
09-03 14:31:55.980: E/AndroidRuntime(573): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-03 14:31:55.980: E/AndroidRuntime(573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
09-03 14:31:55.980: E/AndroidRuntime(573): ... 11 more
EditText と Spinner の値を TextView として 2 番目のアクティビティに渡す必要があります。