首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >com.example.binarystore.project1.vendor_details.Vendor_Details$1 :java.lang.NoClassDefFoundError

com.example.binarystore.project1.vendor_details.Vendor_Details$1 :java.lang.NoClassDefFoundError
EN

Stack Overflow用户
提问于 2017-05-03 18:45:11
回答 2查看 49关注 0票数 0

我的代码在Android工作室的android模拟器中执行和工作得很好,但在我的智能手机上不能工作,我的智能手机连接到我的PC上,USB调试功能已经启用。我得到了这个异常。

模块:应用

代码语言:javascript
复制
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "com.example.binarystore.project1"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:design:25.3.0'
compile 'com.android.support:cardview-v7:25.3.0'
compile 'com.android.support:recyclerview-v7:25.3.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.firebase:firebase-ads:9.0.1'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.google.android.gms:play-services:10.2.1'
compile 'com.google.android.gms:play-services-maps:10.2.1'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.google.code.gson:gson:2.2.4'



testCompile 'junit:junit:4.12'
compile project(':customfont')
}

错误:

代码语言:javascript
复制
 05-03 16:05:05.480 26599-26599/? E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: com.example.binarystore.project1, PID: 26599
                                               java.lang.NoClassDefFoundError: com.example.binarystore.project1.vendor_details.Vendor_Details$1
                                                   at com.example.binarystore.project1.vendor_details.Vendor_Details.addActionListner(Vendor_Details.java:71)``
                                                   at com.example.binarystore.project1.vendor_details.Vendor_Details.onCreate(Vendor_Details.java:46)
                                                   at android.app.Activity.performCreate(Activity.java:5343)
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
                                                   at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
                                                   at android.os.Handler.dispatchMessage(Handler.java:110)
                                                   at android.os.Looper.loop(Looper.java:193)
                                                   at android.app.ActivityThread.main(ActivityThread.java:5333)
                                                   at java.lang.reflect.Method.invokeNative(Native Method)
                                                   at java.lang.reflect.Method.invoke(Method.java:515)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
                                                   at dalvik.system.NativeStart.main(Native Method)

代码:

代码语言:javascript
复制
public class Vendor_Details extends AppCompatActivity implements OnMapReadyCallback {

private static final String TAG = MapsActivity.class.getSimpleName();
CustomSwipeAdaptor adaptor;
ViewPager vp;
LinearLayout next, cook1, restaurant1, laundry1, room_deliver1, gym1, cook2, restaurant2, laundry2, room_deliver2, innerLay;
HorizontalScrollView hsv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.vendor_details_page);

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map_view);
    mapFragment.getMapAsync(this);

    addImageViewpagerListner();
    addActionListner();`Error showing in this line and `
}

private void addImageViewpagerListner() {
    vp = (ViewPager) findViewById(R.id.view_pager);
    adaptor = new CustomSwipeAdaptor(this);
    vp.setAdapter(adaptor);
}

@TargetApi(Build.VERSION_CODES.M)
private void addActionListner() {
    next = (LinearLayout) findViewById(R.id.next);
    innerLay = (LinearLayout) findViewById(R.id.innerLay);
    cook1 = (LinearLayout) findViewById(R.id.cook1);
    restaurant1 = (LinearLayout) findViewById(R.id.restaurant1);
    laundry1 = (LinearLayout) findViewById(R.id.laundry1);
    room_deliver1 = (LinearLayout) findViewById(R.id.room_deliver1);
    gym1 = (LinearLayout) findViewById(R.id.gym1);
    cook2 = (LinearLayout) findViewById(R.id.cook2);
    restaurant2 = (LinearLayout) findViewById(R.id.restaurant2);
    laundry2 = (LinearLayout) findViewById(R.id.laundry2);
    room_deliver2 = (LinearLayout) findViewById(R.id.room_deliver2);

    hsv = (HorizontalScrollView) findViewById(R.id.hs_view);

    hsv.setOnScrollChangeListener(new View.OnScrollChangeListener() {`Error showing this line`
        @Override
        public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            View view = (View) hsv.getChildAt(hsv.getChildCount() - 1);
            int diff = (view.getRight() - (hsv.getWidth() + hsv.getScrollX()));
            if (diff <= 0) {
                next.setVisibility(View.INVISIBLE);
            } else {
                next.setVisibility(View.VISIBLE);
            }
        }
    });

}
@Override
public void onMapReady(GoogleMap googleMap) {
    try {
        // Customise the styling of the base map using a JSON object defined
        // in a raw resource file.
        boolean success = googleMap.setMapStyle(
                MapStyleOptions.loadRawResourceStyle(
                        this, R.raw.map_style_night));
        if (!success) {
            Log.e(TAG, "Style parsing failed.");
        }
    } catch (Resources.NotFoundException e) {
        Log.e(TAG, "Can't find style. Error: ", e);
    }
    LatLng ind = new LatLng(20, 78);
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(ind));
}

}

EN

回答 2

Stack Overflow用户

发布于 2017-05-03 19:17:26

第一个变体

您的问题是由错误使用multidex引起的。所以你的应用会在21+接口下正常工作,并且会导致低接口下的NoClassDefFoundError

您的build.gradle文件中包含以下内容

代码语言:javascript
复制
defaultConfig {
applicationId "com.example.binarystore.project1"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}

您知道,multiDexEnabled true选项仅适用于21+接口,对于较旧的API,您需要在依赖项中包含此行compile 'com.android.support:multidex:1.0.1'。并将此代码添加到您的应用程序代码中

代码语言:javascript
复制
@Override
protected void attachBaseContext(Context base) {
 super.attachBaseContext(base);
 MultiDex.install(this);
}

有关使用multidex的详细信息,请查看here

第二个变种

您正在调用使用@TargetApi(..M)注释在手机上声明的方法,该方法与版本要求不匹配。将版本检查添加到代码中,然后调用另一个方法,或者不调用任何方法。看一下这一行,当你想在19. Method refference上使用它时,你会发现错误,你可以找到只在23api中引入的"setOnScrollChangeListener“方法。

我建议你不要使用compile 'com.google.android.gms:play-services:....',因为它会将所有的播放服务添加到你的项目中,并显著增加你的代码库和应用程序的大小。试着只添加你正在使用的模块。有关详细信息,请阅读this文章

票数 0
EN

Stack Overflow用户

发布于 2017-05-03 19:42:00

在依赖项中使用compile 'com.android.support:multidex:1.0.1'

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43757831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档