我在通过intent 获得传递兑现过的时候报错,空指针,我是getMap方法进行传值,代码如下 public void getMap(View view){ Intent i = new Intent( this , BreweryYourTopBeers. class ); Log.d( "map" , e.beerBreweryId); i.
我在通过intent 获得传递兑现过的时候报错,空指针,我是getMap方法进行传值,代码如下
public void getMap(View view){
Intent i = new Intent( this , BreweryYourTopBeers. class );
Log.d( "map" , e.beerBreweryId);
i.putExtra( "breweryID" , e.beerBreweryId);
i.setClass( this , BreweryMap. class );
startActivity(i);
}
从我的日志中能够看到 在传值之前e.beerBreweryId 确实有值,我在下面的代码中获取改值
public class BreweryMap extends ActionbarMenu {
BeerData e;
String beerID;
GoogleMap map;
//从bundle 中获得beer 详细信息
protected void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout.activity_brewerymap);
//get brewery data
//get beer data
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String breweryID = extras.getString( "brewreyID" );
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
String url = "http://api.brewerydb.com/v2/brewery/" + breweryID + "?key=myKey&format=json&withLocations=y" ;
Log.d( "map" , url);
new myAsyncTask( this ,map).execute(url);
}
}
我每次获得值都是NULL ,不知道是什么原因.
处理方法
有一行写错误了.
把
String breweryID = extras.getString("brewreyID");
换成
String breweryID = extras.getString("breweryID");