FATAL EXCEPTION: main android
Bonsoir;
je suis entraîne de coder la partie du calcul d’itinéraire dans mon projet ,j'ai une erreur qui ferme tout.et voici LogCat::
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
02-24 23:38:20.869: E/AndroidRuntime(2858): FATAL EXCEPTION: main
02-24 23:38:20.869: E/AndroidRuntime(2858): java.lang.IllegalStateException: Could not execute method of the activity
02-24 23:38:20.869: E/AndroidRuntime(2858): at android.view.View$1.onClick(View.java:3597)
02-24 23:38:20.869: E/AndroidRuntime(2858): at android.view.View.performClick(View.java:4202)
02-24 23:38:20.869: E/AndroidRuntime(2858): at android.view.View$PerformClick.run(View.java:17340)
02-24 23:38:20.869: E/AndroidRuntime(2858): at android.os.Handler.handleCallback(Handler.java:725)
02-24 23:38:20.869: E/AndroidRuntime(2858): at android.os.Handler.dispatchMessage(Handler.java:92)
02-24 23:38:20.869: E/AndroidRuntime(2858): at android.os.Looper.loop(Looper.java:137)
02-24 23:38:20.869: E/AndroidRuntime(2858): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-24 23:38:20.869: E/AndroidRuntime(2858): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 23:38:20.869: E/AndroidRuntime(2858): at java.lang.reflect.Method.invoke(Method.java:511)
02-24 23:38:20.869: E/AndroidRuntime(2858): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-24 23:38:20.869: E/AndroidRuntime(2858): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-24 23:38:20.869: E/AndroidRuntime(2858): at dalvik.system.NativeStart.main(Native Method)
02-24 23:38:20.869: E/AndroidRuntime(2858): Caused by: java.lang.reflect.InvocationTargetException
02-24 23:38:20.869: E/AndroidRuntime(2858): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 23:38:20.869: E/AndroidRuntime(2858): at java.lang.reflect.Method.invoke(Method.java:511)
02-24 23:38:20.869: E/AndroidRuntime(2858): at android.view.View$1.onClick(View.java:3592)
02-24 23:38:20.869: E/AndroidRuntime(2858): ... 11 more
02-24 23:38:20.869: E/AndroidRuntime(2858): Caused by: android.os.NetworkOnMainThreadException
02-24 23:38:20.869: E/AndroidRuntime(2858): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
02-24 23:38:20.869: E/AndroidRuntime(2858): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
02-24 23:38:20.869: E/AndroidRuntime(2858): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
02-24 23:38:20.869: E/AndroidRuntime(2858): at java.net.InetAddress.getAllByName(InetAddress.java:214)
02-24 23:38:20.869: E/AndroidRuntime(2858): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
02-24 23:38:20.869: E/AndroidRuntime(2858): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
02-24 23:38:20.869: E/AndroidRuntime(2858): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
02-24 23:38:20.869: E/AndroidRuntime(2858): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
02-24 23:38:20.869: E/AndroidRuntime(2858): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
02-24 23:38:20.869: E/AndroidRuntime(2858): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
02-24 23:38:20.869: E/AndroidRuntime(2858): at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
02-24 23:38:20.869: E/AndroidRuntime(2858): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
02-24 23:38:20.869: E/AndroidRuntime(2858): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
02-24 23:38:20.869: E/AndroidRuntime(2858): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
02-24 23:38:20.869: E/AndroidRuntime(2858): at com.example.bissgeolocalistor.Path.DrawPath(Path.java:51)
02-24 23:38:20.869: E/AndroidRuntime(2858): at com.example.bissgeolocalistor.MainActivity.calcRoute(MainActivity.java:38)
02-24 23:38:20.869: E/AndroidRuntime(2858): ... 14 more
02-24 23:38:20.896: D/dalvikvm(2858): GC_CONCURRENT freed 82K, 6% free 3557K/3760K, paused 75ms+127ms, total 278ms
02-24 23:38:22.956: D/dalvikvm(2858): GC_CONCURRENT freed 68K, 6% free 3919K/4160K, paused 6ms+83ms, total 939ms
02-24 23:38:22.956: D/dalvikvm(2858): WAIT_FOR_CONCURRENT_GC blocked 738ms
02-24 23:38:25.257: I/Process(2858): Sending signal. PID: 2858 SIG: 9 |
la class MainActivity::
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| package com.example.bissgeolocalistor;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class MainActivity extends MapActivity {
private MapView mapView;
private MapController mc;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView) this.findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
mc.setZoom(17);
}
public void calcRoute(View v)
{
double src_lat = 25.04202;
double src_long = 121.534761;
double dest_lat = 25.05202;
double dest_long = 121.554761;
GeoPoint srcGeoPoint = new GeoPoint((int) (src_lat * 1E6),
(int) (src_long * 1E6));
GeoPoint destGeoPoint = new GeoPoint((int) (dest_lat * 1E6),
(int) (dest_long * 1E6));
mapView.getController().animateTo(srcGeoPoint);
Path a= new Path();
a.DrawPath(srcGeoPoint, destGeoPoint, Color.BLACK, mapView);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
} |
el la class Path::::
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| package com.example.bissgeolocalistor;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import android.util.Log;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
public class Path {
public Path() {
}
public void DrawPath(GeoPoint src, GeoPoint dest, int color,MapView mapView) {
// connect to map web service
StringBuilder urlString = new StringBuilder();
urlString.append("http://maps.google.com/maps?f=d&hl=en");
urlString.append("&saddr=");// from
urlString.append(Double.toString((double) src.getLatitudeE6() / 1.0E6));
urlString.append(",");
urlString.append(Double.toString((double) src.getLongitudeE6() / 1.0E6));
urlString.append("&daddr=");// to
urlString.append(Double.toString((double) dest.getLatitudeE6() / 1.0E6));
urlString.append(",");
urlString.append(Double.toString((double) dest.getLongitudeE6() / 1.0E6));
urlString.append("&ie=UTF8&0&om=0&output=kml");
Log.d("xxx", "URL=" + urlString.toString());
// get the kml (XML) doc. And parse it to get the coordinates(direction
// route).
Document doc = null;
HttpURLConnection urlConnection = null;
URL url = null;
try {
url = new URL(urlString.toString());
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(urlConnection.getInputStream());
if (doc.getElementsByTagName("GeometryCollection").getLength() > 0) {
// String path =
// doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getNodeName();
String path = doc.getElementsByTagName("GeometryCollection")
.item(0).getFirstChild().getFirstChild()
.getFirstChild().getNodeValue();
Log.d("xxx", "path=" + path);
String[] pairs = path.split(" ");
String[] lngLat = pairs[0].split(","); // lngLat[0]=longitude
// lngLat[1]=latitude
// lngLat[2]=height
// src
GeoPoint startGP = new GeoPoint((int) (Double
.parseDouble(lngLat[1]) * 1E6), (int) (Double
.parseDouble(lngLat[0]) * 1E6));
mapView.getOverlays()
.add(new MyOverLay(startGP, startGP, 1));
GeoPoint gp1;
GeoPoint gp2 = startGP;
for (int i = 1; i < pairs.length; i++) // the last one would be
// crash
{
lngLat = pairs[i].split(",");
gp1 = gp2;
// watch out! For GeoPoint, first:latitude, second:longitude
gp2 = new GeoPoint(
(int) (Double.parseDouble(lngLat[1]) * 1E6),
(int) (Double.parseDouble(lngLat[0]) * 1E6));
mapView.getOverlays().add(
new MyOverLay(gp1, gp2, 2, color));
Log.d("xxx", "pair:" + pairs[i]);
}
mapView.getOverlays().add(new MyOverLay(dest, dest, 3)); // use
// the
// default
// color
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
}
} |
et androidmanifest::
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bissgeolocalistor"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.bissgeolocalistor.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest> |
Si quelqu'un pouvait au moins me donner une piste
Cordialement