Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.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 i = new Intent(TouristGuideActivity.this, PointOfInterest.class); i.putExtra("videoId", videoId); startActivity(i); 在头等舱,然后在二等舱 String address=getIntent().getExtras().getString("videoId");`

我想将字符串值从一个类传输到同一个包中的另一个类。第二个类在单击菜单项时使用intent调用。我用了密码

Intent i = new Intent(TouristGuideActivity.this, PointOfInterest.class);
i.putExtra("videoId", videoId);
startActivity(i);
在头等舱,然后在二等舱

String address=getIntent().getExtras().getString("videoId");`

但当我点击菜单项时,我得到一个力关闭。如果我去掉了那个多余的部分,它就可以正常工作了。但是那样的话,我不能发送字符串。请帮忙

确保您得到的是相同的类型,例如,如果您放入一个字符串,则获取一个字符串。 然后尝试:

getIntent().getStringExtra("videoId");

确保您得到的是相同的类型,例如,如果放入字符串,则获取字符串。 然后尝试:

getIntent().getStringExtra("videoId");
在你的第二节课上,试着做两件事来获得这些物品

  Bundle extras = getIntent().getExtras();
        if(extras!=null){
            String videoId=extras.getString("videoId");

        }
在你定义了你的类之后,我希望dis能帮助你在另一页上得到值

在你的第二节课上,试着做两件事来获得这些物品

  Bundle extras = getIntent().getExtras();
        if(extras!=null){
            String videoId=extras.getString("videoId");

        }

刚定义完类,我希望dis能帮助你2获取其他页面上的值

你也应该显示LogCat错误..可能是因为videoId为null或其他原因出错..将日志放入videoId打印并检查。字符串地址=getIntent()。getStringExtra(“videoId”)也不起作用:-(@Frankenstein在第一类中,如果我们打印videod,它会显示值。我也可以在第一类中成功使用此值。LogCat:-12-15 12:46:17.022:W/KeyCharacterMap(2076):无法打开keycharmap文件12-15 12:46:17.032:W/KeyCharacterMap(2076):加载keycharmap文件'/system/usr/keychars/synaptics.kcm.bin'.hw.keyboards.65541.devname='synaptics'12-15 12:46:17.032:W/KeyCharacterMap(2076):使用默认keymap:/system/usr/keychars/qwerty.kcm.bin 12-15 12:46:18.162:W/dalvikvm(2076):threadid=1:线程退出时出现未捕获异常(组=0x40028890)12-15 12:46:18.172:E/AndroidRuntime(2076):致命异常:Main难以阅读..请编辑您的帖子并在帖子中显示它您也应该显示LogCat错误..可能是因为videoId为null或其他原因出错..将日志放入打印videoId并检查。字符串地址=getIntent()。getStringExtra(“videoId”)也不起作用:-(@Frankenstein在第一类中,如果我们打印videod,它会显示值。我也可以在第一类中成功使用此值。LogCat:-12-15 12:46:17.022:W/KeyCharacterMap(2076):无法打开keycharmap文件12-15 12:46:17.032:W/KeyCharacterMap(2076):加载keycharmap文件'/system/usr/keychars/synaptics.kcm.bin'.hw.keyboards.65541.devname='synaptics'12-15 12:46:17.032:W/KeyCharacterMap(2076):使用默认keymap:/system/usr/keychars/qwerty.kcm.bin 12-15 12:46:18.162:W/dalvikvm(2076):threadid=1:线程退出时出现未捕获异常(组=0x40028890)12-15 12:46:18.172:E/AndroidRuntime(2076):致命异常:Main很难阅读。请编辑您的帖子并在帖子中显示。我是用上面的代码从Raghav获得的。非常感谢您的尝试。我是用上面的代码从Raghav获得的。非常感谢您的尝试。