2012-01-21 106 views
1

我得到java.lang.VerifyError.I發佈我的日誌文件和下面的代碼。獲取錯誤: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) 

回答

1

我在我的清單文件中犯了一個錯誤。

我想寫

<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

你有沒有設置你的AndroidManifest文件permision這樣的:

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

我認爲你正在使用的任何方法與您的設備api版本不兼容意味着您正在使用任何更高級別的方法API級別低於API級別的設備(或模擬器)中的API級別。

因爲我在我的應用程序中使用killBackgroundProcess()方法(在Android 2.2及更高版本中可用)並且試圖在android 1.6中運行應用程序時遇到了同樣的錯誤。

希望你有這個問題。