Closed GoogleCodeExporter closed 9 years ago
Emulator reports following error:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.test/com.test.MainActivity}:
android.os.NetworkOnMainThreadException
Original comment by n3d...@gmail.com
on 1 Sep 2012 at 6:34
I just tried the Demo application with an Android 4.0.3 AVD
=> no crash, the app loads and display the road exactly as on previous Android
versions!
Very strange.
Could you download and try the OSMBonusPackDemo app on your emulator?
Could you tell which osmdroid and osmbonuspack versions you use?
And could you provide your source code?
Thanks
Original comment by mathieu....@gmail.com
on 1 Sep 2012 at 8:50
osmdroid 3.0.8
osmbonuspack 2.1
Code:
package com.test.android;
import java.util.ArrayList;
import org.osmdroid.bonuspack.routing.OSRMRoadManager;
import org.osmdroid.bonuspack.routing.Road;
import org.osmdroid.bonuspack.routing.RoadManager;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.PathOverlay;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
private MapView map;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = (MapView) findViewById(R.id.mapview);
map.setTileSource(TileSourceFactory.MAPNIK);
GeoPoint startPoint = new GeoPoint(48.13, -1.63);
MapController mapController = map.getController();
mapController.setCenter(startPoint);
mapController.setZoom(15);
RoadManager roadManager = new OSRMRoadManager();
ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
waypoints.add(startPoint);
waypoints.add(new GeoPoint(48.4, -1.9)); //end point
Road road = roadManager.getRoad(waypoints);
PathOverlay roadOverlay = RoadManager.buildRoadOverlay(road, map.getContext());
map.getOverlays().add(roadOverlay);
map.invalidate();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Original comment by n3d...@gmail.com
on 1 Sep 2012 at 10:54
Here is eclipse project:
http://ubuntuone.com/0KlvVfV2tQaVXBiPZTEb4S
Original comment by n3d...@gmail.com
on 2 Sep 2012 at 5:08
I found. Look at:
http://developer.android.com/reference/android/os/NetworkOnMainThreadException.h
tml
Basically, from SDK 3.0, we can't do network calls in the main thread.
I didn't got the issue on OSMBonusPackDemo because 1/ It targets an earlier SDK
version, and 2/ all network calls in the demo are done in threads (async
tasks).
You have 2 solutions:
- Give to your project a target SDK version earlier than 3.0 (even if the
emulator or phone used is > 3.0)
- Do the calls in threads => looking at the source code of the demo app could
help you.
I will add a note about that issue in the tutorials.
Original comment by mathieu....@gmail.com
on 2 Sep 2012 at 7:26
Thank you for response
Original comment by n3d...@gmail.com
on 2 Sep 2012 at 7:38
Original comment by mathieu....@gmail.com
on 5 Sep 2012 at 7:23
Original issue reported on code.google.com by
n3d...@gmail.com
on 1 Sep 2012 at 6:32