I am getting java.lang.VerifyError.I am posting my log-file and code below.
I have looked for several solutions,one of it is the following link, but nothing is working for me.
http://groups.google.com/group/android-developers/browse_thread/thread/423b93964fae33b5
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import com.google.android.maps.GeoPoint;
import android.app.Activity;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class UseGpsActivity extends Activity {
/** Called when the activity is first created. */
private LocationManager mlocManager;
private LocationListener mlocListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Use the LocationManager class to obtain GPS locations */
boolean gps_is_enabled = false;
mlocManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
List<String> accessibleProviders = mlocManager.getProviders(true);
gps_is_enabled = accessibleProviders != null
&& accessibleProviders.size() > 0;
Log.v("gps enabled", gps_is_enabled + "");
mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
mlocListener);
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener {
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(getApplicationContext(), "Gps Disabled", 5000)
.show();
Log.v("gps", "gps disabled");
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(getApplicationContext(), "Gps Enabled", 5000).show();
Log.v("gps", "gps enabled");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onLocationChanged(Location loc) {
// TODO Auto-generated method stub
loc.getLatitude();
loc.getLongitude();
GeoPoint point = new GeoPoint(
(int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude() * 1E6));
String Text = "My current location is: " + "Latitud = "
+ loc.getLatitude() + "Longitud = " + loc.getLongitude();
Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT)
.show();
Geocoder gcd = new Geocoder(UseGpsActivity.this,
Locale.getDefault());
String address = ConvertPointToLocation(point);
Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();
// List<Address> addresses = null;
// try {
// addresses = gcd.getFromLocation(loc.getLatitude(),
// loc.getLongitude(), 1);
//
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// if (addresses != null) {
// if (addresses.size() > 0) {
// Log.v("Addresses : ", addresses.get(0).getLocality() + "");
// Toast.makeText(
// getApplicationContext(),
// "Addresses : " + addresses.get(0).getLocality()
// + "", Toast.LENGTH_LONG).show();
// Log.v("gps", Text + " " + addresses.get(0).getLocality()
// + "");
// }
// } else {
// Log.v("addresses ", "NULL");
// }
}
public String ConvertPointToLocation(GeoPoint point) {
String address = "";
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
point.getLatitudeE6() / 1E6,
point.getLongitudeE6() / 1E6, 1);
if (addresses.size() > 0) {
for (int index = 0; index < addresses.get(0).getMaxAddressLineIndex(); index++)
address += addresses.get(0).getAddressLine(index) + " ";
}
}
catch (IOException e) {
e.printStackTrace();
}
return address;
}
}/* End of Class MyLocationListener */
}/* End of UseGps Activity */
And my logfile
01-21 12:58:09.921: E/AndroidRuntime(584): Uncaught handler: thread main exiting due to uncaught exception
01-21 12:58:09.931: E/AndroidRuntime(584): java.lang.VerifyError: demo.usegps.UseGpsActivity$MyLocationListener
01-21 12:58:09.931: E/AndroidRuntime(584): at demo.usegps.UseGpsActivity.onCreate(UseGpsActivity.java:36)
01-21 12:58:09.931: E/AndroidRuntime(584): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
01-21 12:58:09.931: E/AndroidRuntime(584): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
01-21 12:58:09.931: E/AndroidRuntime(584): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
01-21 12:58:09.931: E/AndroidRuntime(584): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
01-21 12:58:09.931: E/AndroidRuntime(584): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
01-21 12:58:09.931: E/AndroidRuntime(584): at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 12:58:09.931: E/AndroidRuntime(584): at android.os.Looper.loop(Looper.java:123)
01-21 12:58:09.931: E/AndroidRuntime(584): at android.app.ActivityThread.main(ActivityThread.java:4203)
01-21 12:58:09.931: E/AndroidRuntime(584): at java.lang.reflect.Method.invokeNative(Native Method)
01-21 12:58:09.931: E/AndroidRuntime(584): at java.lang.reflect.Method.invoke(Method.java:521)
01-21 12:58:09.931: E/AndroidRuntime(584): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
01-21 12:58:09.931: E/AndroidRuntime(584): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
01-21 12:58:09.931: E/AndroidRuntime(584): at dalvik.system.NativeStart.main(Native Method)
I made a mistake in my manifest file.
I was suppose to write
in the appilcation tag, what i did was, i wrote it in manifest tag.
So basically i was suppose to follow below structure.