0

I'm trying to familiarize myself with android XYPlot, using android studio 3.5. I have tested several examples first, and I'm ending up with the same error - Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.androidplot.xy.XYPlot Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.androidplot.xy.XYPlot and then app crashes.

I would really appreciate any suggestion to get rid of this issue. Thank you!

What I did: Below shows logcat output of such one of the examples (this) I tried. I updated the Gradle with XYPlot library and also as I noticed when searching I wanted to update ProGuard too. Updated ProGuard is also mentioned at the end.

main_activity.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <com.androidplot.xy.XYPlot
        android:id="@+id/mySimpleXYPlot"
        androidplot.gridPadding="4dp|4dp|4dp|4dp"
        androidplot.ticksPerDomainLabel="2"
        androidplot.ticksPerRangeLabel="4"
        andsroidplot.title="A Simple XYPlot Example"
        android:layout_width="fill_parent"
        android:layout_height="527dp"
        android:layout_marginLeft="10px"
        android:layout_marginTop="10px"
        android:layout_marginRight="10px" />
</LinearLayout>

Main Activity

package com.example.plot_testmy2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYPlot;
import com.androidplot.xy.XYSeries;

import java.util.Arrays;

public class MainActivity extends AppCompatActivity {

    private XYPlot plot;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // initialize our XYPlot reference:
        plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

        // add a new series
        XYSeries mySeries = new SimpleXYSeries(
                Arrays.asList(0, 25, 55, 2, 80, 30, 99, 0, 44, 6),
                SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "series1");
        plot.addSeries(mySeries, new LineAndPointFormatter(
                getApplicationContext(), R.xml.f1));

        /*commented

        // reposition the domain label to look a little cleaner:
        plot.position(plot.getDomainLabelWidget(), // the widget to position
                45,                                // x position value, in this case 45 pixels
                XLayoutStyle.ABSOLUTE_FROM_LEFT,   // how the x position value is applied, in this case from the left
                0,                                 // y position value
                YLayoutStyle.ABSOLUTE_FROM_BOTTOM, // how the y position is applied, in this case from the bottom
                AnchorPosition.LEFT_BOTTOM);       // point to use as the origin of the widget being positioned

         */

        plot.centerOnRangeOrigin(60);
        plot.centerOnDomainOrigin(5);
    }
}

Logcat output :

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.plot_testmy2, PID: 29804
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.plot_testmy2/com.example.plot_testmy2.MainActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.androidplot.xy.XYPlot
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.androidplot.xy.XYPlot
     Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.androidplot.xy.XYPlot
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at android.view.LayoutInflater.createView(LayoutInflater.java:645)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.example.plot_testmy2.MainActivity.onCreate(MainActivity.java:22)
        at android.app.Activity.performCreate(Activity.java:6679)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: java.lang.RuntimeException: com.halfhp.fig.FigException: Error while parsing key: ticksPerDomainLabel value: 2
        at com.androidplot.Plot.loadAttrs(Plot.java:563)
        at com.androidplot.Plot.init(Plot.java:403)
        at com.androidplot.Plot.<init>(Plot.java:324)
        at com.androidplot.xy.XYPlot.<init>(XYPlot.java:143)
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) 
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) 
        at com.example.plot_testmy2.MainActivity.onCreate(MainActivity.java:22) 
        at android.app.Activity.performCreate(Activity.java:6679) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6119) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
     Caused by: com.halfhp.fig.FigException: Error while parsing key: ticksPerDomainLabel value: 2
        at com.halfhp.fig.Fig.configure(Fig.java:300)
        at com.halfhp.fig.Fig.configure(Fig.java:208)
        at com.androidplot.Plot.loadAttrs(Plot.java:561)
        at com.androidplot.Plot.init(Plot.java:403) 
        at com.androidplot.Plot.<init>(Plot.java:324) 
        at com.androidplot.xy.XYPlot.<init>(XYPlot.java:143) 
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) 
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) 
        at com.example.plot_testmy2.MainActivity.onCreate(MainActivity.java:22) 
        at android.app.Activity.performCreate(Activity.java:6679) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6119) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
     Caused by: java.lang.NoSuchMethodException: No such public method (case insensitive): setticksPerDomainLabel in class com.androidplot.xy.XYPlot
        at com.halfhp.fig.Fig.getMethodByName(Fig.java:110)
        at com.halfhp.fig.Fig.getSetter(Fig.java:116)
        at com.halfhp.fig.Fig.configure(Fig.java:274)
        at com.halfhp.fig.Fig.configure(Fig.java:208) 
        at com.androidplot.Plot.loadAttrs(Plot.java:561) 
        at com.androidplot.Plot.init(Plot.java:403) 
        at com.androidplot.Plot.<init>(Plot.java:324) 
        at com.androidplot.xy.XYPlot.<init>(XYPlot.java:143) 
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) 
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) 
        at com.example.plot_testmy2.MainActivity.onCreate(MainActivity.java:22) 
        at android.app.Activity.performCreate(Activity.java:6679) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6119) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

gradle :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.plot_testmy2"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation "com.androidplot:androidplot-core:1.5.7"
}

ProGuard :

# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class com.androidplot.**{*;}

2 Answers 2

0

Caused by: java.lang.RuntimeException: com.halfhp.fig.FigException: Error while parsing key: ticksPerDomainLabel value: 2

 <com.androidplot.xy.XYPlot
        android:id="@+id/mySimpleXYPlot"
        androidplot.gridPadding="4dp|4dp|4dp|4dp"
        androidplot.ticksPerDomainLabel="2" <--- this line is causing the problem
        androidplot.ticksPerRangeLabel="4"
        andsroidplot.title="A Simple XYPlot Example"
        android:layout_width="fill_parent"
        android:layout_height="527dp"
        android:layout_marginLeft="10px"
        android:layout_marginTop="10px"
        android:layout_marginRight="10px" />

remove these:

    androidplot.gridPadding="4dp|4dp|4dp|4dp"
    androidplot.ticksPerDomainLabel="2" <--- this line is causing the problem
    androidplot.ticksPerRangeLabel="4"
    andsroidplot.title="A Simple XYPlot Example"

And it should work.

I've never seen dotted properties on XML attributes, it should either be underscore(_) or nothing at all

These are all the possible Attributes this view accepts.

None of the ones listed above are written there, they just don't exist.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, now it works... :) I just removed the mentioned 4 lines in my xml and then executed the app. Thanks a lot again for sharing the useful resource too.
0

the class references R.layout.activity_main while the XML is named main_activity.xml is this correct?

plus there are no andsroidplot.*** attributes, please use ap: instead example

ap:title="A Simple XY Plot"

and don't forget to add

xmlns:ap="http://schemas.android.com/apk/res-auto"

to the root tag of your layout (android studio will do it for you with yellow/red pop-up)

and finally please refer to this page for more info regarding the dependency

https://github.com/halfhp/androidplot/blob/master/docs/quickstart.md

Good Luck

1 Comment

Thank you for the suggestion, I just tried by removing the above mentioned (accepted answer) 4 lines from my xml and then it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.