'Error when trying to use a PieChart (hellocharts) on an Activity
I'm trying to use the external library "hellocharts" in my project. I have linked the library to my project already, but when the activity that has the chart starts, the whole app crash with the exception: "Error inflating class lecho.lib.hellocharts.view.PieChartView".
I don't know what the problem can be. The java class (when I use the Charts) don't seem to have that problem (it doesn't get compile errors of not finding the library).
Here it is the .xml file of the activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical">
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="80dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<Button
android:id="@+id/Dia"
style="@android:style/Widget.Button"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="8dp"
android:text="Dia" />
<Button
android:id="@+id/Semana"
style="@android:style/Widget.Button"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="Semana" />
<Button
android:id="@+id/Mes"
style="@android:style/Widget.Button"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="Mes" />
<Button
android:id="@+id/Temporizador"
style="@android:style/Widget.Button"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="Temp" />
<Button
android:id="@+id/Estadisticas"
style="@android:style/Widget.Button"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="Stats" />
<Button
android:id="@+id/Tienda"
style="@android:style/Widget.Button"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="Tienda" />
</LinearLayout>
</HorizontalScrollView>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<lecho.lib.hellocharts.view.PieChartView
android:id="@+id/graphic_pie_chart"
android:layout_width="match_parent"
android:layout_height="500dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.826" />
<TextView
android:id="@+id/tv_asignatura"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28sp"
android:textStyle="bold"
android:layout_gravity="center"
app:layout_constraintBottom_toTopOf="@+id/graphic_pie_chart"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/graphic_pie_chart"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.3" />
<TextView
android:id="@+id/tv_tiempo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_gravity="center"
app:layout_constraintBottom_toTopOf="@+id/graphic_pie_chart"
app:layout_constraintEnd_toEndOf="@+id/tv_asignatura"
app:layout_constraintStart_toStartOf="@+id/tv_asignatura"
app:layout_constraintTop_toBottomOf="@+id/tv_asignatura"
app:layout_constraintVertical_bias="0.45" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
And here it is the gradle files
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 31
defaultConfig {
applicationId "es.ucm"
minSdkVersion 26
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter()// Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Solution 1:[1]
This issue is already discussed in the same github library page. Seems like they haven't found a solution yet.
However, you can use other libraries to get pie chart.
Here is a sample code
Referred from this page
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Peer Mohamed |