我在通过intent 获得传递兑现过的时候报错,空指针,我是getMap方法进行传值,代码如下
1 2 3 4 5 6 7 8 9 | 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? 确实有值,我在下面的代码中获取改值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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");
?
原文地址:http://www.itmmd.com/201411/134.html
该文章由?萌萌的IT人?整理发布,转载须标明出处。