MapActivity - 宽度和高度必须是> 0 [英] MapActivity - width and height must be > 0

查看:145
本文介绍了MapActivity - 宽度和高度必须是> 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用mapActivity和MapView的一个应用程序,并遇到奇怪的消息:结果
E / AndroidRuntime(4276):java.lang.IllegalArgumentException异常:宽度和高度必须> 0

这消息并不总是出现。我backtraced它显示了有关情况,并发现了这一点:

1),如果它已经很长一段时间,因为我接触到的应用程序,然后运行它,崩溃遗嘱显示,注意,如果撞车后我重新打开应用程序,然后有一次崩溃。

2)如果我删除memrey(RAM),然后在我运行应用程序会崩溃。

3)如果我跑dibugg模式,然后我从来没有遇到死机...

从我的角度来看我觉得Android的还不misured但相关的东西崩溃仍试图显示它。
我还是不碰的MapView MISURE参数,所以我为什么要永远得到此崩溃?
反正,我不知道该怎么办,因为debugg模式不能真的帮助在这里。
我会显示我的onCreate()位置:

  / **************方法**** *************************************
@覆盖
公共无效的onCreate(捆绑savedInstanceState){    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE); //摆脱了窗口的标题栏,注:我们之前我们称之为做到这一点的setContentView()
    //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); //这条线被用于删除在窗口的最上栏(一个与时间等)    的setContentView(R.layout.create_map);
    mMapView =(图形页面)findViewById(R.id.mapview);
    moveDotBtn =(按钮)findViewById(R.id.movedot);
    finishBuildBtn =(按钮)findViewById(R.id.finish);    mapController = mMapView.getController();
    mMapOverlays = mMapView.getOverlays();
    mMapView.setBuiltInZoomControls(真);
    mMapView.setSatellite(假);
    mMapView.setStreetView(假);    WHEREAMI =新MyCustomLocationOverlay(这一点,mMapView,mapController);
    。mMapView.getOverlays()加(WHEREAMI);
    //mMapView.postInvalidate(); //无需调用覆盖where_m_i将不会显示。    sensor_mgr =(的SensorManager)getSystemService(Context.SENSOR_SERVICE); //激活罗盘
    传感器= sensor_mgr.getDefaultSensor(Sensor.TYPE_ORIENTATION); //激活指南针,和方向    电源管理=(电源管理)getSystemService(Context.POWER_SERVICE); //使始终,从不看
    激活锁定= powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK,我的锁);    locMgr =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
    lastLocation = NULL;
    敏感的T =新暴躁();
    mMapOverlays.add(T);    iconItems = getResources()getStringArray(R.array.icons)。
    RES = getResources();
    mIconOverlays =新IconItemizedOverlay(RES.getDrawable(R.drawable.ic_bench));
    mMapOverlays.add(mIconOverlays);    mapController.setZoom(17);
}@覆盖
公共无效onResume()
{
    wakeLock.acquire(); //让你的手机清醒的时刻。    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,传感器,SensorManager.SENSOR_DELAY_NORMAL);
    super.onResume();
}


解决方案

您应该做onWindowFocusChanged更改,因为你不是在那之前获分配的屏幕高度/宽度。

  @覆盖
   公共无效onWindowFocusChanged(布尔hasFocus){
      如果(hasFocus){
             setOverlay(); //你的code应该来这里
         }
      }
      super.onWindowFocusChanged(hasFocus);
   }

i created an app using mapActivity and MapView and encounter the wierd message:
" E/AndroidRuntime(4276): java.lang.IllegalArgumentException: width and height must be > 0 "

that message is not always shows up. I backtraced the situation it shows up and found out this:

1) If it's been long time since i touch the app and then run it, the crash wills show up, note that if after the crash i reopen the app then there is NO crash again.

2) if I delete the memrey (RAM) then after i run the app it will crash.

3)if I run dibugg mode then i never encounter the crash...

from my point of view i think the crash related to something that Android did not yet misured but still trying to display it. still i do not touch the mapview misure parameters so why should i ever get this crash? anyways, i have no idea what to do since the debugg mode can't realy help here. i will display my onCreate() here:

/********************************  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();
}

解决方案

You should do your changes in onWindowFocusChanged since you are not alloted screen height/width before that.

 @Override
   public void onWindowFocusChanged(boolean hasFocus) {
      if (hasFocus) {
             setOverlay(); //Your code should come here
         }
      }
      super.onWindowFocusChanged(hasFocus);
   }

这篇关于MapActivity - 宽度和高度必须是> 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