Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.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
Java 无法从捆绑包中获取字符串_Java_Android_Bundle - Fatal编程技术网

Java 无法从捆绑包中获取字符串

Java 无法从捆绑包中获取字符串,java,android,bundle,Java,Android,Bundle,登录成功后,我创建了一个新活动。但当我启动应用程序时,应用程序会在5秒内崩溃,并显示消息 尝试在空对象引用上调用虚拟方法“java.lang.String android.os.Bundle.getString(java.lang.String)” 错误来自于此 name.setText(" "+bundle.getString("name")); 替换此代码段: Bundle bundle = getIntent().getExtras(); name.setText("

登录成功后,我创建了一个新活动。但当我启动应用程序时,应用程序会在5秒内崩溃,并显示消息

尝试在空对象引用上调用虚拟方法“java.lang.String android.os.Bundle.getString(java.lang.String)”

错误来自于此

name.setText(" "+bundle.getString("name"));


替换此代码段:

    Bundle bundle = getIntent().getExtras();
    name.setText(" "+bundle.getString("name"));
        "class".with(getActivity())
            .using(Album.class)
            .bucketId(Application.getBucketId())
            .entityId(getArguments().getString(YourActivity.GALLERY_ID))
            .retrieve(new XXXX()); Change code : Use Bundle method To replace code below type  Bundle bundle = getArguments();
            "example".with(getActivity())
            .using(Album.class)
            .bucketId(Application.getBucketId())
            .entityId(bundle.getString(YourActivity.GALLERY_ID))
            .retrieve(new XXXX());


您的问题将得到解决。

替换此代码段:

    Bundle bundle = getIntent().getExtras();
    name.setText(" "+bundle.getString("name"));
        "class".with(getActivity())
            .using(Album.class)
            .bucketId(Application.getBucketId())
            .entityId(getArguments().getString(YourActivity.GALLERY_ID))
            .retrieve(new XXXX()); Change code : Use Bundle method To replace code below type  Bundle bundle = getArguments();
            "example".with(getActivity())
            .using(Album.class)
            .bucketId(Application.getBucketId())
            .entityId(bundle.getString(YourActivity.GALLERY_ID))
            .retrieve(new XXXX());
尝试调用虚拟方法“java.lang.String” null对象上的android.os.Bundle.getString(java.lang.String)“” 参考文献

嗯,您需要避免对空对象调用方法。在您的情况下:

name.setText(" "+bundle.getString("name"));
在这种情况下,bundle是空对象。所以它抛出了一个错误。 避免此崩溃的解决方案是添加if/else语句

if (bundle != null) 
   // set text for name like what you have done
else
   // set a default text for name

但是,我建议最好检查您的代码并理解为什么您的包会变为null

我通过键入来解析代码 在活动中,您通过捆绑获得价值

    Bundle bundle = getIntent().getExtras();
    hName = bundle.getString("sharedName");

    b1 =new Bundle(); //this b1 should be declared Globally where you are getting value 
    b1.putString("sharedName",hName);

问题中的代码不包含
NoSQL
class
    Bundle bundle = getIntent().getExtras();
    hName = bundle.getString("sharedName");

    b1 =new Bundle(); //this b1 should be declared Globally where you are getting value 
    b1.putString("sharedName",hName);