Use My location Latitude Longitude and DB Latitude Longitude Calculation Distance - java

Use My location Latitude Longitude and DB Latitude Longitude Calculation Distance.but always error "The application AndroidGoogleMaps(process com.androidhive.googlemaps)has stopped unexpectedly.Please try again."
public class AndroidGoogleMapsActivity extends MapActivity {
public int mm[][]= new int[100][100];
double[][] rtdist= new double[50][2];
double[][] okdist= new double[50][2];
public GeoPoint[] endpp = new GeoPoint[100];
private static String KEY_SUCCESS = "success";
private MyLocationOverlay mylayer;
private MapController mapController;
private MapView mapView;
protected GeoPoint geoPoint;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
setupMap();
}
private void findViews() {
mapView = (MapView) findViewById(R.id.mapView);
mapController = mapView.getController();
mapView.setBuiltInZoomControls(true);
}
private void setupMap() {
List<Overlay> overlays = mapView.getOverlays();
mylayer = new MyLocationOverlay(this, mapView);
mylayer.runOnFirstFix(new Runnable() {
public void run() {
// Zoom in to current location
mapView.setTraffic(true);
mapController.setZoom(17);
mapController.animateTo(mylayer.getMyLocation());
}
});
overlays.add(mylayer);
GeoPoint startpp = mylayer.getMyLocation();
String b="SELECT lat,lng FROM markers";
UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.execqlcmd(b);
try {
if (json.getString(KEY_SUCCESS) != null)
{
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1)
{
for(int i=0 ; i<100 ; i++) {
JSONObject json_row = json.getJSONObject("r"+i);
mm[i][0]=(int)(Double.parseDouble(json_row.getString("c0")) * 1E6) ;
mm[i][1]=(int)(Double.parseDouble(json_row.getString("c1")) * 1E6) ;
endpp[i] =new GeoPoint(mm[i][0], mm[i][1] );
MapController mc = mapView.getController();
DistanceCalculator caldist= new DistanceCalculator(6371);
for(int j = 0; j < 2; j++)
{
rtdist[j][0]=1;
rtdist[j][1]=caldist.CalculationByDistance(startpp, endpp[j]);
//startpp The location of the phone is
//endpp DB's lat lng
//To judge the results of this array is in line with the distance required by the user
if(rtdist[j][1]<=50)
{
okdist[j][0]=rtdist[j][0]; //The amount of store
okdist[j][0]=rtdist[j][1]; //Store the distance
}
}
mc.animateTo(geoPoint);
mc.setZoom(15);
mapView.invalidate();
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.mark_red);
AddItemizedOverlay itemizedOverlay =
new AddItemizedOverlay(drawable, this);
OverlayItem overlayitem = new OverlayItem(geoPoint, "Hello", "Sample Overlay item");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
}}}}
catch (JSONException e) {
e.printStackTrace();
}
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
mylayer.enableMyLocation();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mylayer.disableMyLocation();
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
public class DistanceCalculator {
private double Radius;
// R = earth's radius (mean radius = 6,371km)
// Constructor
DistanceCalculator(double R) {
Radius = R;
}
public double CalculationByDistance(GeoPoint startpp, GeoPoint endpp) {
double lat1 = startpp.getLatitudeE6()/1E6;
double lat2 = endpp.getLatitudeE6()/1E6;
double lon1 = startpp.getLongitudeE6()/1E6;
double lon2 = endpp.getLongitudeE6()/1E6;
double dLat = Math.toRadians(lat2-lat1);
double dLon = Math.toRadians(lon2-lon1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2);
double c = 2 * Math.asin(Math.sqrt(a));
return Radius * c;
}
}
}
LogCat :
05-13 14:49:44.703: D/dalvikvm(303): GC_FOR_MALLOC freed 4358 objects / 275032 bytes in 316ms
05-13 14:49:44.903: D/dalvikvm(303): GC_FOR_MALLOC freed 10567 objects / 641664 bytes in 58ms
05-13 14:49:45.063: D/dalvikvm(303): GC_FOR_MALLOC freed 4727 objects / 310440 bytes in 45ms
05-13 14:49:45.243: D/dalvikvm(303): GC_FOR_MALLOC freed 6480 objects / 394584 bytes in 48ms
05-13 14:49:45.443: D/dalvikvm(303): GC_FOR_MALLOC freed 7949 objects / 616640 bytes in 51ms
05-13 14:49:45.623: D/dalvikvm(303): GC_FOR_MALLOC freed 6072 objects / 370040 bytes in 51ms
05-13 14:49:45.813: D/dalvikvm(303): GC_FOR_MALLOC freed 4449 objects / 354128 bytes in 62ms
05-13 14:49:45.823: I/dalvikvm-heap(303): Grow heap (frag case) to 3.048MB for 87396-byte allocation
05-13 14:49:45.884: D/dalvikvm(303): GC_FOR_MALLOC freed 45 objects / 2392 bytes in 66ms
05-13 14:49:45.953: D/dalvikvm(303): GC_FOR_MALLOC freed 2 objects / 80 bytes in 67ms
05-13 14:49:45.953: I/dalvikvm-heap(303): Grow heap (frag case) to 3.129MB for 87396-byte allocation
05-13 14:49:46.013: D/dalvikvm(303): GC_FOR_MALLOC freed 0 objects / 0 bytes in 58ms
05-13 14:49:46.273: E/JSON(303): {"tag":"exesqlcmd","success":1,"error":0,"rownum":2,"colnum":2,"r0":{"c0":"23.973728","c1":"121.583641"},"r1":{"c0":"23.973827","c1":"121.585625"}}
05-13 14:49:46.293: D/AndroidRuntime(303): Shutting down VM
05-13 14:49:46.293: W/dalvikvm(303): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-13 14:49:46.313: E/AndroidRuntime(303): FATAL EXCEPTION: main
05-13 14:49:46.313: E/AndroidRuntime(303): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.googlemaps/com.androidhive.googlemaps.AndroidGoogleMapsActivity}: java.lang.NullPointerException
05-13 14:49:46.313: E/AndroidRuntime(303): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-13 14:49:46.313: E/AndroidRuntime(303): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-13 14:49:46.313: E/AndroidRuntime(303): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-13 14:49:46.313: E/AndroidRuntime(303): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-13 14:49:46.313: E/AndroidRuntime(303): at android.os.Handler.dispatchMessage(Handler.java:99)
05-13 14:49:46.313: E/AndroidRuntime(303): at android.os.Looper.loop(Looper.java:123)
05-13 14:49:46.313: E/AndroidRuntime(303): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-13 14:49:46.313: E/AndroidRuntime(303): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 14:49:46.313: E/AndroidRuntime(303): at java.lang.reflect.Method.invoke(Method.java:521)
05-13 14:49:46.313: E/AndroidRuntime(303): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-13 14:49:46.313: E/AndroidRuntime(303): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-13 14:49:46.313: E/AndroidRuntime(303): at dalvik.system.NativeStart.main(Native Method)
05-13 14:49:46.313: E/AndroidRuntime(303): Caused by: java.lang.NullPointerException
05-13 14:49:46.313: E/AndroidRuntime(303): at com.androidhive.googlemaps.AndroidGoogleMapsActivity$DistanceCalculator.CalculationByDistance(AndroidGoogleMapsActivity.java:178)
05-13 14:49:46.313: E/AndroidRuntime(303): at com.androidhive.googlemaps.AndroidGoogleMapsActivity.setupMap(AndroidGoogleMapsActivity.java:106)
05-13 14:49:46.313: E/AndroidRuntime(303): at com.androidhive.googlemaps.AndroidGoogleMapsActivity.onCreate(AndroidGoogleMapsActivity.java:41)
05-13 14:49:46.313: E/AndroidRuntime(303): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-13 14:49:46.313: E/AndroidRuntime(303): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-13 14:49:46.313: E/AndroidRuntime(303): ... 11 more

