我在通过intent 获得传递兑现过的时候报错,空指针,我是getMap方法进行传值,代码如下
1 2 3 4 5 6 7 8 9class="java keyword" style="margin: 0px !important; padding: 0px !important; outline: 0px !important; border-radius: 0px !important; border: 0px currentColor !important; left: auto !important; top: auto !important; width: auto !important; height: auto !important; text-align: left !important; right: auto !important; bottom: auto !important; color: #006699 !important; line-height: 1.1em !important; overflow: visible !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; font-style: normal !important; font-weight: bold !important; vertical-align: baseline !important; float: none !important; position: static !important; min-height: inherit !important; box-sizing: content-box !important;">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 20public
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人 整理发布,转载须标明出处。