2011-10-06 83 views
2

我正在努力尋找此代碼鎖定的原因。據我所知,我在我的清單文件中聲明瞭正確的權限,如下所示。我曾嘗試在實際的設備上運行它(Droid x w。/ 2.3.3)和AVD無濟於事。我已經附上了logcat,這也把我帶到了classnotfound異常。我已經清理了該項目,並驗證了maps.jar包含在googleapi的包中,我也用它作爲應用程序的目標。 (Google API的2.3.3)。不知道該從哪裏出發。使用MapView引發的ClassNotFoundException

Activity Code: 

'package com.SmartPark; 

import java.util.List; 

import android.content.Context; 
import android.graphics.drawable.Drawable; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.os.Handler; 
import android.widget.LinearLayout; 
//import android.widget.TextView; 
import android.widget.Toast; 

import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapView; 
import com.google.android.maps.Overlay; 
import com.google.android.maps.OverlayItem; 



public class SmartParkActivity extends MapActivity { 
//** Called when the activity is first created. */ 
    LinearLayout linearlayout; 
    MapView mapView; 
    List<Overlay> mapOverlays; 
    Drawable drawable; 
    HelloItemizedOverlay itemizedOverlay; 
    GeoPoint point = new GeoPoint(42392400,-83134700); 
    OverlayItem overlayitem = new OverlayItem(point, "", ""); 
    private LocationManager lm; 
    private LocationListener locationListener; 
    public double[] gps=new double[2]; 
    public boolean setgps; 
    final Handler mHandler = new Handler(); 
    //TextView tvl; //latitude display 
    // TextView tvlong;//longitude display 
    int lat2; 
    int longitude2; 
    public float z; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     mapView = (MapView) findViewById(R.id.mapview); 
     mapView.setBuiltInZoomControls(true); 
     mapOverlays = mapView.getOverlays(); 
     drawable = this.getResources().getDrawable(R.drawable.greendot1); 
     itemizedOverlay = new HelloItemizedOverlay(drawable); 
     OverlayItem overlayitem = new OverlayItem(point, "", ""); 
     itemizedOverlay.addOverlay(overlayitem); 
     mapOverlays.add(itemizedOverlay); 
     // tvl = (TextView) this.findViewById(R.id.gpslview); 
     // tvlong = (TextView) this.findViewById(R.id.gpslongview); 
    } 

    @Override 
    protected boolean isRouteDisplayed() { 

      return false; 
    } 

    @Override 
     protected void onStart() { 
      super.onStart(); 


     lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

     locationListener = new MyLocationListener(); 

     lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 0, 
       locationListener); 

     mHandler.postDelayed(mUpdateTimeTask, 500); 



    } 
    @Override 
    protected void onStop() { 
     super.onStop(); 

     lm.removeUpdates(locationListener); 
     mHandler.removeCallbacks(mUpdateTimeTask); 
     } 

    @Override 
    protected void onDestroy() { 
     super.onDestroy(); 

     lm.removeUpdates(locationListener); 
     mHandler.removeCallbacks(mUpdateTimeTask); 
     } 






    //} 
// helper method to schedule the postdelayed mhandler at specified interval 
    private boolean foo() { 
     setgps=false; 


     mHandler.postDelayed(mUpdateTimeTask, 500); 

     return true; 
    }; 


    //Method to acquire set gps variable and display it. update overlay if  possible 
    private Runnable mUpdateTimeTask = new Runnable() { 
      public void run() { 

       mapOverlays.clear(); 
       GeoPoint point = setgeopoint(gps[0],gps[1]); 
       OverlayItem overlayitem = new OverlayItem(point, "", ""); 
       mapOverlays.add(itemizedOverlay); 
       itemizedOverlay.addOverlay(overlayitem); 

       // tvl.setText("Latitude:"+gps[0]); 
       // tvlong.setText("Longitude"+gps[1]); 
       // z=(float)android.location.Location.getSpeed(); 
       setgps=foo(); //reschedules the task 

    }; 
    }; 

    //math functions 

    //convert gps double to an int and set to GeoPoint 
    public GeoPoint setgeopoint (double dl, double dlong) { 
     int intl = (int) (dl*1000000); 
     int intlong = (int) (dlong*1000000); 

     GeoPoint point= new GeoPoint (intl, intlong); 
     return point; 
    } 




    public class MyLocationListener implements LocationListener 
    { 
     @Override 
     public void onLocationChanged(Location loc) 
     { 
      if (loc != null) { 
       Toast.makeText(
         getBaseContext(), 
         "Location changed : Lat: " + loc.getLatitude() 
           + " Lng: " + loc.getLongitude(), 
         Toast.LENGTH_SHORT).show(); 
       gps[0]= lat2; 
       gps[1]=longitude2; 
       gps[0] = loc.getLatitude(); 
       gps[1] = loc.getLongitude(); 
       z=loc.getSpeed(); 

      } 
     } 
     public void onProviderDisabled(String provider) 
     { 
      Toast.makeText(getApplicationContext(),"Gps  Disabled",Toast.LENGTH_SHORT).show(); 
     } 
     public void onProviderEnabled(String provider) 
     { 
      Toast.makeText(getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show(); 
     } 
     public void onStatusChanged(String provider, int status, Bundle extras) 
     { 
      Toast.makeText(getApplicationContext(),"Status changed",Toast.LENGTH_SHORT).show(); 
     } 
    } 





}' 

