我創建一個MapView的活動,由於某種原因,這個代碼不工作:的Android MapController撞毀我的應用程序
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.setContentView(R.layout.map_view);
MapView mapView = (MapView)this.findViewById(R.layout.map_view);
MapController mapController = mapView.getController();
此行特別是會導致應用崩潰:
MapController mapController = mapView.getController();
當我將該線路取出時,該應用的工作方式應該如此,但是當我將其放入時,它在啓動活動時崩潰,並顯示錯誤消息:
07-05 21:27:24.857: E/AndroidRuntime(23801): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uie.top25.seattle/com.uie.top25.seattle.MapDetailActivity}: java.lang.NullPointerException
這是我的呼籲的MapView:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.detail);
Bundle bundle = this.getIntent().getExtras();
ListData listdata = bundle.getParcelable("uie.top25.seattle.listdata");
// int itemId = this.getIntent().getIntExtra(DiningActivity.ITEM_ID, -1);
String itemTitle = listdata.getTitle();
int itemNum = listdata.getItem();
String sHead = listdata.getSubhead();
String dText = listdata.getDetailText();
final float latitude = listdata.getLatitude();
final float longitude = listdata.getLongitude();
Log.i(TAG, "Title that is set : " + itemTitle);
Log.i(TAG, "Item Number that is set : " + itemNum);
Log.i(TAG, "Latitude that is set : " + latitude);
Log.i(TAG, "Longitude that is set : " + longitude);
if (itemNum >= 0)
{
TextView tView = (TextView) this.findViewById(R.id.textTitle);
tView.setText(itemTitle);
TextView nView = (TextView) this.findViewById(R.id.itemNumber);
nView.setText("" + itemNum);
TextView subHead = (TextView) this.findViewById(R.id.textSubheader);
subHead.setText(sHead);
TextView details = (TextView) this.findViewById(R.id.itemDescription);
details.setText(dText);
ImageButton mapButton = (ImageButton) this.findViewById(R.id.mapButton);
mapButton.setOnClickListener(new View.OnClickListener() {
//this is where I call my mapView from
@Override
public void onClick(View v)
{
Intent mapIntent = new Intent(DetailActivity.this, MapDetailActivity.class);
//mapIntent.putExtra("uie.top25.seattle.listlat", latitude);
//mapIntent.putExtra("uie.top25.seattle.longitude", longitude);
startActivity(mapIntent);
}
});
}
}
}
誰能給我一些指導,以什麼我做錯了嗎?
謝謝!我不敢相信我錯過了! – BlackHatSamurai 2012-07-06 04:52:04