Android Google Map Api错误
问题描述:
我有一个关于通过Intent()
将数据传输到MapView的问题。Android Google Map Api错误
String coorx = temptItem.getCordx();
String coory = temptItem.getCordy();
goTomap.putExtra("x", coorx);
goTomap.putExtra("y", coory);
System.out.println(coorx);
startActivity(goTomap);
其中goTomap是我的意图: goTomap =新意图(此,MyMap.class); 但经过我的ListView中点击转到另一个类,它提供了:
java.lang.RuntimeException: Unable to start activity .....
java.lang.NullPointerException
我的清单是来自网络的许多示例代码。
<activity android:name=".MyMap"
android:label="location">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
无论如何要解决这个问题?
编辑 新增MyMap中
package com.nyp.stud084839L.isbconnects;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class MyMap extends MapActivity{
private MapView mapView;
private MapController mc;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.map_view);
String coordinates[] = {"40.747778", "-73.985556"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
GeoPoint p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc = mapView.getController();
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
答
从你已经在注释中说,您的局部变量的MapView必须为空(即findViewById()失败),因此问题是,你的布局/ main.xml不包含具有属性android:id="@+id/map_view"
的MapView。
和该行中的NullPointerException是否被抛出?也许不是你的活动,而是任何其他行... – Franco 2011-02-01 13:08:38
java.lang.RuntimeException:无法启动活动ComponentInfo {com.nyp.stud084839L.isbconnects/com.nyp.stud084839L.isbconnects.MyMap}:java.lang.NullPointerException – robobooga 2011-02-01 13:20:38