if you want to calculate distance between two geographic point you have to see those two methods in the Location Class
Location Class
you can use it like this:
Location locationA = new Location("point A");
locationA.setLatitude(latA);
locationA.setLongitude(lngA);
Location locationB = new Location("point B");
locationB.setLatitude(latB);
LocationB.setLongitude(lngB);
distance = locationA.distanceTo(locationB);

Related

NullPointerException on getting current location value (lat, lng) Google Maps

My code on getting current location is working when I'm using map fragment, but when I use it in another class without displaying the map, I'm getting nullpointerException in String provider. Can you please check what's wrong with my program and if possible explain why I'm getting this error.
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v = inflater
.inflate(R.layout.layout_school_list, container, false);
lvList = (ListView) v.findViewById(R.id.lvSchools);
LocationManager locationManager = (LocationManager) getSystemService("location");
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
final Location currentLoc = locationManager
.getLastKnownLocation(provider);
if (currentLoc != null) {
onLocationChanged(currentLoc);
}
if (Distance==true){
double lat = currentLoc.getLatitude();
double lng = currentLoc.getLongitude();
ArrayList<Double> rangeList = getRangeList(lat, lng);
ArrayList<String> theList1 = new ArrayList<String>();
for (int count = 0; count < rangeList.size(); count++)
{
String temp = sTuition[count];
theTuitionFee = Integer.parseInt(temp);
for(int subloop=0; subloop<sSpecialty[count].length; subloop++) {
List<String> values = (List<String>)thisFilter[4];
if (rangeList.get(count) <= DistanceVal
&&sReg[count].equalsIgnoreCase((String)thisFilter[0])
&& sAdmin[count].equalsIgnoreCase((String)thisFilter[1])
&& sAmbience[count].equalsIgnoreCase((String)thisFilter[3])
&& amountTF >= theTuitionFee
&& filtered(sSpecialty[count][subloop], values)) {
theList1.add(sList[count]);
}
}
}
displayNearbyList(theList1);
}
Here's my methods:
public void onLocationChanged(Location location) {
double currentLat = location.getLatitude();
double currentLng = location.getLongitude();
}
And also getting error with getSystemService and my IDE requires me to put this
private LocationManager getSystemService(String string) {
// TODO Auto-generated method stub
return null;
}
which is not used in my other working class.
Here's my stack trace . I'm new here , so I don't know how to post stack trace properly
08-29 12:14:45.017: E/AndroidRuntime(6864): FATAL EXCEPTION: main
08-29 12:14:45.017: E/AndroidRuntime(6864): java.lang.NullPointerException
08-29 12:14:45.017: E/AndroidRuntime(6864): at capstone.app.recommender.SchoolListFragmentFilter.onCreateView(SchoolListFragmentFilter.java:67)
08-29 12:14:45.017: E/AndroidRuntime(6864): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
08-29 12:14:45.017: E/AndroidRuntime(6864): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
08-29 12:14:45.017: E/AndroidRuntime(6864): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
08-29 12:14:45.017: E/AndroidRuntime(6864): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
08-29 12:14:45.017: E/AndroidRuntime(6864): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
08-29 12:14:45.017: E/AndroidRuntime(6864): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)
08-29 12:14:45.017: E/AndroidRuntime(6864): at android.os.Handler.handleCallback(Handler.java:725)
08-29 12:14:45.017: E/AndroidRuntime(6864): at android.os.Handler.dispatchMessage(Handler.java:92)
08-29 12:14:45.017: E/AndroidRuntime(6864): at android.os.Looper.loop(Looper.java:137)
08-29 12:14:45.017: E/AndroidRuntime(6864): at android.app.ActivityThread.main(ActivityThread.java:5041)
08-29 12:14:45.017: E/AndroidRuntime(6864): at java.lang.reflect.Method.invokeNative(Native Method)
08-29 12:14:45.017: E/AndroidRuntime(6864): at java.lang.reflect.Method.invoke(Method.java:511)
08-29 12:14:45.017: E/AndroidRuntime(6864): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-29 12:14:45.017: E/AndroidRuntime(6864): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-29 12:14:45.017: E/AndroidRuntime(6864): at dalvik.system.NativeStart.main(Native Method)
You should replace your line
LocationManager locationManager = (LocationManager) getSystemService("location");
With this one
LocationManager locationManager = (LocationManager)<your context>.getSystemService(Context.LOCATION_SERVICE);
private LocationManager getSystemService(String string) {
// TODO Auto-generated method stub
return null;
}
This is the method you have to imlpement by yourself, as you return null. the locationManager below is null, and therefore throws NullPointerException
String provider = locationManager.getBestProvider(criteria, true);
check the post below to know how should you implement getSystemService()
How does getSystemService() work exactly?

