java - 在通知中使用 ConstraintLayout 时崩溃

标签 java android android-notifications android-constraintlayout

当我在自定义 Notification 中使用 ConstraintLayout 时,我得到一个 InflationException。我可以在我的应用程序的其他地方使用它们,而不是在 Notification 的自定义布局中。我假设支持库中包含的任何小部件都不能在 RemoteView 中使用,但我找不到任何确认。有人知道吗?

E/StatusBar: couldn't inflate view for notification com.example.app/0x1
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[],nativeLibraryDirectories=[/system/priv-app/TeleService/lib/arm64, /system/fake-libs64, /system/priv-app/TeleService/TeleService.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.widget.RemoteViews.inflateView(RemoteViews.java:3278)
    at android.widget.RemoteViews.-wrap1(Unknown Source:0)
    at android.widget.RemoteViews$AsyncApplyTask.doInBackground(RemoteViews.java:3380)
    at android.widget.RemoteViews$AsyncApplyTask.doInBackground(RemoteViews.java:3376)
    at android.os.AsyncTask$2.call(AsyncTask.java:333)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:764)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.app, PID: 9732
android.app.RemoteServiceException: Bad notification posted from package com.example.app: Couldn't inflate contentViewsandroid.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1775)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

最佳答案

A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:

  • FrameLayout
  • LinearLayout
  • RelativeLayout
  • GridLayout

And the following widget classes:

  • AnalogClock
  • Button
  • Chronometer
  • ImageButton
  • ImageView
  • ProgressBar
  • TextView
  • ViewFlipper
  • ListView
  • GridView
  • StackView
  • AdapterViewFlipper

Descendants of these classes are not supported.

阅读更多: https://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout

关于java - 在通知中使用 ConstraintLayout 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45396426/

相关文章:

java - 可靠地跳过 java.io.InputStream 及其子类型中的数据

java - 如何使用RDBMS DML创建任意错误

android - 致命信号 11 (SIGSEGV) 位于 0x00000000(代码=1),线程 27830(ple.myfragexample)——仅适用于 Android 4.1.2

安卓画点

android - 在显示之前处理状态栏通知

通知点击的Android调用方法

android - android中通知按钮的Onclick监听器

java - Java中推荐使用ArrayList和HashMap?

java - 如何将列表转换为UpdatableRecord?

java - Android - 在库和应用程序之间创建接口(interface)