java.lang.OutOfMemoryError:位图大小超出虚拟机预算,即使我不使用任何图像
我的应用程序遇到了以前从未遇到过的问题。我使用这个应用程序已经有一段时间了,并且运行了数千次,但我从未遇到过此错误。
我有一个服务器,它接收一些 GPS 数据,这些数据也写入数据库和单例类中。 在我的一个类中,我使用异步任务线程来从单例类中读取到达的新 GPS 数据并在地图上显示这些点。
现在突然我在这样的行中遇到错误:
mc.animateTo(p1);
where mc=mapView.getController();
这就是我的代码的样子:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapView = (MapView) findViewById(R.id.mapview1);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
mc.setZoom(17);
mapView.setSatellite(true);
mapView.setStreetView(true);
mapView.invalidate();
}
public class InitTask extends AsyncTask<Void, GeoPoint, Void> {
GeoPoint p;
protected Void doInBackground(Void... voids) {
try {
while (true) {
if(number.equals("Car1"))
{
longitude = ServerManager.getInstance().getLastLongitude1();
latitude = ServerManager.getInstance().getLastLatitude1();
speed = ServerManager.getInstance().getLastSpeed1();
loc1 = ServerManager.getInstance().getLastLocation1();
speed = ServerManager.getInstance().getLastSpeed1();
}
runOnUiThread(new Runnable() {
public void run() {
speed_1.setText(Integer.toString(speed));
location.setText(loc1);
}
});
p = new GeoPoint(latitude, longitude);
publishProgress(p);
Thread.sleep(1500);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onProgressUpdate(GeoPoint... progress1) {
theRouteDraw(progress1[0]);
}
这就是 RouteDraw() 的样子:
public void theRouteDraw(GeoPoint p1) {
mc.animateTo(p1);
mc.setZoom(17);
mapView.setSatellite(true);
mapView.invalidate();
}
ServerManager 是我的单例类...我从那里读取新数据并使用publishProgress();以及 theRouteDraw() 方法在地图上显示这些点。
我没有在地图上使用任何叠加层或特殊图像。
我在这一行的方法中遇到错误
public void theRouteDraw(GeoPoint p1) {
public void theRouteDraw(GeoPoint p1) {
mc.animateTo(p1);
mc.setZoom(17);
mapView.setSatellite(true);
mapView.invalidate();
}
:mc.animateTo(p1);
这是我的日志猫:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
at com.google.android.maps.StreetViewRenderer.generateNewTileImage(StreetViewRenderer.java
at com.google.android.maps.StreetViewRenderer.renderTile(StreetViewRenderer.java:88)
at com.google.android.maps.AndroidTileOverlayRenderer.renderTile(AndroidTileOverlayRenderer.)
at com.google.googlenav.map.Map.drawTile(Unknown Source)
at com.google.googlenav.map.Map.drawMapBackground(Unknown Source)
at com.google.googlenav.map.Map.preLoad(Unknown Source)
at com.google.android.maps.MapController.animateTo(MapController.java:234)
at com.google.android.maps.MapController.animateTo(MapController.java:203)
at com.Server_1.Server4.theRouteDraw(Server4.java:159)
I'm having a problem in my app that I never met before.I've been having this app for a while and runned it thousands of time, but I never got this error.
I have a server that receives some GPS data that are written also in a DB and a singleton class.
In one of my classes I use an Async Task thread in order to read from the singleton class the new GPS data that arrived and display those points on the map.
And now suddenly I get error at a line like this:
mc.animateTo(p1);
where mc=mapView.getController();
This is how my code looks like:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapView = (MapView) findViewById(R.id.mapview1);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
mc.setZoom(17);
mapView.setSatellite(true);
mapView.setStreetView(true);
mapView.invalidate();
}
public class InitTask extends AsyncTask<Void, GeoPoint, Void> {
GeoPoint p;
protected Void doInBackground(Void... voids) {
try {
while (true) {
if(number.equals("Car1"))
{
longitude = ServerManager.getInstance().getLastLongitude1();
latitude = ServerManager.getInstance().getLastLatitude1();
speed = ServerManager.getInstance().getLastSpeed1();
loc1 = ServerManager.getInstance().getLastLocation1();
speed = ServerManager.getInstance().getLastSpeed1();
}
runOnUiThread(new Runnable() {
public void run() {
speed_1.setText(Integer.toString(speed));
location.setText(loc1);
}
});
p = new GeoPoint(latitude, longitude);
publishProgress(p);
Thread.sleep(1500);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onProgressUpdate(GeoPoint... progress1) {
theRouteDraw(progress1[0]);
}
This is how theRouteDraw() looks like:
public void theRouteDraw(GeoPoint p1) {
mc.animateTo(p1);
mc.setZoom(17);
mapView.setSatellite(true);
mapView.invalidate();
}
ServerManager is my singleton class...I read new data from there and use publishProgress(); and the method theRouteDraw() to display those points on the map.
I'm not using any overlay or special image on my map.
I get error in this method
public void theRouteDraw(GeoPoint p1) {
public void theRouteDraw(GeoPoint p1) {
mc.animateTo(p1);
mc.setZoom(17);
mapView.setSatellite(true);
mapView.invalidate();
}
at this line: mc.animateTo(p1);
This is my logcat:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
at com.google.android.maps.StreetViewRenderer.generateNewTileImage(StreetViewRenderer.java
at com.google.android.maps.StreetViewRenderer.renderTile(StreetViewRenderer.java:88)
at com.google.android.maps.AndroidTileOverlayRenderer.renderTile(AndroidTileOverlayRenderer.)
at com.google.googlenav.map.Map.drawTile(Unknown Source)
at com.google.googlenav.map.Map.drawMapBackground(Unknown Source)
at com.google.googlenav.map.Map.preLoad(Unknown Source)
at com.google.android.maps.MapController.animateTo(MapController.java:234)
at com.google.android.maps.MapController.animateTo(MapController.java:203)
at com.Server_1.Server4.theRouteDraw(Server4.java:159)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谷歌地图图像图块是位图,谷歌地图也缓存一些图像,因此会分配位图。我面临着类似的问题。
在这种情况下,删除:
可能会解决它,这似乎会引发错误,并且这可能涉及加载相当多的图像是有道理的。您可能在某个地方存在内存泄漏,可能是对地图视图的引用,这是问题的根源。
Google maps image tiles are bitmaps and google maps does cache some images as well, so there are bitmaps being allocated. I'm facing similar problems.
In this case removing:
Will probably solve it, this seems to be throwing the error and it makes sense that this might involve the loading of quite a few images. You might have a memory leak somewhere, probably a reference to your mapview, which is the root of the problem.