Listview when item click it will go to another listview

So here my problem i'm setting the onitemclicklistener on listview1 and making it that if an item already exist on the order list, then the quantity will increment, but my problem is my program keep crashing
Here's my code
MainActivity.java
public class MainActivity extends Activity {
Database helper;
ListView lv,lv2;
ArrayAdapter<PostItemList> adapter;
ArrayAdapter<PostInventory> adapterInventory;
ArrayAdapter<PostOrder> adapterOrder;
ArrayList<PostItemList> list;
ArrayList<PostInventory> listInventory;
ArrayList<PostOrder> listorder;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
helper = new Database(MainActivity.this);
lv = (ListView)findViewById(R.id.itemList);
lv2 = (ListView)findViewById(R.id.orderList);
list = helper.getAllData();
adapter = new PostAdapterItemList(MainActivity.this,list);
lv.setAdapter(adapter);
listorder = new ArrayList<PostOrder>();
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1,final int pos,
long arg3) {
// TODO Auto-generated method stub
PostItemList getData = list.get(pos);
String parseData = getData.toStringOrder();
String name[] = parseData.split(",");
int itemQuantity = Integer.parseInt(name[1]);
double itemPrice = Double.parseDouble(name[2]);
if (itemQuantity == 0){
String output = name[0] + " is out of stock.";
Toast.makeText(getBaseContext(), output, Toast.LENGTH_LONG).show();
} else {
itemQuantity = itemQuantity - 1;
String newQuantity = String.valueOf(itemQuantity);
helper.updateQuantity(name[0], newQuantity);
list.clear();
list = helper.getAllData();
adapter = new PostAdapterItemList(MainActivity.this, list);
lv.setAdapter(adapter);
int checker = 0;
if (listorder.isEmpty()){
listorder.add(new PostOrder(name[0], "1", name[2]));
adapterOrder = new PostAdapterOrder(MainActivity.this,listorder);
lv2.setAdapter(adapterOrder);
} else if (listorder.size()>0){
for(PostOrder order : listorder){
if (name[0].contentEquals(order.getItemName())){
String quantity = order.getItemQuantity();
order.setItemQuantity(String.valueOf((Integer.parseInt(quantity))+1));
adapterOrder.notifyDataSetChanged();
} else {
checker = 1;
}
}
}
if (checker==1){
listorder.add(new PostOrder(name[0], "1", name[1]));
adapterOrder = new PostAdapterOrder(MainActivity.this, listorder);
lv2.setAdapter(adapterOrder);
}
}
}
});
}
Logcat
10-11 00:05:13.190: D/dalvikvm(854): GC_FOR_ALLOC freed 57K, 5% free 3034K/3176K, paused 32ms, total 33ms
10-11 00:05:13.190: I/dalvikvm-heap(854): Grow heap (frag case) to 3.646MB for 635812-byte allocation
10-11 00:05:13.290: D/dalvikvm(854): GC_FOR_ALLOC freed 0K, 4% free 3655K/3800K, paused 22ms, total 22ms
10-11 00:05:13.870: I/Choreographer(854): Skipped 73 frames! The application may be doing too much work on its main thread.
10-11 00:05:13.950: D/gralloc_goldfish(854): Emulator without GPU emulation detected.
10-11 00:05:14.230: I/Choreographer(854): Skipped 37 frames! The application may be doing too much work on its main thread.
10-11 00:05:20.070: D/AndroidRuntime(854): Shutting down VM
10-11 00:05:20.070: W/dalvikvm(854): threadid=1: thread exiting with uncaught exception (group=0xb3a67ba8)
10-11 00:05:20.080: E/AndroidRuntime(854): FATAL EXCEPTION: main
10-11 00:05:20.080: E/AndroidRuntime(854): Process: com.example.posv3, PID: 854
10-11 00:05:20.080: E/AndroidRuntime(854): java.util.ConcurrentModificationException
10-11 00:05:20.080: E/AndroidRuntime(854): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
10-11 00:05:20.080: E/AndroidRuntime(854): at com.example.posv3.MainActivity$1.onItemClick(MainActivity.java:71)
10-11 00:05:20.080: E/AndroidRuntime(854): at android.widget.AdapterView.performItemClick(AdapterView.java:299)
10-11 00:05:20.080: E/AndroidRuntime(854): at android.widget.AbsListView.performItemClick(AbsListView.java:1113)
10-11 00:05:20.080: E/AndroidRuntime(854): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2904)
10-11 00:05:20.080: E/AndroidRuntime(854): at android.widget.AbsListView$3.run(AbsListView.java:3638)
10-11 00:05:20.080: E/AndroidRuntime(854): at android.os.Handler.handleCallback(Handler.java:733)
10-11 00:05:20.080: E/AndroidRuntime(854): at android.os.Handler.dispatchMessage(Handler.java:95)
10-11 00:05:20.080: E/AndroidRuntime(854): at android.os.Looper.loop(Looper.java:136)
10-11 00:05:20.080: E/AndroidRuntime(854): at android.app.ActivityThread.main(ActivityThread.java:5017)
10-11 00:05:20.080: E/AndroidRuntime(854): at java.lang.reflect.Method.invokeNative(Native Method)
10-11 00:05:20.080: E/AndroidRuntime(854): at java.lang.reflect.Method.invoke(Method.java:515)
10-11 00:05:20.080: E/AndroidRuntime(854): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-11 00:05:20.080: E/AndroidRuntime(854): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-11 00:05:20.080: E/AndroidRuntime(854): at dalvik.system.NativeStart.main(Native Method)
If you want to remove item from your iteration
for(Iterator<MyAdapter> it = result.iterator(); it.hasNext();) {
MyAdapter s = it.next();
if(s.getClientPoints().getPointsSpent() == 0) {
it.remove();
}
}
Sir Himanshu Agarwal, thanks for helping me. i solve the problem and heres my solution for the items thats is listed when it is already present on the list
for(PostOrder order : listorder){
if (name[0].contentEquals(order.getItemName())){
String quantity = order.getItemQuantity();
order.setItemQuantity(String.valueOf((Integer.parseInt(quantity))+1));
adapterOrder.notifyDataSetChanged();
break;
} else {
counter++;
}
}
}
if (counter == listorder.size()){
listorder.add(new PostOrder(name[0], "1", name[1]));
adapterOrder = new PostAdapterOrder(MainActivity.this, listorder);
lv2.setAdapter(adapterOrder);
}

