Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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_Variables_Android Intent_Android Activity - Fatal编程技术网

Android 向活动发送一个额外的消息

Android 向活动发送一个额外的消息,android,variables,android-intent,android-activity,Android,Variables,Android Intent,Android Activity,我有以下代码: Rechercher.java: public void doOnResult(String json){ if ( json.equals("Aucune propostion pour le mois")||json.equals("Aucune propostion pour cette date")) { Toast.makeText(Rechercher.this, "Aucune proposition actuellement.", Toas

我有以下代码:

Rechercher.java:

public void doOnResult(String json){
    if ( json.equals("Aucune propostion pour le mois")||json.equals("Aucune propostion pour cette date")) {
        Toast.makeText(Rechercher.this, "Aucune proposition actuellement.", Toast.LENGTH_LONG).show();
        finish();
    } else {
        Intent iAfficher = new Intent(this, Afficher.class);
        extras.putString("json", json);
        extras.putInt("nbplaces", mCounter);
        iAfficher.putExtras(extras);
        this.startActivityForResult(iAfficher, 10);
    }                   
}
Integer places = extras.getInt("nbplaces");

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.afficher);
    ListView lvTrajets = (ListView)findViewById(R.id.lvTrajets);
    Bundle bundle = getIntent().getExtras();

    .......

    proposition.put("Date",propId);
    proposition.put("Trajet", propLieu+" de "+propVille+" --> "+propGare+" Places : "+places);
Afficher.java:

public void doOnResult(String json){
    if ( json.equals("Aucune propostion pour le mois")||json.equals("Aucune propostion pour cette date")) {
        Toast.makeText(Rechercher.this, "Aucune proposition actuellement.", Toast.LENGTH_LONG).show();
        finish();
    } else {
        Intent iAfficher = new Intent(this, Afficher.class);
        extras.putString("json", json);
        extras.putInt("nbplaces", mCounter);
        iAfficher.putExtras(extras);
        this.startActivityForResult(iAfficher, 10);
    }                   
}
Integer places = extras.getInt("nbplaces");

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.afficher);
    ListView lvTrajets = (ListView)findViewById(R.id.lvTrajets);
    Bundle bundle = getIntent().getExtras();

    .......

    proposition.put("Date",propId);
    proposition.put("Trajet", propLieu+" de "+propVille+" --> "+propGare+" Places : "+places);
places变量始终等于0


我不知道为什么我不能得到正确的值。

移动这个
整数位=extras.getInt(“nbplaces”)内部
onCreate
。另外还有
extras
的初始化

public Intent getIntent ()

Added in API level 1
Return the intent that started this activity.
使用
int-places
代替
Integer-places
int
是一种基本数据类型,因此对于基本数据类型,请使用
int
而不是
Integer

int places;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.afficher);
Bundle extras = getIntent().getExtras(); 
places = extras.getInt("nbplaces");
您需要等待活动创建完成,然后使用
getIntent()


移动此
Integer places=extras.getInt(“nbplaces”)内部
onCreate
。另外还有
extras
的初始化

public Intent getIntent ()

Added in API level 1
Return the intent that started this activity.
使用
int-places
代替
Integer-places
int
是一种基本数据类型,因此对于基本数据类型,请使用
int
而不是
Integer

int places;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.afficher);
Bundle extras = getIntent().getExtras(); 
places = extras.getInt("nbplaces");
您需要等待活动创建完成,然后使用
getIntent()

请试试这个:

Integer places ;
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.afficher);

Bundle bundle = getIntent().getExtras(); 
places = bundle.getInt("nbplaces")
...........
请试试这个:

Integer places ;
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.afficher);

Bundle bundle = getIntent().getExtras(); 
places = bundle.getInt("nbplaces")
...........

在onCreate()方法中的bundle声明之后放置以下行

并删除以下行

Integer places = extras.getInt("nbplaces");

在onCreate()方法中的bundle声明之后放置以下行

并删除以下行

Integer places = extras.getInt("nbplaces");

您需要从
onCreate
方法中
Afficher.java
文件中的
Bundle
获取值,如下所示:

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.afficher);
    ListView lvTrajets = (ListView)findViewById(R.id.lvTrajets);
    Bundle bundle = getIntent().getExtras();

    Integer places = bundle.getInt("nbplaces"); //get value here
    String jsonval=bundle.getString("json"); 

您需要从
onCreate
方法中
Afficher.java
文件中的
Bundle
获取值,如下所示:

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.afficher);
    ListView lvTrajets = (ListView)findViewById(R.id.lvTrajets);
    Bundle bundle = getIntent().getExtras();

    Integer places = bundle.getInt("nbplaces"); //get value here
    String jsonval=bundle.getString("json"); 


put
Integer places=getIntent().getExtras().getInt(“nbplaces”)
setContentView
之后应该是
getString
getInt
@user3507621您能看到我的answer@shayanpourvatan是的,我在这项活动中明白了!但这不是我的最终愿望,我必须再次将它传递给另一个活动,我测试它并告诉它you@shayanpourvatan我得到了另一个活动的值,非常感谢:)但是你没有在回答中告诉我这一点,所以我不能接受你的回答,我会接受其他人的回答put
Integer places=getIntent().getExtras().getInt(“nbplaces”)
setContentView
之后应该是
getString
getInt
@user3507621您能看到我的answer@shayanpourvatan是的,我在这项活动中明白了!但这不是我的最终愿望,我必须再次将它传递给另一个活动,我测试它并告诉它you@shayanpourvatan我得到了其他活动的值,非常感谢:)但是你没有在回答中告诉我这一点,所以我不能接受你的回答,我会接受其他人的回答你的代码中有什么额外的内容?您需要初始化,为什么有两个
bundle
从intent保存相同的数据<代码>b
捆绑
都是相同的。您的代码中的
附加部分是什么?您需要初始化,为什么有两个
bundle
从intent保存相同的数据
b
bundle
都是相同的。
extras
没有定义。@SachinG现在您可以看到声明的extras。仍然不知道为什么它被否决了。如果没有声明,它将根本无法编译,请忘记获取0“是”。它首先不会编译。这将使编译错误正确吗?因此,在定义之前使用
extras
是不正确的。您假设它是在代码中未提及的某个地方声明的。如果OP没有定义它,那么这将给出一个错误。@SachinG但是如果你看这个问题,他说他得到的值是0。所以它编译得很好。因此,它必须已经声明,并且假设是正确的。
extras
没有定义。@SachinG现在您可以看到声明的extras。仍然不知道为什么它被否决了。如果没有声明,它将根本无法编译,请忘记获取0“是”。它首先不会编译。这将使编译错误正确吗?因此,在定义之前使用
extras
是不正确的。您假设它是在代码中未提及的某个地方声明的。如果OP没有定义它,那么这将给出一个错误。@SachinG但是如果你看这个问题,他说他得到的值是0。所以它编译得很好。因此,它必须已经声明并且假设是正确的您的答案很好,我会尽快接受它,谢谢您的帮助:)@user3507621总是很乐意帮助:)我认为更多的旧asnwer是我的,但是,问题是您的问题正在解决,很高兴看到它,下一个关于stackoverflow的问题见:)@ErsinGülbahar一切顺利。:)你的回答很好,我会尽快接受,谢谢你的帮助:)@user3507621总是很乐意帮助:)我想更多的旧asnwer是我的,但问题是你的问题正在解决,很高兴看到它,下一个关于stackoverflow的问题见:)@ErsinGülbahar祝你一切顺利。:)