我创建了一个意图,它获取输入到两个编辑文本中的值,并在单击提交按钮时将它们作为意图发送到另一个类,这里是代码:
Button bSubmit1 = (Button) findViewById(R.id.submit2); //Submit Button
bSubmit1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
String entry_Minutes = entryminutes.getText().toString();
String entry_Hours = entryhours.getText().toString();
Intent i=new Intent("com.lukeorpin.theappliancekeeper.MOVINGSTRINGS");
i.putExtra("Entry_Minutes", entry_Minutes);
i.putExtra("Entry_Hours", entry_Hours);
startActivity(i);
然后开始下一个类中的活动,其中在意图中发送的字符串应该显示在另外两个编辑文本中,但是两个编辑文本框中没有出现任何内容。这是另一个类中代码的另一部分:
public class EntryStatistics extends Activity {
EditText hoursBox, minutesBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.entrystatistics);
hoursBox = (EditText)findViewById(R.id.entry_hours);
minutesBox = (EditText)findViewById(R.id.entry_minutes);
String entry_minutes = getIntent().getStringExtra("Entry_Minutes");
if(entry_minutes!=null){
return;
}
String entry_hours = getIntent().getStringExtra("Entry_Hours");
if(entry_hours!=null){
return;
}
hoursBox.setText(entry_hours);
minutesBox.setText(entry_minutes);
谁能告诉我为什么字符串中的值没有显示在编辑文本中?什么都没有显示。谢谢
以下是完整的错误消息:
04-14 03:00:47.300: E/AndroidRuntime(373): FATAL EXCEPTION: main
04-14 03:00:47.300: E/AndroidRuntime(373): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lukeorpin.theappliancekeeper/com.lukeorpin.theappliancekeeper.EntryStatistics}: java.lang.NullPointerException
04-14 03:00:47.300: E/AndroidRuntime(373): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-14 03:00:47.300: E/AndroidRuntime(373): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-14 03:00:47.300: E/AndroidRuntime(373): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-14 03:00:47.300: E/AndroidRuntime(373): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-14 03:00:47.300: E/AndroidRuntime(373): at android.os.Handler.dispatchMessage(Handler.java:99)
04-14 03:00:47.300: E/AndroidRuntime(373): at android.os.Looper.loop(Looper.java:123)
04-14 03:00:47.300: E/AndroidRuntime(373): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-14 03:00:47.300: E/AndroidRuntime(373): at java.lang.reflect.Method.invokeNative(Native Method)
04-14 03:00:47.300: E/AndroidRuntime(373): at java.lang.reflect.Method.invoke(Method.java:507)
04-14 03:00:47.300: E/AndroidRuntime(373): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-14 03:00:47.300: E/AndroidRuntime(373): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-14 03:00:47.300: E/AndroidRuntime(373): at dalvik.system.NativeStart.main(Native Method)
04-14 03:00:47.300: E/AndroidRuntime(373): Caused by: java.lang.NullPointerException
04-14 03:00:47.300: E/AndroidRuntime(373): at com.lukeorpin.theappliancekeeper.EntryStatistics.onCreate(EntryStatistics.java:34)
04-14 03:00:47.300: E/AndroidRuntime(373): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-14 03:00:47.300: E/AndroidRuntime(373): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-14 03:00:47.300: E/AndroidRuntime(373): ... 11 more
这是第 34 和 35 行:
hoursBox.setText(entry_hours);
minutesBox.setText(entry_minutes);