安卓:java.lang.IllegalArgumentException:如果无效的有效载荷项目类型 [英] Android: java.lang.IllegalArgumentException: Invalid payload item type

查看:806
本文介绍了安卓:java.lang.IllegalArgumentException:如果无效的有效载荷项目类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:)一些用户告诉我除了GOT:

  java.lang.IllegalArgumentException:如果无效的有效载荷项目类型
在android.util.EventLog.writeEvent(本机方法)
在android.app.Activity.onMenuItemSelected(Activity.java:2452)
在com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:846)
在com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:153)
在com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:956)
在com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:534)
在com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
在android.view.View $ PerformClick.run(View.java:11934)
在android.os.Handler.handleCallback(Handler.java:587)
在android.os.Handler.dispatchMessage(Handler.java:92)
在android.os.Looper.loop(Looper.java:132)
在android.app.ActivityThread.main(ActivityThread.java:4123)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:491)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:841)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
在dalvik.system.NativeStart.main(本机方法)
 

但我不明白什么可以是错误的。有没有人有这个问题的一些想法?我试着重复异常,但我没能做到这一点。这里是code

  @覆盖
公共布尔onCreateOptionsMenu(功能菜单){
   MenuInflater充气= getMenuInflater();
   inflater.inflate(R.menu.app_menu,菜单);
   返回true;
}

@覆盖
公共布尔onOptionsItemSelected(菜单项项){
   开关(item.getItemId()){
   案例R.id.about:
      startActivity(新意图(这一点,AboutActivity.class));
      返回true;
   案例R.id.settings:
      startActivity(新意图(这一点,SettingsActivity.class));
      返回true;
   案例R.id.help:
      startActivity(新意图(这一点,AboutActivity.class));
      返回true;
   }

   返回true;
}
 

与app_menu XLM文件:

 < XML版本=1.0编码=UTF-8&GT?;
<菜单
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目机器人:ID =@ + ID /约
          机器人:图标=@机器人:可绘制/ ic_menu_info_details
          机器人:标题=@字符串/ about_menu_item/>
    <项目机器人:ID =@ + ID /设置
          机器人:图标=@机器人:可绘制/ ic_menu_ preferences
          机器人:标题=@字符串/ settings_menu_item/>
< /菜单>
 

解决方案

就像人说过,当的格式,因为在练习一个Android错误的菜单项标题,当它写入到系统事件日志出现错误。

<一个href="https://android-review.googlesource.com/#/c/47831/">https://android-review.googlesource.com/#/c/47831/

虽然我只看到它体现在LG到目前为止,好像它会在修复之前的任何版本的Andr​​oid发生。据我可以告诉从提交,它被标记在4.3中最早发行,但也许我读错了。

在活动的onMenuItemSelected,他们使用MenuItem.getTitleCondensed(),这将导致错误。我不使用冷凝标题的任何地方,而据我可以告诉大家,使用它在默认情况下并没有出台,直到V7支持库的意见,我们正在使用V4。

所以,我的变化是覆盖onMenuItemSelected在基类的活动,并设置简明标题为标题的字符串版本。这让格式化的标题显示(如使用自定义字体),然后使用普通字符串之一的事件日志:

  @覆盖
公众最终布尔onMenuItemSelected(INT FEATUREID,android.view.MenuItem项){
    //修复Android的标题格式错误
    如果(Build.VERSION.SDK_INT&LT; Build.VERSION_ codeS.JELLY_BEAN_MR2
            &功放;&安培; item.getTitleCondensed()!= NULL){
        item.setTitleCondensed(item.getTitleCondensed()的toString());
    }

    返回super.onMenuItemSelected(FEATUREID,项目);
}
 

也许你可能只是做它在4.1.2,或只是LG,但它不是很清楚,我为什么对其它版本并不明显。它看起来像臭虫可能会在其他地方发生。也许有人可以找出它推出的时候,但似乎没有像很多缺点不必要设置额外的字符串。

Hi everyone:) Some users tell me about the exception the got:

java.lang.IllegalArgumentException: Invalid payload item type
at android.util.EventLog.writeEvent(Native Method)
at android.app.Activity.onMenuItemSelected(Activity.java:2452)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:846)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:153)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:956)
at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:534)
at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
at android.view.View$PerformClick.run(View.java:11934)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)

But i cant understand what can be wrong. Does anyone have some ideas about the problem? I've tried to repeat that exception, but i failed to do this. Here is the code

@Override
public boolean onCreateOptionsMenu(Menu menu) {  
   MenuInflater inflater = getMenuInflater();
   inflater.inflate(R.menu.app_menu, menu);
   return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {  
   switch (item.getItemId()) {
   case R.id.about:
      startActivity(new Intent(this, AboutActivity.class));
      return true;
   case R.id.settings:
      startActivity(new Intent(this, SettingsActivity.class));
      return true;
   case R.id.help:
      startActivity(new Intent(this, AboutActivity.class));
      return true;
   }

   return true;
} 

with app_menu xlm file:

<?xml version="1.0" encoding="utf-8"?>
<menu
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/about"
          android:icon="@android:drawable/ic_menu_info_details"
          android:title="@string/about_menu_item"/>
    <item android:id="@+id/settings"
          android:icon="@android:drawable/ic_menu_preferences"
          android:title="@string/settings_menu_item"/>
</menu>

解决方案

Like people have said, the bug occurs when there's formatting in the MenuItem title, because of an Android bug in Activity when it writes to the system EventLog.

https://android-review.googlesource.com/#/c/47831/

Although I've only seen it manifest on LG so far, it seems like it will happen in any version of Android before the fix. As far as I can tell from that commit, the earliest release it was tagged in was 4.3, but maybe I'm reading it wrong.

In Activity's onMenuItemSelected, they use MenuItem.getTitleCondensed() which causes the error. I don't use the condensed title anywhere, and as far as I can tell the views that use it by default weren't introduced until v7 support library and we're using v4.

So, my change was to override onMenuItemSelected in a base Activity class and set the condensed title to be a string version of the title. This lets the formatted title be displayed (like with a custom font), and then use the plain string one for event log:

@Override
public final boolean onMenuItemSelected(int featureId, android.view.MenuItem item) {
    // fix android formatted title bug
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 
            && item.getTitleCondensed() != null) {
        item.setTitleCondensed(item.getTitleCondensed().toString());
    }

    return super.onMenuItemSelected(featureId, item);
}

Probably you could just do it in 4.1.2, or just for LG, but it's not clear to me why it hasn't manifest on other versions. It looks like the bug could happen elsewhere. Maybe someone can figure out when it was introduced, but there didn't seem like much downside to needlessly setting an extra string.

这篇关于安卓:java.lang.IllegalArgumentException:如果无效的有效载荷项目类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