gpt4 book ai didi

java - 使用 XYPlot 时如何解决问题 'Binary XML file line #8: Binary XML file line #8: Error inflating class com.androidplot.xy.XYPlot'

转载 作者:行者123 更新时间:2023-12-01 18:38:26 26 4
gpt4 key购买 nike

我正在尝试使用 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。

ma​​in_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>

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

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) 

梯度:

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"
}

混淆器:

# 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.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这个观点接受。

上面列出的内容都没有写在那里,它们只是不存在。

关于java - 使用 XYPlot 时如何解决问题 'Binary XML file line #8: Binary XML file line #8: Error inflating class com.androidplot.xy.XYPlot',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59993903/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com