如何摆脱问题'二进制XML文件第8行:二进制XML文件第8行:使用XYPlot时会膨胀类com.androidplot.xy.XYPlot类]

问题描述 投票:0回答:2

[我正在尝试使用android studio 3.5熟悉android XYplot。我首先测试了几个示例,但最终都出现了相同的错误-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然后应用崩溃。

我真的很感谢任何建议摆脱这个问题。谢谢!

我做了什么:下面显示了我尝试过的示例之一(this)的logcat输出。我用XYPlot库更新了Gradle,而且正如我在搜索时注意到的那样,我也想更新ProGuard。最后还提到了更新的ProGuard。

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>

主要活动

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输出:

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.**{*;}
java android xml androidplot
2个回答
0
投票
原因:java.lang.RuntimeException:com.halfhp.fig.FigException:解析键时出错:ticksPerDomainLabel值: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" /> 删除这些:

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

它应该起作用。

我从未见过XML属性上的点线属性,它应该是下划线(_)或什么都没有]]

这些是此视图接受的所有可能的Attributes

上面列出的任何一个都没有写在那里,只是不存在。


0
投票
© www.soinside.com 2019 - 2024. All rights reserved.