我創建使用mapActivity和MapView的一個應用程序並遇到怪異消息:
「E/AndroidRuntime(4276):java.lang.IllegalArgumentException異常:寬度和高度必須> 0」MapActivity - 寬度和高度必須> 0
該消息並不總是顯示出來。我回溯了它出現的情況,發現這個:
1)如果我已經很長時間觸摸應用程序並運行它,崩潰將顯示,請注意,如果在崩潰後我重新打開應用程序,然後有一次NO崩潰。
2)如果我刪除memrey(RAM),然後在我運行應用程序時就會死機。
3)如果我跑dibugg模式的話,我從來沒有遇到死機...
從我的角度來看,我認爲有關的東西墜毀的Android還不misured但仍試圖顯示它。 可是我還是不碰的MapView MISURE參數,所以我爲什麼要感到這樣會崩潰嗎? 反正,我不知道該怎麼做,因爲debugg模式不能真的幫助這裏。 我會展示我的onCreate()在這裏:
/******************************** Methods *****************************************
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //get rid of the title bar of the window, NOTE: we have to do this BEFORE we call "setContentView()"
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); //this line is use to remove the uppermost bar in the window (the one with the time , etc.)
setContentView(R.layout.create_map);
mMapView = (MapView)findViewById(R.id.mapview);
moveDotBtn = (Button)findViewById(R.id.movedot);
finishBuildBtn = (Button)findViewById(R.id.finish);
mapController = mMapView.getController();
mMapOverlays = mMapView.getOverlays();
mMapView.setBuiltInZoomControls(true);
mMapView.setSatellite(false);
mMapView.setStreetView(false);
whereAmI = new MyCustomLocationOverlay(this, mMapView,mapController);
mMapView.getOverlays().add(whereAmI);
//mMapView.postInvalidate(); //without that call the overlay "where_m_i" will not show.
sensor_mgr = (SensorManager) getSystemService(Context.SENSOR_SERVICE); //activate for compass
sensor = sensor_mgr.getDefaultSensor(Sensor.TYPE_ORIENTATION); //activate for compass, and orientation
powerManager =(PowerManager)getSystemService(Context.POWER_SERVICE); //to make always on, and never looked
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Lock");
locMgr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
lastLocation = null;
Touchy t = new Touchy();
mMapOverlays.add(t);
iconItems = getResources().getStringArray(R.array.icons);
RES = getResources();
mIconOverlays = new IconItemizedOverlay(RES.getDrawable(R.drawable.ic_bench));
mMapOverlays.add(mIconOverlays);
mapController.setZoom(17);
}
@Override
public void onResume()
{
wakeLock.acquire(); //make your phone awake at all times.
locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0 , whereAmI);
locMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0 , whereAmI);
whereAmI.enableMyLocation();
whereAmI.enableCompass();
findLastKnownLocation();
sensor_mgr.registerListener(sensorEventListener , sensor ,SensorManager.SENSOR_DELAY_NORMAL);
super.onResume();
}