通过几个活动传递字符串

Cat*_*ath -1 android bundle src android-activity

我将我的项目类组织在多个src文件夹中,这些文件一直工作得很好,直到我改变了活动之间的切换,现在将字符串传递到以下活动.我认为这个问题与课程路径有关.

                Bundle bundle = new Bundle();
                bundle.putString("email", userEmail);
                Intent intent = new Intent(MainActivity.this,
                        com.fm.mondev.MeanSelection.class);
                intent.putExtras(bundle);
                startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

[编辑]我意识到问题与Classes的路径并不完全相关,即使我目前有MeanSelection.class而不是com.fm.mondev.MeanSelection.class.实际上,问题似乎与捆绑有关.当我在Login和Main活动之间使用它时,它可以工作,但不能用于Main活动之后的活动.我也尝试了下面显示的替代方法.我随后编辑了相应的活动.

                Intent intent = new Intent(MainActivity.this,
                        MeanSelection.class);
                intent.putExtra("email", userEmail);
                startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

我看过我的logcat但是我找不到任何有用的东西.我知道如果我评论putExtra(s)行,这是有效的.

[答案]在查找logcat的每个错误行并阅读您的答案后,我意识到其中一个变量通过Log.d写入了问题.因此,解决方案是删除这些行,因为它们只是为了验证变量是否通过捆绑从先前的活动中正确选取.我的结论是:从现在开始,我不会记录从一个活动传递到另一个活动的字符串.我不知道这是否真的与Android的问题或只是附带没有可行的解释,这是我们都知道这么好这些事情之一,但只要我删除这些行,我有我的应用程序启动和运行.

Phi*_*hix 6

应用程序在应该打开第二个活动时崩溃.这是以下错误让我相信这与路径有关:"E/AndroidRuntime(7115):java.lang.RuntimeException:无法启动活动ComponentInfo {com.fm/com.fm.mondev.MeanSelection}:java. lang.NullPointerException:println需要一条消息"

println需要一条消息与活动无关.阅读你的logcat!

当我尝试Log空值时,我得到这个错误,即

String foo = emptyBundle.getString("barValue");
Log.d(TAG, foo) // error, Log output functions cannot output null values.
Log.d(TAG, "barValue: " + barValue);  // outputs "barValue: null"
Run Code Online (Sandbox Code Playgroud)

确保您所记录的内容或System.out.printlning具有值.