HTML parsing JSoup img doesn't work

NEW LOGCAT
06-21 13:24:25.850: W/ActivityThread(25137): Application it.rs.esempioparsinglistview is waiting for the debugger on port 8100...
06-21 13:24:40.704: W/System.err(25137): java.net.MalformedURLException: Protocol not found: /portals/v3_2/images/background-images.jpg
06-21 13:24:40.714: W/System.err(25137): at java.net.URL.<init>(URL.java:176)
06-21 13:24:40.714: W/System.err(25137): at java.net.URL.<init>(URL.java:125)
06-21 13:24:40.724: W/System.err(25137): at it.rs.esempioparsinglistview.MainActivity$ParsingPaginaWeb.doInBackground(MainActivity.java:119)
06-21 13:24:40.724: W/System.err(25137): at it.rs.esempioparsinglistview.MainActivity$ParsingPaginaWeb.doInBackground(MainActivity.java:1)
06-21 13:24:40.724: W/System.err(25137): at android.os.AsyncTask$2.call(AsyncTask.java:288)
06-21 13:24:40.724: W/System.err(25137): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-21 13:24:40.734: W/System.err(25137): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
06-21 13:24:40.744: W/System.err(25137): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-21 13:24:40.744: W/System.err(25137): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-21 13:24:40.744: W/System.err(25137): at java.lang.Thread.run(Thread.java:841)
06-21 13:29:03.541: W/ActivityThread(25327): Application it.rs.esempioparsinglistview is waiting for the debugger on port 8100...
06-21 13:29:16.984: W/System.err(25327): java.net.MalformedURLException: Protocol not found: /portals/v3_2/images/background-images.jpg
06-21 13:29:17.004: W/System.err(25327): at java.net.URL.<init>(URL.java:176)
06-21 13:29:17.004: W/System.err(25327): at java.net.URL.<init>(URL.java:125)
06-21 13:29:17.014: W/System.err(25327): at it.rs.esempioparsinglistview.MainActivity$ParsingPaginaWeb.doInBackground(MainActivity.java:118)
06-21 13:29:17.014: W/System.err(25327): at it.rs.esempioparsinglistview.MainActivity$ParsingPaginaWeb.doInBackground(MainActivity.java:1)
06-21 13:29:17.014: W/System.err(25327): at android.os.AsyncTask$2.call(AsyncTask.java:288)
06-21 13:29:17.014: W/System.err(25327): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-21 13:29:17.024: W/System.err(25327): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
06-21 13:29:17.024: W/System.err(25327): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-21 13:29:17.034: W/System.err(25327): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-21 13:29:17.034: W/System.err(25327): at java.lang.Thread.run(Thread.java:841)
HTML code
<figure class="f-art-list">
<a href="/news/Cronaca/295507/news.aspx" id="MainContent_ListNews_rptNews_lnkToNews1_0" title="Ai domiciliari dopo atti incendiari nei confronti di imprenditore di Noci. Arrestati due santermani">
<img style="display: block;" data-original="http://cdn.livenetwork.it/news/295507/634903800413300428_arresto_carabinieri_HomeStandard_191x95.jpg" src="http://cdn.livenetwork.it/news/295507/634903800413300428_arresto_carabinieri_HomeStandard_191x95.jpg" class="lazy img-responsive" alt="Ai domiciliari dopo atti incendiari nei confronti di imprenditore di Noci. Arrestati due santermani" title="Ai domiciliari dopo atti incendiari nei confronti di imprenditore di Noci. Arrestati due santermani">
</a>
</figure>
Hi i have problem on parsing HTML JSoup, LogCat evidence problem on this part:
cache.immagineart.setImageBitmap(immaginiart.get(pos));
LogCat error messages
06-20 12:30:17.097: E/AndroidRuntime(15941): FATAL EXCEPTION: main
06-20 12:30:17.097: E/AndroidRuntime(15941): Process: it.rs.esempioparsinglistview, PID: 15941
06-20 12:30:17.097: E/AndroidRuntime(15941): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
06-20 12:30:17.097: E/AndroidRuntime(15941): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
06-20 12:30:17.097: E/AndroidRuntime(15941): at java.util.ArrayList.get(ArrayList.java:308)
06-20 12:30:17.097: E/AndroidRuntime(15941): at it.rs.esempioparsinglistview.ParsingArrayAdapter.getView(ParsingArrayAdapter.java:78)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.widget.AbsListView.obtainView(AbsListView.java:2295)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.widget.ListView.onMeasure(ListView.java:1175)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.View.measure(View.java:16521)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1231)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.View.measure(View.java:16521)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.View.measure(View.java:16521)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
06-20 12:30:17.097: E/AndroidRuntime(15941): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.View.measure(View.java:16521)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
06-20 12:30:17.097: E/AndroidRuntime(15941): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2553)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.View.measure(View.java:16521)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.Choreographer.doFrame(Choreographer.java:544)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.os.Handler.handleCallback(Handler.java:733)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.os.Handler.dispatchMessage(Handler.java:95)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.os.Looper.loop(Looper.java:136)
06-20 12:30:17.097: E/AndroidRuntime(15941): at android.app.ActivityThread.main(ActivityThread.java:5142)
06-20 12:30:17.097: E/AndroidRuntime(15941): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 12:30:17.097: E/AndroidRuntime(15941): at java.lang.reflect.Method.invoke(Method.java:515)
06-20 12:30:17.097: E/AndroidRuntime(15941): at dalvik.system.NativeStart.main(Native Method)
ParsingArrayAdapter.java:78 is this: cache.immagineart.setImageBitmap(immaginiart.get(pos));
This Part is for insert Bitmap in ArrayList for img
The URL parsing is: http://www.santeramolive.it/news/tutte-le-news.aspx
Mainactivity.java
public class MainActivity extends Activity {
ListView lista;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lista = (ListView)this.findViewById(R.id.main_lista);//list id
//asynctask
ParsingPaginaWeb parsing = new ParsingPaginaWeb();
parsing.execute("");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private class ParsingPaginaWeb extends AsyncTask<String,String,String> {
ArrayList<String> titoli; //list title
ArrayList<String> descrizioni; //list description
ArrayList<String> date; // list date
ArrayList<String> categorie; // list category
ArrayList<Bitmap> immaginiart; // lista img
#Override
protected void onPreExecute()
{
titoli = new ArrayList<String>();
descrizioni = new ArrayList<String>();
date= new ArrayList<String>();
categorie= new ArrayList<String>();
immaginiart = new ArrayList<Bitmap>();
}
#Override
protected String doInBackground(String... params) {
Bitmap bitmap;
try {
Document doc = Jsoup.connect("http://www.santeramolive.it/news/tutte-le-news.aspx")
.userAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22")
.timeout(30000).get();
Element listarticoli = doc.getElementsByClass("list-articles").first();
Elements articoli = listarticoli.getElementsByClass("art-list");
for(Element articolo : articoli)
{
// title
String titolo = articolo.getElementsByClass("t-art-list").first().text();
// description
String descrizione = articolo.getElementsByTag("p").first().text();
// insert in arraylist
titoli.add(titolo);
descrizioni.add(descrizione);
Elements dcs = articolo.getElementsByClass("date-tag-art-list");
for(Element dc : dcs)
{
String data = dc.getElementsByClass("date-art-list").first().text();
String categoria = dc.getElementsByClass("tag-art-list").first().text();
date.add(data); // add date
categorie.add(categoria);// add category
}
//img part
Elements imgdivs = articolo.getElementsByClass("f-art-list");
for(Element imgsdiv : imgdivs)
{
Element divimg = imgsdiv.getElementsByClass("lazy img-responsive").first();
String imgSrc = divimg.attr("src");
InputStream input = new java.net.URL(imgSrc).openStream();
bitmap = BitmapFactory.decodeStream(input);
immaginiart.add(bitmap);
}
}
} catch (Exception e) {
Log.e("ESEMPIO", "ERRORE NEL PARSING");
}
return null;
}
#Override
protected void onPostExecute(String result)
{
ParsingArrayAdapter adapter = new ParsingArrayAdapter(MainActivity.this, titoli, descrizioni, date, categorie, immaginiart);
lista.setAdapter(adapter);
}
}
}
ParsingArrayAdapter.java
public class ParsingArrayAdapter extends ArrayAdapter<String>{
//riferimenti statici alle risorse e agli id
private final static int LAYOUT = R.layout.riga_listview;
private final static int TITOLO = R.id.riga_listview_titolo;
private final static int DESCRIZIONE = R.id.riga_listview_descrizione;
private final static int DATA = R.id.riga_listview_data;
private final static int CATEGORIA = R.id.riga_listview_categoria;
private final static int IMMAGINE= R.id.riga_listview_immagine;
ArrayList<String> titoli;
ArrayList<String> descrizioni;
ArrayList<String> date;
ArrayList<String> categorie;
ArrayList<Bitmap> immaginiart;
Context c; //context
LayoutInflater inflater; //layout inflater
public ParsingArrayAdapter(Context context,ArrayList<String> titoli,ArrayList<String> descrizioni, ArrayList<String> date, ArrayList<String> categorie, ArrayList<Bitmap> immaginiart)
{
super(context,TITOLO);
this.c = context;
this.titoli = titoli;
this.descrizioni = descrizioni;
this.date= date;
this.categorie= categorie;
this.immaginiart= immaginiart;
this.inflater = LayoutInflater.from(c);
}
#Override
public int getCount()
{
return titoli.size();
}
#Override
public View getView(int pos,View view,ViewGroup parent)
{
CacheRiga cache; //cache
if(view==null)
{
// creo la view ma non l'attacco alla lista in quanto devo ancora modificare
// i testi delle textview
view = inflater.inflate(LAYOUT, parent,false);
cache = new CacheRiga();
cache.titolo = (TextView) view.findViewById(TITOLO);
cache.descrizione = (TextView) view.findViewById(DESCRIZIONE);//collego descrizione
cache.data = (TextView) view.findViewById(DATA);
cache.categoria = (TextView) view.findViewById(CATEGORIA);
cache.immagineart = (ImageView) view.findViewById(IMMAGINE);
view.setTag(cache);
}
else
{
cache = (CacheRiga) view.getTag(); dalla view
}
cache.titolo.setText(titoli.get(pos));
cache.descrizione.setText(descrizioni.get(pos));
cache.data.setText(date.get(pos));
cache.categoria.setText(categorie.get(pos));
cache.immagineart.setImageBitmap(immaginiart.get(pos));
return view;
}
private class CacheRiga {
public TextView titolo;
public TextView descrizione;
public TextView data;
public TextView categoria;
public ImageView immagineart;
}
}
Your problem is in
String imgSrc = divimg.attr("src");
because divimg== null. The stacktrace is clearly showing this. Further the app crashes. Why didn't you tell? Why didn't you post more of the logcat/stacktrace? You would have been helped sooner.
Change your code to:
Element divimg = imgsdiv.getElementsByClass("lazy img-responsive").first();
if ( divimg==null)
{
Log.e(TAG, "divimg==null: " + titolo);
immaginiart.add(null);
}
else
{
String imgSrc = divimg.attr("src");
InputStream input = new java.net.URL(imgSrc).openStream();
bitmap = BitmapFactory.decodeStream(input);
immaginiart.add(bitmap);
}
This will not decode the image but just display an empty image.

