3

您好我正在尝试向操作栏添加动画视图,但在 Android 2.3 上出现此错误(适用于 Android 4)

  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); 

load_action_view.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>

你知道什么问题吗?

4

1 回答 1

4

修复了将 getApplication() 更改为此(它在 Activity 中)

于 2012-12-06T00:55:12.240 回答