在我的app
我正在建立一个定制的notification
与big view
约150dp
。
layout
如下
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imagenotileft"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imagenotileft" />
<View
android:id="@+id/view"
android:layout_width="365dp"
android:layout_height="@dimen/dp_2"
android:layout_marginTop="@dimen/dp_23"
android:layout_centerHorizontal="true"
android:layout_below="@+id/title"
android:background="@color/comunica_app_light_grey" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/view"
android:layout_toRightOf="@+id/imagenotileft" />
<ImageView
android:id="@+id/imagenotiright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="10dp" />
</RelativeLayout>
当调用创建View
函数时,app
组件导致notification
崩溃.code
部分没有任何问题,因为它没有View
组件完全膨胀。
错误期间的日志如下所示。
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1
12-21 10:27:36.504 1701-1701/? E/StatusBar: couldn't inflate view for notification edu.uoc.app.comunica.dev/0x0
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.view.View
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.view.View
Caused by: android.view.InflateException: Binary XML file line #0: Class not allowed to be inflated android.view.View
at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:683)
at android.view.LayoutInflater.createView(LayoutInflater.java:634)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:700)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
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.widget.RemoteViews.inflateView(RemoteViews.java:3198)
at android.widget.RemoteViews.apply(RemoteViews.java:3162)
at com.android.systemui.statusbar.BaseStatusBar.inflateViews(BaseStatusBar.java:1667)
at com.android.systemui.statusbar.BaseStatusBar.createNotificationViews(BaseStatusBar.java:2171)
at com.android.systemui.statusbar.phone.PhoneStatusBar.addNotification(PhoneStatusBar.java:1407)
at com.android.systemui.statusbar.BaseStatusBar$7$2.run(BaseStatusBar.java:634)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
12-21 10:27:36.528 29283-29283/edu.uoc.app.comunica.dev E/AndroidRuntime: FATAL EXCEPTION: main
Process: edu.uoc.app.comunica.dev, PID: 29283
android.app.RemoteServiceException: Bad notification posted from package edu.uoc.app.comunica.dev: Couldn't expand RemoteViews for: StatusBarNotification(pkg=edu.uoc.app.comunica.dev user=UserHandle{0} id=0 tag=null key=0|edu.uoc.app.comunica.dev|0|null|10115: Notification(pri=0 contentView=edu.uoc.app.comunica.dev/0x7f0c002a vibrate=null sound=null tick defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE))
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
我无法弄清楚从日志中导致这种情况的原因。
请提供解决方案。
您已为该视图添加了此ID
android:id="@+id/title"
并且以下id未分配给任何视图
@+id/send_date
这可能是个问题
您必须添加自定义视图所需的所有构造函数。如果你使用android studio找到Code-> Generate,然后是“constructor”,然后检查所有可用的构造函数,在下一个窗口中你必须取消选中所有类属性,然后IDE为你生成这个构造函数。
public class CustomView extends View {
public CustomView(Context context) {
super(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
public CustomView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
}