【发布时间】:2012-12-05 19:18:02
【问题描述】:
我正在开发一个 android 应用程序。在我的活动中,我使用以下代码。
LocationResult locationResult = new LocationResult(){
@Override
public void gotLocation(Location location){
//Got the location!
Drawable marker = getResources().getDrawable(
R.drawable.currentlocationmarker);//android.R.drawable.btn_star_big_on
int markerWidth = marker.getIntrinsicWidth();
int markerHeight = marker.getIntrinsicHeight();
marker.setBounds(0, markerHeight, markerWidth, 0);
MyItemizedOverlay myItemizedOverlay = new MyItemizedOverlay(marker);
currentmarkerPoint = new GeoPoint((int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
currLocation = location;
mBlippcoordinate = currentmarkerPoint;
mBlippLocation = location;
myItemizedOverlay.addItem(currentmarkerPoint, "", "");
mBlippmapview.getOverlays().add(myItemizedOverlay);
animateToCurrentLocation(currentmarkerPoint);
}
};
MyLocation myLocation = new MyLocation();
myLocation.getLocation(this, locationResult);
我正在使用上面的代码从 gps 或网络中查找位置。animateToCurrentLocation(currentmarkerPoint); 方法包含一个异步任务。所以我得到了
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
提前致谢。
【问题讨论】:
-
我敢打赌,你的 asynctask 中有某种对话框或 toast :) 你需要重新排列你的代码,这样你就不会从 UI 进行网络操作
标签: android android-asynctask handler