java.lang.NoClassDefFoundError: org.achartengine.m

2019-07-25 16:13发布

问题:

I am trying to create a Dial Chart using AChartLibrary(I am completely lost..I have no idea how to do it and I am trying my hand in it but to no avail so any tutorial that might help is welcomed).

I have managed to implement the Chart as follows

import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.View;
import android.view.LayoutInflater;
import android.widget.GridLayout;
import android.widget.LinearLayout;
import org.achartengine.GraphicalView;
import org.achartengine.model.CategorySeries;
import org.achartengine.ChartFactory;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.DialRenderer;
import org.achartengine.renderer.DialRenderer.Type;
import org.achartengine.renderer.SimpleSeriesRenderer;

public class Fragment_Statistics extends Fragment {
    private GraphicalView mChartView;
    public double MAX=180.00,MIN=0.00;
    public View onCreateView(LayoutInflater layoutInflater,ViewGroup container,Bundle SavedInstances){
        View statistics_fragment=getActivity().getLayoutInflater().inflate(R.layout.fragment_statistics, null);
        /** Colors to be used for the pie slices. */
        int[] COLORS = new int[] { Color.GREEN, Color.BLUE, Color.MAGENTA, Color.CYAN };
        /** The main series that will include all the data. */
        CategorySeries mSeries = new CategorySeries("Dial Chart");
        mSeries.add(MAX);
        /** The main renderer for the main dataset. */
        DialRenderer mRenderer = new DialRenderer();
        mRenderer.setAngleMin(MIN);
        mRenderer.setAngleMax(MAX);
        mRenderer.setMaxValue(MAX);
        mChartView=ChartFactory.getDialChartView(getActivity(),mSeries,mRenderer);
        return statistics_fragment;
    }

Whenever I execute it I get the following error

 java.lang.NoClassDefFoundError: org.achartengine.model.CategorySeries
            at com.spintum.preexam.Fragment_Statistics.onCreateView(Fragment_Statistics.java:30)
            at android.app.Fragment.performCreateView(Fragment.java:1700)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
            at android.app.BackStackRecord.run(BackStackRecord.java:698)
            at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
            at android.app.Activity.performStart(Activity.java:5273)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:110)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5292)
            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:824)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
            at dalvik.system.NativeStart.main(Native Method)

The error points to CategorySeries line and as you can see I have imported the necessary files but still it is showing an error.

This question also deals with a similar situation but the solution is provided for eclipse not for android studio. The answers in the aforementioned posts seem to suggest that the problem lies in the gradle file but my file seems to be correct

GRADLE:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
    compileSdkVersion 22
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.spintum.preexam"
        minSdkVersion 19
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral()
}
dependencies {
//    compile fileTree (dir:'libs',include:'achartengine-*.jar')
    //compile fileTree('libs/achartengine-1.1.0.jar')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:percent:22.2.0'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.google.android.gms:play-services-auth:8.3.0'
    compile 'com.google.android.gms:play-services-identity:8.3.0'
    compile 'com.google.android.gms:play-services-plus:8.3.0'
    compile 'com.google.android.gms:play-services-location:8.3.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.github.markushi:circlebutton:1.1'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32@aar'
}

What is causing this error and how can I rectify it? Any and all help is appreciated..