获取错误:java.lang.VerifyError

时间:2012-01-21 08:30:43

标签: android google-maps verifyerror

我收到了java.lang.VerifyError。我发布了我的日志文件和代码。

我找了几个解决方案,其中一个是以下链接, 但没有什么对我有用。

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 */

我的日志文件

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)

3 个答案:

答案 0 :(得分:2)

我在清单文件中犯了错误。

我想写一下

<uses-library android:name="com.google.android.maps" />

在appilcation标签中,我所做的是,我用清单标签写了它。

所以基本上我想要遵循以下结构。

<manifest>
<uses-permission/>
<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="com.google.android.maps" />

                       .
                       .
                       .

答案 1 :(得分:1)

您是否设置了Android Manifest文件的权限,如下所示:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

答案 2 :(得分:0)

我认为您使用的任何与您的设备api版本不兼容的方法意味着您在API级别低于此级别的设备(或仿真器)中使用任何更高API级别的方法。

当我在我的应用程序中使用killBackgroundProcess()方法(在Android 2.2及更高版本中可用)并尝试在Android 1.6中运行应用程序时,我遇到了同样的错误。

希望你遇到问题。