Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 意图获取字符串错误_Android_Android Intent - Fatal编程技术网

Android 意图获取字符串错误

Android 意图获取字符串错误,android,android-intent,Android,Android Intent,我在另一个类中创建了两个类。在这两个类中,我使用了Intent类 Intent intent = new Intent(getApplicationContext(), DurationsActivity.class ); intent.putExtra("to",mydate); 在父类中,我使用此代码检索intent值 String to = getIntent().getExtras().getString("to"); String f

我在另一个类中创建了两个类。在这两个类中,我使用了
Intent

Intent intent = new Intent(getApplicationContext(), DurationsActivity.class );   
                     intent.putExtra("to",mydate); 
在父类中,我使用此代码检索intent值

String to = getIntent().getExtras().getString("to");
String from = getIntent().getExtras().getString("from");
我的logcat重试了这个

java.lang.NullPointerException

mydate就像一个键,用来标识意图中的值

宣布我的日期:-

 String mydate,mydate1;

 Intent intent = new Intent(ActivityName.this, DurationsActivity.class );   //Be Specific
                 intent.putExtra("to",mydate); 
                intent.putExtra("from",mydate1); 
而不是DurationActivity.class中 您可以使用onCreate中的常用代码从以前的活动中获取内容:-

 String to = getIntent().getExtras().getString("to");
 String from = getIntent().getExtras().getString("from");
试试看,希望能奏效

字符串to=getIntent().getExtras().getString(“to”)


String from=getIntent().getExtras().getString(“from”)

似乎您设置了“to”额外,但没有设置“from”Post完整堆栈跟踪,因此我们知道此错误发生的位置。此外,了解您试图从何处检索
意图
额外内容(即在
活动中,在什么方法中,等等…)可能对我们有所帮助。我尝试在方法inparent classmydate中检索方法inparent classmydate可能为空。您正在调试吗?父类是否扩展活动?Stacktrace?没有足够的信息来帮助你。没有更多的信息,可能性是无穷的
Intent intent = new Intent(YourCurrentActivity.this, DurationsActivity.class );   
                 intent.putExtra("to",""+mydate);