Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
HugoAvilaOliveira opened this issue Jun 5, 2021 · 1 comment
Open

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

HugoAvilaOliveira opened this issue Jun 5, 2021 · 1 comment

Comments

@HugoAvilaOliveira
Copy link

HugoAvilaOliveira commented Jun 5, 2021

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

<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
Copy link

I've the same error..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants