嗨,我试图在操作栏中添加一个动画视图,但是在Android2.3上出现了这个错误(在Android4上有效)

  1194         AndroidRuntime  E  FATAL EXCEPTION: main
  1194         AndroidRuntime  E  android.view.InflateException: Binary XML file line #3: Error inflating class <unknown>
  1194         AndroidRuntime  E    at android.view.LayoutInflater.createView(LayoutInflater.java:518)
  1194         AndroidRuntime  E    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
  1194         AndroidRuntime  E    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
  1194         AndroidRuntime  E    at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
  1194         AndroidRuntime  E    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
  1194         AndroidRuntime  E    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
  1194         AndroidRuntime  E    at it.patrick91.unisamenu.MainActivity.load(MainActivity.java:165)
  1194         AndroidRuntime  E    at it.patrick91.unisamenu.MainActivity.onOptionsItemSelected(MainActivity.java:219)
  1194         AndroidRuntime  E    at com.actionbarsherlock.app.SherlockListActivity.onMenuItemSelected(SherlockListActivity.java:208)
  1194         AndroidRuntime  E    at com.actionbarsherlock.ActionBarSherlock.callbackOptionsItemSelected(ActionBarSherlock.java:603)
  1194         AndroidRuntime  E    at com.actionbarsherlock.internal.ActionBarSherlockCompat.onMenuItemSelected(ActionBarSherlockCompat.java:529)
  1194         AndroidRuntime  E    at com.actionbarsherlock.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:738)
  1194         AndroidRuntime  E    at com.actionbarsherlock.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:148)
  1194         AndroidRuntime  E    at com.actionbarsherlock.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:879)
  1194         AndroidRuntime  E    at com.actionbarsherlock.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:510)
  1194         AndroidRuntime  E    at com.actionbarsherlock.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:145)
  1194         AndroidRuntime  E    at android.view.View.performClick(View.java:2485)
  1194         AndroidRuntime  E    at android.view.View$PerformClick.run(View.java:9080)
  1194         AndroidRuntime  E    at android.os.Handler.handleCallback(Handler.java:587)
  1194         AndroidRuntime  E    at android.os.Handler.dispatchMessage(Handler.java:92)
  1194         AndroidRuntime  E    at android.os.Looper.loop(Looper.java:130)
  1194         AndroidRuntime  E    at android.app.ActivityThread.main(ActivityThread.java:3687)
  1194         AndroidRuntime  E    at java.lang.reflect.Method.invokeNative(Native Method)
  1194         AndroidRuntime  E    at java.lang.reflect.Method.invoke(Method.java:507)
  1194         AndroidRuntime  E    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
  1194         AndroidRuntime  E    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
  1194         AndroidRuntime  E    at dalvik.system.NativeStart.main(Native Method)
  1194         AndroidRuntime  E  Caused by: java.lang.reflect.InvocationTargetException
  1194         AndroidRuntime  E    at java.lang.reflect.Constructor.constructNative(Native Method)
  1194         AndroidRuntime  E    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
  1194         AndroidRuntime  E    at android.view.LayoutInflater.createView(LayoutInflater.java:505)
  1194         AndroidRuntime  E    ... 26 more
  1194         AndroidRuntime  E  Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01000f a=3}
  1194         AndroidRuntime  E    at android.content.res.Resources.loadDrawable(Resources.java:1681)
  1194         AndroidRuntime  E    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
  1194         AndroidRuntime  E    at android.view.View.<init>(View.java:1951)
  1194         AndroidRuntime  E    at android.widget.ImageView.<init>(ImageView.java:112)
  1194         AndroidRuntime  E    at android.widget.ImageView.<init>(ImageView.java:108)
  1194         AndroidRuntime  E    ... 29 more

使图像膨胀的代码如下:
LayoutInflater inflater = (LayoutInflater) getApplication()
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ImageView iv = (ImageView) inflater.inflate(R.layout.load_action_view,
        null);
Animation rotation = AnimationUtils.loadAnimation(getApplication(),
        R.anim.load_anim);
rotation.setRepeatCount(Animation.INFINITE);
iv.startAnimation(rotation);

加载操作视图.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/Widget.Sherlock.ActionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_action_load" />

做一些测试我注意到删除style=@style/widget.sherlock.actionButton”可以解决这个问题。
清单中的应用程序标记如下:
<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Sherlock" >..</application>

你知道有什么问题吗?

最佳答案

修正了将getapplication()更改为this(它在一个活动中)

关于android - 使用Widget.Sherlock.ActionButton对ImageView进行充气时,资源不是Drawable,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13734716/

10-09 09:09