Update and remove GridView items at runtime

i am developing a project where i compare the images of two items,So if two items will have same image after clicking these items should be hide. my code is given below and this code encounter a problem. is this a logical error or any other issue? i try to solve the issue but did't resolve.. Please guide me... here is my main Activity.
MainActivity.java
public class MainActivity extends Activity {
Context ctx;
int imagesArray[];
ImageAdapter adapter;
List<Integer> pictures;
boolean flage = false;
GridView gridView;
int save1, save2;
int img1 = -1, img2 = -1;
public int OriginalArray[] = { R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3, R.drawable.sample_0,
R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3 };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView myimage = new ImageView(ctx);
gridView = (GridView) findViewById(R.id.gv_memory);
gridView.setAdapter(adapter);
shuffleArray();
gridView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
myimage.setImageResource(pictures.get(position));
if (flage == false) {
img1 = pictures.get(position);
flage = true;
} else if (flage == true) {
img2 = pictures.get(position);
checkResult();
flage = false;
}
}
private void checkResult() {
// TODO Auto-generated method stub
if (img1 == img2) {
adapter.pictureList.remove(img1);
adapter.pictureList.remove(img2);
adapter.notifyDataSetChanged();
Toast.makeText(MainActivity.this, "Congratualatin !!!!",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainActivity.this, "Sorry!!!!",
Toast.LENGTH_LONG).show();
}
}
});
}
private void shuffleArray() {
// TODO Auto-generated method stub
pictures = new ArrayList<Integer>();
for (int index = 0; index < OriginalArray.length; index++) {
pictures.add(OriginalArray[index]);
}
Collections.shuffle(pictures);
}
}
ImageAdapter.java
public class ImageAdapter extends BaseAdapter {
private Context context;
List<Integer> pictureList = new ArrayList<Integer>();
public ImageAdapter(Context c) {
context = c;
for (int i = 0; i < 8; i++) {
pictureList.add(R.drawable.question);
}
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return (pictureList.size());
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return pictureList.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView myimage = new ImageView(context);
myimage.setImageResource(pictureList.get(position));
myimage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
myimage.setLayoutParams(new GridView.LayoutParams(70, 70));
return myimage;
}
}
LogCat.
03-14 06:09:03.793: D/dalvikvm(2877): GC_FOR_ALLOC freed 54K, 8% free 2771K/2996K, paused 111ms, total 117ms
03-14 06:09:03.802: I/dalvikvm-heap(2877): Grow heap (frag case) to 3.943MB for 1127536-byte allocation
03-14 06:09:03.922: D/dalvikvm(2877): GC_FOR_ALLOC freed 2K, 6% free 3870K/4100K, paused 118ms, total 118ms
03-14 06:09:03.962: D/AndroidRuntime(2877): Shutting down VM
03-14 06:09:03.962: W/dalvikvm(2877): threadid=1: thread exiting with uncaught exception (group=0x41465700)
03-14 06:09:03.972: E/AndroidRuntime(2877): FATAL EXCEPTION: main
03-14 06:09:03.972: E/AndroidRuntime(2877): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.memory/com.example.memory.MainActivity}: java.lang.NullPointerException
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.os.Looper.loop(Looper.java:137)
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.app.ActivityThread.main(ActivityThread.java:5103)
03-14 06:09:03.972: E/AndroidRuntime(2877): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 06:09:03.972: E/AndroidRuntime(2877): at java.lang.reflect.Method.invoke(Method.java:525)
03-14 06:09:03.972: E/AndroidRuntime(2877): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-14 06:09:03.972: E/AndroidRuntime(2877): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-14 06:09:03.972: E/AndroidRuntime(2877): at dalvik.system.NativeStart.main(Native Method)
03-14 06:09:03.972: E/AndroidRuntime(2877): Caused by: java.lang.NullPointerException
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.view.ViewConfiguration.get(ViewConfiguration.java:318)
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.view.View.<init>(View.java:3264)
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.widget.ImageView.<init>(ImageView.java:112)
03-14 06:09:03.972: E/AndroidRuntime(2877): at com.example.memory.MainActivity.onCreate(MainActivity.java:33)
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.app.Activity.performCreate(Activity.java:5133)
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-14 06:09:03.972: E/AndroidRuntime(2877): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
03-14 06:09:03.972: E/AndroidRuntime(2877): ... 11 more
03-14 06:14:04.503: I/Process(2877): Sending signal. PID: 2877 SIG: 9
You have
final ImageView myimage = new ImageView(ctx);
ctz is not initialized. Its only declared as Context ctx;
You have this
gridView.setAdapter(adapter);
But you need to intialize adapter before using the same
So change to
setContentView(R.layout.main);
final ImageView myimage = new ImageView(this); //this refers to Activity context
gridView = (GridView) findViewById(R.id.gv_memory);
adapter = new ImageAdapter(this)
gridView.setAdapter(adapter);

