Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.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_Android Studio_Android Intent_Bundle - Fatal编程技术网

Java 未显示捆绑包中使用的其他活动的字符串

Java 未显示捆绑包中使用的其他活动的字符串,java,android,android-studio,android-intent,bundle,Java,Android,Android Studio,Android Intent,Bundle,我想在账单页面上找到比萨饼的名字,但它没有显示(空白) Menu.java: bundle = new Bundle(); bundle.putString("name",pizzaName); y = new Intent(this,Bill.class); y.putExtras(bundle); startActivity(y); Bill.java: text1=(TextView)findViewById(R.id.textView6); y= new

我想在账单页面上找到比萨饼的名字,但它没有显示(空白)

Menu.java:

bundle = new Bundle();
        bundle.putString("name",pizzaName);
y = new Intent(this,Bill.class);
        y.putExtras(bundle);
startActivity(y);
Bill.java:

text1=(TextView)findViewById(R.id.textView6);
y= new Intent();
        bundle=getIntent().getExtras();
        Name=bundle.getString("name");
text1.setText();

输出:

您不需要执行
y=newintent()在Bill.java中

将Bill.java中的代码更改如下。另外,为了更好地命名约定,请将Bill.java更改为BillActivity.java

    TextView text1 = (TextView) findViewById(R.id.textView6);
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        String name = bundle.getString("name");
        text1.setText(name);
    }

您可以像这样简单地传递和检索值

// Creating and initializing an Intent object
Intent intent = new Intent(this, NextActivity.class);

// Attach the key value pair using putExtra to this intent
String pizza = "Margherita";
intent.putExtra("PIZZA_NAME", pizza);

// Start the activity
startActivity(intent);

移除y=新意图();在您的账单中。类

无需获取y=新意图();当您从bundle获取数据时

text1=(TextView)findViewById(R.id.textView6)

bundle=getIntent().getExtras()

Name=bundle.getString(“Name”)


text1.setText()

如果要使用bundle对象,请参考以下内容
// Get the current intent
Intent intent = getIntent();

// Get the attached extras from the intent
// We should use the same key as we used to attach the data.
String pizza = intent.getStringExtra("PIZZA_NAME");