我有一个tabview加载了mapview,当我在手机上测试代码时,它可以工作,但如果我导出APK并将其发送到客户端,它会在打开时崩溃。他们位于该国的不同地区,因此从他们那里获取任何有用的信息都是有限的。
我的手机正在运行2.2.1
他们的手机正在运行2.3.4
我在清单中使用了android:minSdkVersion =“7”。
我尝试使用各种版本的Google api libs 2.3.3适用于我的但不适合他们Google 2.1适用于我的,但不适用于他们。
应用程序的其余部分工作,只是地图崩溃了。
3.0以及之后由于某种原因全部崩溃了。
这是地图类:
public class GPSLocatorActivity extends MapActivity implements LocationListener {
private MapView map=null;
private MyLocationOverlay me=null;
private LocationManager lm;
private MyLocationOverlay lo;
private double latit;
private double lonit;
private ArrayList<HashMap<String, String>> thelist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initLocation();
map=(MapView)findViewById(R.id.mapView);
//json stuff
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, myjasonfeedurlString>>();
// Log.e("log_tag", "here we are at url "+latit);
String url = "http://myjsonlocation/json.php?la=" + latit + "&lo=" + lonit;
//Log.e("log_tag", "here is url "+url);
JSONObject json = getJSONfromURL(url);
try{
JSONArray earthquakes = json.getJSONArray("locations");
//Loop the Array
for(int i=0;i < earthquakes.length();i++){
HashMap<String, String> hmap = new HashMap<String, String>();
JSONObject e = earthquakes.getJSONObject(i);
hmap.put("id", String.valueOf(i));
hmap.put("name", e.getString("name"));
hmap.put("latitude", e.getString("lat"));
hmap.put("longitude", e.getString("lon"));
hmap.put("street", e.getString("street"));
//Log.e("log_tag", "Here's what I pulled "+e.getString("name"));
mylist.add(hmap);
}
thelist = mylist;
}
catch(JSONException e) {
// Log.e("log_tag", "Error parsing data "+e.toString());
}
map.getController().setCenter(getPoint(latit,
lonit));
map.getController().setZoom(14);
map.setBuiltInZoomControls(true);
Drawable marker=getResources().getDrawable(R.drawable.ball24);
marker.setBounds(0, 0, marker.getIntrinsicWidth(),
marker.getIntrinsicHeight());
map.getOverlays().add(new SitesOverlay(marker));
me=new MyLocationOverlay(this, map);
map.getOverlays().add(me);
}
@Override
public void onResume() {
super.onResume();
// me.enableCompass();
}
@Override
public void onPause() {
super.onPause();
lo.disableMyLocation();
// me.disableCompass();
}
@Override
protected boolean isRouteDisplayed() {
return(false);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_S) {
map.setSatellite(!map.isSatellite());
return(true);
}
else if (keyCode == KeyEvent.KEYCODE_Z) {
map.displayZoomControls(true);
return(true);
}
return(super.onKeyDown(keyCode, event));
}
private GeoPoint getPoint(double lat, double lon) {
return(new GeoPoint((int)(lat*1000000.0),
(int)(lon*1000000.0)));
}
private class SitesOverlay extends ItemizedOverlay<OverlayItem> {
private List<OverlayItem> items=new ArrayList<OverlayItem>();
public SitesOverlay(Drawable marker) {
super(marker);
boundCenterBottom(marker);
for(int i=0;i < thelist.size();i++){
Map<String, String> hmap = thelist.get(i);
double tlo = Double.valueOf(hmap.get("longitude"));
double tla = Double.valueOf(hmap.get("latitude"));
GeoPoint point = new GeoPoint((int)(tla*1E6),(int)(tlo*1E6));
//Log.e("log_tag","geopoint : " + point +" me "+ (int)(latit*1000000.0) + " , " +(int)(lonit*1000000.0));
items.add(new OverlayItem(point,hmap.get("name"), hmap.get("street")));
}
items.add(new OverlayItem(getPoint(0.748963847316034,
-123.96807193756104),
"blank", "placeholder"));
populate();
}
@Override
protected OverlayItem createItem(int i) {
return(items.get(i));
}
@Override
protected boolean onTap(int i) {
Toast.makeText(GPSLocatorActivity.this,
items.get(i).getTitle() + " @ " + items.get(i).getSnippet(),
Toast.LENGTH_SHORT).show();
return(true);
}
@Override
public int size() {
return(items.size());
}
}
private void initLocation(){
lm= (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 500, this);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
// Log.e("log_tag", "lat "+ latitude);
// Log.e("log_tag", "lon: "+ longitude);
latit = latitude;
lonit = longitude;
}
public void onLocationChanged(Location arg0) {
List overlays = map.getOverlays();
lo = new MyLocationOverlay(this,map);
overlays.add(lo);
lo.enableMyLocation();
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
//json
public static JSONObject getJSONfromURL(String url){
//initialize
InputStream is = null;
String result = "";
JSONObject jArray = null;
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
//Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
//Log.e("log_tag", "Error converting result "+e.toString());
}
//try parse the string to a JSON object
try{
jArray = new JSONObject(result);
}catch(JSONException e){
//Log.e("log_tag", "Error parsing data "+e.toString());
}
return jArray;
}
//json
}
任何想法都将不胜感激。我还没有使用地图。
由于
答案 0 :(得分:0)
设置BugSense帐户并将其集成到您的应用中,以便您可以跟踪其他设备上的崩溃情况。除非你知道异常是什么,否则很难知道原因是什么。