jjoe64 / GraphView

Android Graph Library for creating zoomable and scrollable line and bar graphs.
https://github.com/jjoe64/GraphView/wiki
Other
2.76k stars 811 forks source link

Error inflating class com.jjoe64.graphview.GraphView #676

Open HugoAvilaOliveira opened 3 years ago

HugoAvilaOliveira commented 3 years ago

I compiled this code, it's OK, but in my phone doesnt work.

The code

import androidx.appcompat.app.AppCompatActivity; import java.util.Random;

import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.widget.LinearLayout;

import com.jjoe64.graphview.series.*; import com.jjoe64.graphview.GraphView; import com.jjoe64.graphview.Viewport; import com.jjoe64.graphview.series.DataPoint; import com.jjoe64.graphview.series.LineGraphSeries;

public class Grafico extends Activity { private static final Random RANDOM = new Random(); private LineGraphSeries series; private int lastX = 0;

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

    // we get graph view instance
    GraphView graph = (GraphView) findViewById(R.id.graph);
    // data
    series = new LineGraphSeries<DataPoint>();
    graph.addSeries(series);
    // customize a little bit viewport
    Viewport viewport = graph.getViewport();
    viewport.setYAxisBoundsManual(true);
    viewport.setMinY(0);
    viewport.setMaxY(10);
    viewport.setScrollable(true);

}

@Override
protected void onResume() {
    super.onResume();
    // we're going to simulate real time with thread that append data to the graph
    new Thread(new Runnable() {

        @Override
        public void run() {
            // we add 100 new entries
            for (int i = 0; i < 100; i++) {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        addEntry();
                    }
                });

                // sleep to slow down the add of entries
                try {
                    Thread.sleep(600);
                } catch (InterruptedException e) {
                    // manage error ...
                }
            }
        }
    }).start();
}

// add random data to graph
private void addEntry() {
    // here, we choose to display max 10 points on the viewport and we scroll to end
    series.appendData(new DataPoint(lastX++, RANDOM.nextDouble() * 10d), true, 10);
}

}

DEBUG

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.appmodbus, PID: 4982 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.appmodbus/com.example.appmodbus.Grafico}: android.view.InflateException: Binary XML file line #16 in com.example.appmodbus:layout/activity_grafico: Binary XML file line #16 in com.example.appmodbus:layout/activity_grafico: Error inflating class com.jjoe64.graphview.GraphView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3311) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3460) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2047) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:224) at android.app.ActivityThread.main(ActivityThread.java:7590) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) Caused by: android.view.InflateException: Binary XML file line #16 in com.example.appmodbus:layout/activity_grafico: Binary XML file line #16 in com.example.appmodbus:layout/activity_grafico: Error inflating class com.jjoe64.graphview.GraphView Caused by: android.view.InflateException: Binary XML file line #16 in com.example.appmodbus:layout/activity_grafico: Error inflating class com.jjoe64.graphview.GraphView Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at android.view.LayoutInflater.createView(LayoutInflater.java:858) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1010) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088) at android.view.LayoutInflater.inflate(LayoutInflater.java:686) at android.view.LayoutInflater.inflate(LayoutInflater.java:538) at android.view.LayoutInflater.inflate(LayoutInflater.java:481) at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:442) at android.app.Activity.setContentView(Activity.java:3390) at com.example.appmodbus.Grafico.onCreate(Grafico.java:28) at android.app.Activity.performCreate(Activity.java:7893) at android.app.Activity.performCreate(Activity.java:7880) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3286) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3460) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2047) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:224) at android.app.ActivityThread.main(ActivityThread.java:7590) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/widget/EdgeEffectCompat; at com.jjoe64.graphview.Viewport.(Viewport.java:579) at com.jjoe64.graphview.GraphView.init(GraphView.java:205) at com.jjoe64.graphview.GraphView.(GraphView.java:178) E/AndroidRuntime: ... 28 more Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.widget.EdgeEffectCompat" on path: DexPathList[[zip file "/data/app/com.example.appmodbus-YQnQSahL5phEHLpuFP2AOw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.appmodbus-YQnQSahL5phEHLpuFP2AOw==/lib/arm64, /system/lib64, /system/product/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:230) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 31 more XML

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Grafico">

<com.jjoe64.graphview.GraphView
    android:id="@+id/graph"
    android:layout_width="278dp"
    android:layout_height="205dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

antoninhrlt commented 3 years ago

I've the same error..