Android 从自定义对话框设置值

Android 从自定义对话框设置值,android,map,Android,Map,我写了一个程序,你可以给用户的位置,然后显示他的位置。对于获取位置,我使用一个自定义对话框,但我不知道如何使用用户输入的位置。例如,我使用一个按钮来接受值,但每次使用这个方法时,我都会得到一个错误。 这是我使用按钮并获取错误的来源: public class main extends MapActivity { /** Called when the activity is first created. */ EditText lat; EditText lang; Integer lati

我写了一个程序,你可以给用户的位置,然后显示他的位置。对于获取位置,我使用一个自定义对话框,但我不知道如何使用用户输入的位置。例如,我使用一个按钮来接受值,但每次使用这个方法时,我都会得到一个错误。 这是我使用按钮并获取错误的来源:

public class main extends MapActivity {
/** Called when the activity is first created. */

EditText lat;
EditText lang;

Integer latitude;
Integer longtitude;

Button b = (Button) findViewById(R.id.button1);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    MapView view = (MapView) findViewById(R.id.themap);
    view.setBuiltInZoomControls(true);

    final MapController control = view.getController();

    LocationManager manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    LocationListener listener = new LocationListener() {

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLocationChanged(Location location) {
            latitude = Integer.valueOf(lat.getText().toString());
            longtitude = Integer.valueOf(lang.getText().toString());

            control.setCenter(new GeoPoint(latitude, longtitude));

        }
    };
    manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Dialog d = new Dialog(main.this);
    d.setContentView(R.layout.choose);
    d.setTitle("Location");
    d.show();
    lat = (EditText) findViewById(R.id.editText1);
    lang = (EditText) findViewById(R.id.editText2);
    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

        }
    });
    return super.onOptionsItemSelected(item);
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
}

这是我的权限:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>

错误是什么?Post logcat outputs.b未正确初始化,您必须像EditText字段按钮b=(按钮)findViewById(R.id.button1)一样初始化按钮;设置内容视图后,如果我放置按钮b=(按钮)findViewById(R.id.button1),则将其放入onCreate;在oncreate中,我不能在OnOptions ItemSelected上引用它。我定义了类似EditText的按钮,但在按下菜单选项后,我得到了错误。
05-23 13:15:10.953: W/KeyCharacterMap(13490): No keyboard for id 131074
05-23 13:15:10.953: W/KeyCharacterMap(13490): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
05-23 13:15:21.434: W/MapActivity(13490): Recycling dispatcher android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher@40719228
05-23 13:15:21.444: V/MapActivity(13490): Recycling map object.
05-23 13:15:21.524: I/MapActivity(13490): Handling network change notification:CONNECTED
05-23 13:15:21.524: E/MapActivity(13490): Couldn't get connection factory client