2017-03-22 44 views
0

我有相同的代碼:NoClassDefFoundError的設備上

public static void clearCacheWithoutMainActivity() 
{ 
    try 
    { 
     viewModelForClass.entrySet().removeIf(e -> !e.getKey().equals(className)); 
    } 
    catch(NoClassDefFoundError e) 
    { 
     int k = 0; 
    } 
} 

private static Map<String, Pair<BaseObservable, Date>> viewModelForClass = new LinkedHashMap<>(); 

private static final String className = MainActivity.class.getName(); 

在仿真機器人。我不明白錯誤的NoClassDefFoundError。但在我的設備這個Android 5.1我抓住了這個錯誤。

compileSdkVersion 25 
    buildToolsVersion "25.0.2" 

    defaultConfig { 
     applicationId "ca.amikash.cashback" 
     minSdkVersion 16 
     targetSdkVersion 22 
     versionCode 1 
     versionName "1.0.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     multiDexEnabled true 
    } 

    dexOptions { 
     preDexLibraries = false 
     jumboMode = false 
     maxProcessCount 4 
     javaMaxHeapSize "6g" 
    } 
    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_8 
     targetCompatibility JavaVersion.VERSION_1_8 
    } 

我的build.gradle文件。這可能是錯誤的?

回答

1

這將是更有幫助的,你可以分享的錯誤日誌了。

編輯完清單文件設置機器人:在標籤名稱如下:

<application android:name="android.support.multidex.MultiDexApplication"> 

或者,如果你重寫應用程序類,將其更改爲延長MultiDexApplication

看看這個鏈接更多的信息:developer.android.com/studio/build/multidex.html

+0

java.lang.NoClassDefFoundError:ca.amikash.cashback.ViewModelProvider $$ LAMBDA $ 1只是這個錯誤。擴展MultiDexApplication - 沒有幫助我 –

+1

您是否正在使用具有ca.amikash.cashback.ViewModelProvider類的庫項目? –

+0

在類TheApplication擴展MultiDexApplication我使用ViewModelProvider.clearCacheWithoutMainActivity(); –

0
for(Iterator<Map.Entry<String, Pair<BaseObservable, Date>>> it = viewModelForClass.entrySet().iterator(); it.hasNext();) { 
      Map.Entry<String, Pair<BaseObservable, Date>> entry = it.next(); 
      if(!entry.getKey().equals(className)) { 
       it.remove(); 
      } 
     } 

相反

viewModelForClass.entrySet().removeIf(e -> !e.getKey().equals(className)); 

解決的問題。但仍然不明白爲什麼排除被排除。沒有lambdas的代碼並不漂亮,但是該怎麼做。

相關問題