2013-03-14 58 views
1

我有一個問題,我正在做一個地圖應用程序,我需要使用一些浮動menu.i找到一個很好的例子,它被張貼在這個網站(QuickAction)。但是當我包括這個項目構建我的項目的路徑,我得到一個NoClassDefError。繼承人我的日誌。NoClassDefException導入項目時

的logcat:

03-14 15:19:17.858: W/dalvikvm(1807): VFY: unable to find class referenced in signature (Lnet/londatiga/android/QuickAction;) 
03-14 15:19:17.888: E/dalvikvm(1807): Could not find class 'net.londatiga.android.ActionItem', referenced from method com.gps.gpsclient.GPSClientActivity.createFloatingMenu 
03-14 15:19:17.888: W/dalvikvm(1807): VFY: unable to resolve new-instance 646 (Lnet/londatiga/android/ActionItem;) in Lcom/gps/gpsclient/GPSClientActivity; 
03-14 15:19:17.888: D/dalvikvm(1807): VFY: replacing opcode 0x22 at 0x0000 
03-14 15:19:17.898: D/dalvikvm(1807): DexOpt: unable to opt direct call 0x0f95 at 0x02 in Lcom/gps/gpsclient/GPSClientActivity;.createFloatingMenu 
03-14 15:19:17.908: D/dalvikvm(1807): DexOpt: unable to opt direct call 0x0f98 at 0x20 in Lcom/gps/gpsclient/GPSClientActivity;.createFloatingMenu 
03-14 15:19:17.968: I/org.osmdroid.views.MapView(1807): Using tile source: [email protected] 
03-14 15:19:17.978: I/org.osmdroid.tileprovider.modules.MapTileFileStorageProviderBase(1807): sdcard state: mounted 
03-14 15:19:17.978: I/org.osmdroid.tileprovider.modules.MapTileFileStorageProviderBase(1807): sdcard state: mounted 
03-14 15:19:18.038: I/org.osmdroid.tileprovider.MapTileProviderBase(1807): rescale tile cache from 0 to 10 
03-14 15:19:18.088: I/org.osmdroid.tileprovider.MapTileProviderBase(1807): Finished rescale in 44ms 
03-14 15:19:18.098: D/dalvikvm(1807): GC_CONCURRENT freed 141K, 3% free 6877K/7047K, paused 2ms+7ms 
03-14 15:19:18.128: D/dalvikvm(1807): GC_FOR_ALLOC freed 39K, 4% free 7144K/7431K, paused 28ms 
03-14 15:19:18.258: D/dalvikvm(1807): GC_CONCURRENT freed 206K, 3% free 7467K/7687K, paused 2ms+3ms 
03-14 15:19:18.258: D/AndroidRuntime(1807): Shutting down VM 
03-14 15:19:18.268: I/dalvikvm(1807): threadid=3: reacting to signal 3 
03-14 15:19:18.288: W/dalvikvm(1807): threadid=1: thread exiting with uncaught exception (group=0x40a671f8) 
03-14 15:19:18.298: I/dalvikvm(1807): Wrote stack traces to '/data/anr/traces.txt' 
03-14 15:19:18.298: E/AndroidRuntime(1807): FATAL EXCEPTION: main 
03-14 15:19:18.298: E/AndroidRuntime(1807): java.lang.NoClassDefFoundError: net.londatiga.android.ActionItem 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at com.gps.gpsclient.GPSClientActivity.createFloatingMenu(GPSClientActivity.java:61) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at com.gps.gpsclient.GPSClientActivity.onCreate(GPSClientActivity.java:47) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at android.app.Activity.performCreate(Activity.java:4492) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at android.app.ActivityThread.access$600(ActivityThread.java:123) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at android.os.Handler.dispatchMessage(Handler.java:99) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at android.os.Looper.loop(Looper.java:137) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at android.app.ActivityThread.main(ActivityThread.java:4424) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at java.lang.reflect.Method.invokeNative(Native Method) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at java.lang.reflect.Method.invoke(Method.java:511) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
03-14 15:19:18.298: E/AndroidRuntime(1807):  at dalvik.system.NativeStart.main(Native Method) 
03-14 15:19:18.558: D/dalvikvm(1807): GC_CONCURRENT freed 406K, 7% free 7450K/7943K, paused 3ms+2ms 
03-14 15:19:18.768: I/dalvikvm(1807): threadid=3: reacting to signal 3 
03-14 15:19:18.768: I/dalvikvm(1807): Wrote stack traces to '/data/anr/traces.txt' 
03-14 15:19:18.888: I/dalvikvm(1807): threadid=3: reacting to signal 3 
03-14 15:19:18.898: I/dalvikvm(1807): Wrote stack traces to '/data/anr/traces.txt' 

我認爲它與構建路徑somethink,但是這是我第一次寫清項目構建路徑,所以我沒有任何經驗,that.Imports工作正常。

活動:

package com.gps.gpsclient; 



import net.londatiga.android.ActionItem; 
import net.londatiga.android.QuickAction; 

import org.osmdroid.tileprovider.tilesource.TileSourceFactory; 
import org.osmdroid.util.GeoPoint; 
import org.osmdroid.views.MapController; 
import org.osmdroid.views.MapView; 



import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.MotionEvent; 
import android.view.View; 
import android.widget.Button; 
import org.osmdroid.views.MapView; 


import com.gps.gpsclient.R; 




public class GPSClientActivity extends Activity { 

private MapView view; 
private MapDrawer mainDrawer; 
private QuickAction mQuickAction; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_gps); 
     view = (MapView) findViewById(R.id.mapView); 
     view.setTileSource(TileSourceFactory.MAPNIK); 
     view.setBuiltInZoomControls(true); 
     MapController mapController = view.getController(); 
     mapController.setZoom(10); 
     GeoPoint point2 = new GeoPoint(51496994, -134733); 
     mapController.setCenter(point2); 
     mainDrawer=new MapDrawer(view); 
     createFloatingMenu(); 
     final Button button = (Button) findViewById(R.id.addButton); 
     button.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View arg0, MotionEvent arg1) { 
       mQuickAction.show(view); 
       return false; 
      } 
     }); 

    } 

    public void createFloatingMenu() 
    { 
     ActionItem item=new ActionItem(); 
     item.setIcon(getResources().getDrawable(R.drawable.ic_launcher)); 
     item.setTitle("Custom"); 
     mQuickAction =new QuickAction(view.getContext()); 
     mQuickAction.addActionItem(item); 


    } 


} 

希望你能幫助

回答

3

清理並生成

如果那不幫助,然後重新啓動Eclipse和乾淨,並再次建立。

編輯:

你說:

。但當我有這個項目,我的項目的構建路徑,我得到一個 NoClassDefError。

看起來您的構建路徑中包含一些庫項目。您需要將此外部項目標記爲庫項目。爲此,在將項目導入工作區後,轉至您的主項目。右點擊並轉到屬性..並選擇左側的「Android」組。在右側窗格中,您會在極端底部找到一個庫面板。單擊添加並找到並添加其他項目並將其標記爲圖書館項目。

enter image description here

這樣做,乾淨的構建和做後我剛纔所說。 Refer this Q/A as well

如果這解決了您的問題,請將其標記爲答案。

+0

我試了一下,仍然是一樣的錯誤 – 2013-03-14 14:45:01

+0

再次看我的編輯 – Nezam 2013-03-15 04:41:45