清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.SmartPark" 
    android:versionCode="1" 
    android:versionName="1.0"> 
<uses-sdk android:minSdkVersion="10" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses- permission> 
    <uses-permission android:name="android.permission.ACCESS_LOCATION"></uses-permission> 
<uses-permission android:name="android.permission.ACCESS_GPS"></uses-permission> 
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS"></uses-permission> 
<application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <uses-library android:name="com.google.android.maps" /> 
    <activity android:name=".MapviewActivity" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

    </activity> 
    </application> 

</manifest> 

的logcat:

10-06 09:19:07.239: ERROR/AndroidRuntime(13602): java.lang.RuntimeException: Unable to  instantiate activity ComponentInfo{com.SmartPark/com.SmartPark.MapviewActivity}:  java.lang.ClassNotFoundException: com.SmartPark.MapviewActivity in loader  dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.SmartPark-2.apk] 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1618) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at android.app.ActivityThread.access$1500(ActivityThread.java:124) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at  android.app.ActivityThread$H.handleMessage(ActivityThread.java:968) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at android.os.Handler.dispatchMessage(Handler.java:99) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at android.os.Looper.loop(Looper.java:123) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at android.app.ActivityThread.main(ActivityThread.java:3806) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at java.lang.reflect.Method.invokeNative(Native Method) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at java.lang.reflect.Method.invoke(Method.java:507) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at dalvik.system.NativeStart.main(Native Method) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602): Caused by: java.lang.ClassNotFoundException: com.SmartPark.MapviewActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.SmartPark-2.apk] 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1610) 
10-06 09:19:07.239: ERROR/AndroidRuntime(13602):  ... 11 more 
+0

不錯的個人資料圖片。 :) –

+0

不要介意「使用圖書館」的位置。我發佈了錯誤的清單。我將地圖庫移動到應用程序標記的子節點上,併發生相同的錯誤。上面顯示的固定清單。還是一樣的錯誤 – johann316

回答

1

您的清單中是否應該是MapViewActivity而不是MapviewActivity

+0

由拉斯維加斯的啓發!我將兩個不同的程序合併到一個程序中,但是當我從MapView活動中複製並粘貼清單時,我沒有將活動的名稱更改爲SmartPark。 DER!謝謝你拉斯維加斯鼓舞我。適當的活動名稱應該是SmartParkActivity ...而不是MapView。 – johann316

2

添加使用庫中應用的標籤......(你在活動標記添加...)

所以你androidmanifiest如下::

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.SmartPark" 
    android:versionCode="1" 
    android:versionName="1.0"> 
<uses-sdk android:minSdkVersion="10" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> 
    <uses-permission android:name="android.permission.ACCESS_LOCATION"></uses-permission> 
    <uses-permission android:name="android.permission.ACCESS_GPS"></uses-permission> 
    <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS"> </uses-permission> 
<application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <uses-library android:name="com.google.android.maps"></uses-library> 
    <activity android:name=".SmartParkActivity" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <uses-library android:name="com.google.android.maps" /> 
    </activity> 

</application> 

</manifest> 
+0

是的,對不起,我試過了,但它仍然不起作用。同樣的錯誤。發佈的清單是我試圖移動地圖文件的地方,但它仍然無效。上面顯示的固定清單。 – johann316

+0

現在添加這個鮮明的文件,我改變了它....... –

相關問題