onActivityResult错误错误、onActivityResult

2023-09-12 05:59:34 作者:不谈情

我有一个启动另一个使用startActivityForResult活动。这一步是确定的。然后第二个活动有一张地图和一个按钮被点击时的GeoPoint坐标传递到用于第一次活动fullfil一个EditText包。该函数onActivityResult是拼命地跑,直到结束,然后在程序崩溃和屏幕上会出现一条消息,找不到源代码。

I have an activity that launches another one using startActivityForResult. This step is ok. Then the second activity has a map and when a button is clicked the geopoint coordinates are passed to a bundle that is used on first activity to fullfil an EditText. The function onActivityResult is runned until the end and then the program crashes and appears a message with "Source not found" on screen.

这是对mapActivity功能:

This is the function on mapActivity:

public void ConfirmLoc(View v){
    double lat = loc.getLatitudeE6()/1E6;
    double lng = loc.getLongitudeE6()/1E6;
    Intent ievloc = new Intent();
    Bundle bevloc = new Bundle();
    bevloc.putDouble("latitude",lat);
    bevloc.putDouble("longitude",lng);
    ievloc.putExtras(bevloc);
    setResult(RESULT_OK,ievloc);
    finish();
}

这是第一次活动的onActivityResult:

And this is the onActivityResult on first Activity:

protected void onActivityResult(int requestCode, int resultCode, Intent data){
    if(requestCode==1){
        if(resultCode==RESULT_OK){
            EditText loc= (EditText) findViewById(R.id.LocalizacaoEvento);
            bevloc = data.getExtras();
            if(bevloc!=null){
                String latitud = String.valueOf(bevloc.getDouble("latitude"));
                String longitud = String.valueOf(bevloc.getDouble("longitude"));
                loc.setText(latitud+" , "+longitud,TextView.BufferType.EDITABLE);

            }
        }
        else if(resultCode==RESULT_CANCELED){

        }
    }
}

谁能帮助?谢谢

Can anyone help? thanks

推荐答案

您需要添加@覆盖行的onActivityResult方法之上。当你这样做,你也将加入以下线的方法的第一行:

You need to add the @Override line on top of your onActivityResult method. When you do this, you will also be adding the following line as the first line of the method:

super.onActivityResult(requestCode, resultCode, data); 

此外,还要确保你的编译器设置为1.6,而不是1.5因为默认情况下在Eclipse。

Also ensure that your compiler settings is 1.6 and not 1.5 as by default in Eclipse.