我正在创建一个 mapView 活动,由于某种原因,此代码不起作用:
@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();
当我取出那条线时,应用程序会正常工作,但是当我放入它时,它会在我启动 Activity 时崩溃,并显示错误消息:
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);
}
});
}
}
}
谁能给我一些关于我做错了什么的方向?