gpt4 book ai didi

android - 使用外部库组件时错误膨胀类

转载 作者:行者123 更新时间:2023-11-29 19:07:53 30 4
gpt4 key购买 nike

我创建了一个简单的小部件,它使用饼图/圆环图(圆形进度条)呈现相同的数据。我想使用一些外部组件,所以我选择了:

com.github.lzyzsd.circleprogress.ArcProgress

我将 ArcProgress 组件放置到我的 widget.xml 中,我可以在“预览”选项卡中清楚地看到它。没有编译、构建或任何其他错误。当我运行应用程序并将小部件放到主屏幕时,我遇到了一个异常:

W/AppWidgetHostView: updateAppWidget couldn't find any view, using error view
android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class com.github.lzyzsd.circleprogress.ArcProgress
Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class com.github.lzyzsd.circleprogress.ArcProgress
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.github.lzyzsd.circleprogress.ArcProgress" on path: DexPathList[[zip file "/data/app/com.sec.android.app.launcher-2/base.apk", zip file "/data/app/com.sec.android.app.launcher-2/base.apk"],nativeLibraryDirectories=[/data/app/com.sec.android.app.launcher-2/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:616)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:873)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.inflate(LayoutInflater.java:525)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.widget.RemoteViews.inflateView(RemoteViews.java:3844)
at android.widget.RemoteViews.apply(RemoteViews.java:3808)
at android.appwidget.AppWidgetHostView.applyRemoteViews(AppWidgetHostView.java:456)
at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:385)
at com.android.launcher3.home.LauncherAppWidgetHostView.updateAppWidget(LauncherAppWidgetHostView.java:161)
at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:418)
at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:136)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

我认为 gradle 存在一些问题,因为我的第一次尝试是:

az.plainpie.PieView

结果是一样的(当然 ClassNotFound 是“az.plainpie.PieView”)。

我的 widget.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin"
android:background="#AA000000">
<!--xmlns:plainpie="http://schemas.android.com/apk/res-auto"-->


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/countryView"
android:visibility="visible">

<!-- <az.plainpie.PieView
android:id="@+id/globalValue"
android:layout_width="100dp"
android:layout_height="100dp"
plainpie:inner_pie_padding="10"
plainpie:percentage="75"
plainpie:percentage_size="35"
plainpie:inner_text_visibility="true"/> -->

<com.github.lzyzsd.circleprogress.ArcProgress
android:id="@+id/arc_progress"
android:layout_width="100dp"
android:layout_height="100dp"
app:arc_bottom_text_size="10sp"
app:arc_progress="55"
app:arc_bottom_text="VALUE"/>

<TextView
android:id="@+id/countryText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="temp"
android:textSize="@dimen/text_size_big"
android:textStyle="bold"
android:textColor="@color/colorWhite"/>

</LinearLayout>
</LinearLayout>

项目等级:

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'me.tatarka:gradle-retrolambda:3.6.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

模块等级:

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId 'pl.test.simplewidget'
minSdkVersion 15
targetSdkVersion 25
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})

compile 'com.google.code.gson:gson:2.8.0'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.8.0'

compile group: 'joda-time', name: 'joda-time', version: '2.9.9'

compile 'com.github.zurche:plain-pie:v0.2.1' //pie chart library zurche/plain-pie
compile 'com.github.lzyzsd:circleprogress:1.2.1' // circle progress bar

compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}

我试过清理项目、卸载应用程序、使用不同的手机。我的 Android Studio 取消选中“离线工作”并选中推荐的“默认 gradle 包装器”。我搜索了解决方案,但没有一个解决了我的问题。你能看出哪里出了问题吗?

最佳答案

不幸的是,您不能像在the documentation 中那样在您的应用程序小部件中使用这些自定义 View 。说:

Creating the App Widget layout is simple if you're familiar with Layouts. However, you must be aware that App Widget layouts are basedon RemoteViews, which do not support every kind of layout or view widget.

Android: AppWidget with custom view not working 阅读相关问题

关于android - 使用外部库组件时错误膨胀类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46540210/

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