gpt4 book ai didi

java - Android MapController 导致我的应用程序崩溃

转载 作者:行者123 更新时间:2023-12-01 19:03:20 26 4
gpt4 key购买 nike

我正在创建一个 mapView Activity ,但由于某种原因此代码不起作用:

@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

这是我对 map View 的调用:

@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);

}
});
}
}

}

任何人都可以给我一些指导,告诉我我做错了什么吗?

最佳答案

您可以尝试替换这一行:

 MapView mapView = (MapView)this.findViewById(R.layout.map_view);

这个:

 MapView mapView = (MapView)this.findViewById(R.id.<your mapView Id>);

关于java - Android MapController 导致我的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11355897/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com