logcat have error about ArrayList

program not error but logcat error about index array list so picture I can't solve . please help me.
public class MainActivity extends MapActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mv = (MapView) findViewById(R.id.mapview);
mv.setBuiltInZoomControls(true);
MapController mc = mv.getController();
ArrayList all_geo_points = getDirections(16.821219, 100.260457, 13.913698, 100.510954);
GeoPoint moveTo = (GeoPoint) all_geo_points.get(0);
mc.animateTo(moveTo);
mc.setZoom(12);
mv.getOverlays().add(new MyOverlay(all_geo_points));
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
public static ArrayList getDirections(double lat1, double lon1, double lat2, double lon2) {
String url = "http://maps.googleapis.com/maps/api/directions/xml?origin=" +lat1 + "," + lon1 + "&destination=" + lat2 + "," + lon2 + "&sensor=false&units=metric";
String tag[] = { "lat", "lng" };
ArrayList list_of_geopoints = new ArrayList();
HttpResponse response = null;
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
response = httpClient.execute(httpPost, localContext);
InputStream in = response.getEntity().getContent();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in);
if (doc != null) {
NodeList nl1, nl2;
nl1 = doc.getElementsByTagName(tag[0]);
nl2 = doc.getElementsByTagName(tag[1]);
if (nl1.getLength() > 0) {
list_of_geopoints = new ArrayList();
for (int i = 0; i < nl1.getLength(); i++) {
Node node1 = nl1.item(i);
Node node2 = nl2.item(i);
double lat = Double.parseDouble(node1.getTextContent());
double lng = Double.parseDouble(node2.getTextContent());
list_of_geopoints.add(new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)));
}
} else {
// No points found
}
}
} catch (Exception e) {
e.printStackTrace();
}
return list_of_geopoints;
}
public class MyOverlay extends Overlay {
private ArrayList all_geo_points;
public MyOverlay(ArrayList allGeoPoints) {
super();
this.all_geo_points = allGeoPoints;
}
#Override
public boolean draw(Canvas canvas, MapView mv, boolean shadow, long when) {
super.draw(canvas, mv, shadow);
drawPath(mv, canvas);
return true;
}
public void drawPath(MapView mv, Canvas canvas) {
int xPrev = -1, yPrev = -1, xNow = -1, yNow = -1;
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeWidth(4);
paint.setAlpha(100);
if (all_geo_points != null)
for (int i = 0; i < all_geo_points.size() - 4; i++) {
GeoPoint gp = (GeoPoint) all_geo_points.get(i);
Point point = new Point();
mv.getProjection().toPixels(gp, point);
xNow = point.x;
yNow = point.y;
if (xPrev != -1) {
canvas.drawLine(xPrev, yPrev, xNow, yNow, paint);
}
xPrev = xNow;
yPrev = yNow;
}
}
}
}
This is code About google maps is line drive so input point latitude and longtitude two point for way line to driver and input is array . In code don't error but code have warning about array 8 wraning it all warning about array. run program have error logcat about array index.
01-18 00:37:29.720: E/AndroidRuntime(667): FATAL EXCEPTION: main
01-18 00:37:29.720: E/AndroidRuntime(667): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.getgoogledirection/com.example.getgoogledirection.MainActivity}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.os.Looper.loop(Looper.java:137)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-18 00:37:29.720: E/AndroidRuntime(667): at java.lang.reflect.Method.invokeNative(Native Method)
01-18 00:37:29.720: E/AndroidRuntime(667): at java.lang.reflect.Method.invoke(Method.java:511)
01-18 00:37:29.720: E/AndroidRuntime(667): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-18 00:37:29.720: E/AndroidRuntime(667): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-18 00:37:29.720: E/AndroidRuntime(667): at dalvik.system.NativeStart.main(Native Method)
01-18 00:37:29.720: E/AndroidRuntime(667): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
01-18 00:37:29.720: E/AndroidRuntime(667): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
01-18 00:37:29.720: E/AndroidRuntime(667): at java.util.ArrayList.get(ArrayList.java:304)
01-18 00:37:29.720: E/AndroidRuntime(667): at com.example.getgoogledirection.MainActivity.onCreate(MainActivity.java:45)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.Activity.performCreate(Activity.java:5008)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
It would be much easier to help you, if you put the output of logcat here.
As you mention, the error probably comes from the method getDirections.

Categories

Resources