Android custom widget exception

XML

<?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/com.org.BatteryManager" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <com.org.BatteryManager.BatteryView android:layout_width="match_parent" android:layout_height="wrap_content" app:textColor="#ffffffff" /> </LinearLayout> 

Logcat

02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): updateAppWidget cannot find any view using error view 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): android.view.InflateException: Binary XML file line # 9: Error inflating class com.org.BatteryManager.BatteryView 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java∗76) 02- 17 18: 49: 49.392: WARN / AppWidgetHostView (124): on android.view.LayoutInflater.rInflate (LayoutInflater.java:618) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): on android.view. LayoutInflater.inflate (LayoutInflater.java:407) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): on android.view.LayoutInflater.inflate (LayoutInflater.javahaps20) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): on android.widget.RemoteViews.apply (RemoteViews.java:930) 02 -17 18: 49: 49.392: WARN / AppWidgetHostView (124): on android.appwidget.AppWidgetHostView.updateAppWidget (AppWidgetHostView.j 219) 02-17 18: 49: 49.392: WARN / AppWi dgetHostView (124): in android.appwidget .AppWidgetHost.updateAppWidgetView (AppWidgetHost.java:250) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): in android.appwidget.AppWidgetHost $ UpdateHessage.hand.Java: 73) 02-17 18: 49: 49.392 : WARN / AppWidgetHostView (124): at android.os.Handler.dispatchMessage (Handler.java:99) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): in android.os.Looper.loop (Looper. java: 123) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): in android.app.ActivityThread.main (ActivityThread.java:4627) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124) : in java.lang.reflect.Method.invokeNative (native method) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): in java.lang.reflect.Method.invoke (Method.javahaps21) 02- 17 18: 49: 49.392: WARN / AppWidgetHostView (124): on com.android.i nternal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:868) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): on com.android.internal.os.ZygoteInit.main (ZygoteInit.java:626 ) 02-17 18: 4 9: 49.392: WARN / AppWidgetHostView (124): at dalvik.system.NativeStart.main (native method) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): called: java. lang.ClassNotFoundException: com. org.BatteryManager.BatteryView in the bootloader dalvik.system.PathClassLoader [.] 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): in dalvik.system.PathClassLoader.findClass (PathClassLoader.java:243) 02-17 18 : 49: 49.392: WARN / AppWidgetHostView (124): in java.lang.ClassLoader.loadClass (ClassLoader.java=73) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): in java.lang.ClassLoader. loadClass (ClassLoader.javaPoint32) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): on android.view.LayoutInflater.createView (LayoutInflater.java:466) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): on android.view.LayoutInflater.createViewFromTag (LayoutInflater.java∗65) 02-17 18: 49: 49.392: WARN / AppWidgetHostView (124): ... 15 more

+7
source share
2 answers

I had the same confusing issue. To fix this, your custom view should contain a constructor with two arguments: Context and AttributeSet, as indicated here .

+6
source

What is com.org.BatteryManager.BatteryView?

If you want to use a custom view, this is possible. The way to do this is to create a custom view class in Java that extends the component class of the base view.

For example, I use custom Gallery components in many of my applications. The gallery class will only move one frame left or right across the screen, which is different from the default behavior.

The way I created my own gallery is an extension of the main gallery class -

 package com.testing.whatever; public class CustomGallery extends Gallery { //CODE OVERRIDES HERE } 

Then in my XML code, the code looked the same as you already have -

 <com.testing.whatever.CustomGallery android:layout_width="fill_parent" android:layout_height="fill_parent" /> 

I suspect you are getting your error because you did not encode com.org.BatteryManager.BatteryView or in the wrong place in your java files.

0
source

All Articles