开发者

Android Custom Widget Inflate 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 couldn't 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:576) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.widget.RemoteViews.apply(RemoteViews.java:930) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:219) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:250) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.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): at android.os.Looper.loop(Looper.java:123) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.app.ActivityThread.main(ActivityThread.java:4627) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at java.lang.reflect.Method.invokeNative(Native Method) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at java.lang.reflect.Method.invoke(Method.java:521) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at dalvik.system.NativeStart.main(Native Method) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): Caused by: java.lang.ClassNotFoundException: com.org.BatteryManager.BatteryView in loader dalvik.system.PathClassLoader[.] 02-17 18:49:49.392: WARN/AppWidgetHos开发者_如何学CtView(124): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at java.lang.ClassLoader.loadClass(ClassLoader.java:532) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.view.LayoutInflater.createView(LayoutInflater.java:466) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565) 02-17 18:49:49.392: WARN/AppWidgetHostView(124): ... 15 more


I had the same confusing problem. To fix it your custom view should provide a constructor with two arguments: Context and AttributeSet as adviced here.


What is com.org.BatteryManager.BatteryView?

If you want to use a custom view then it is possible. The way to do it is create a custom view class in Java that extends some base view component class.

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

The way that I made my custom gallery is to extends the basic Gallery class --

package com.testing.whatever;

public class CustomGallery extends Gallery {
    //CODE OVERRIDES HERE
}

Then in my XML code, the code looked similar to what you already have --

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

I suspect you're getting your error because you haven't coded com.org.BatteryManager.BatteryView or it's in the wrong place in your java files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