RefreshActionItem icon indicating copy to clipboard operation
RefreshActionItem copied to clipboard

RefreshActionItem object in activity is null

Open devilmac opened this issue 11 years ago • 13 comments

Hi Manuel Peinado,

I'm trying to use this library, I followed your instructions to add this library in my project but I'm experiencing an error in onCreateOptionsMenu method. This is the body of my onCreateOptionsMenu method:

    getSupportMenuInflater().inflate(R.menu.activity_home, menu);

MenuItem item = menu.findItem(R.id.refresh_menu);

if (item != null) {
    mRefreshActionItem = (RefreshActionItem) item.getActionView();
    mRefreshActionItem.setMenuItem(item);
    mRefreshActionItem.setMax(100);
    mRefreshActionItem.setRefreshActionListener(this);
    loadData();
}

//  return super.onCreateOptionsMenu(menu);
return true;

and I get the NullPointerException in the following line:

mRefreshActionItem.setMenuItem(item);.

As you can see, only the mRefreshActionItem object can be null. My question is: why do I get this exception???

devilmac avatar Jun 08 '13 11:06 devilmac

Can you post your menu xml, i.e. activity_home.xml?

Are you setting the actionViewClass in the menu xml?

android:actionViewClass="com.manuelpeinado.refreshactionitem.RefreshActionItem"

intrications avatar Jun 08 '13 12:06 intrications

This is my activity_home.xml menu

    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
        <item
           android:id="@+id/add_menu"
           android:icon="@drawable/button_add"
           android:showAsAction="ifRoom"
           android:title="@string/add_menu"/>
        <item
           android:id="@+id/refresh_menu"
           android:actionViewClass="com.manuelpeinado.refreshactionitem.RefreshActionItem"
           android:showAsAction="always"
           android:title="@string/refresh_menu"/>
   </menu>

devilmac avatar Jun 09 '13 07:06 devilmac

There is one more thing: I've tried my application on both API Level 10 and API Level 17 of Android, and it has worked fine on only API Level 10, on API Level 17 it has thrown the exception mentioned above.

devilmac avatar Jun 09 '13 08:06 devilmac

How weird. I'll see if I can look into it tomorrow. Thanks for reporting.

ManuelPeinado avatar Jun 09 '13 10:06 ManuelPeinado

Sorry but I can't seem to reproduce your problem.

ManuelPeinado avatar Jun 10 '13 18:06 ManuelPeinado

For Android API Level 17 I use the Android emulator, maybe this is the reason of my problem. I will try my app on a device soon and I will tell you the results.

devilmac avatar Jun 11 '13 08:06 devilmac

I Have same issue here !

E/AndroidRuntime(19851): java.lang.NullPointerException E/AndroidRuntime(19851): at com.possebom.json.MainActivity.onCreateOptionsMenu(MainActivity.java:27) E/AndroidRuntime(19851): at com.actionbarsherlock.app.SherlockActivity.onCreatePanelMenu(SherlockActivity.java:184) E/AndroidRuntime(19851): at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:559)

alexandrepossebom avatar Jun 13 '13 19:06 alexandrepossebom

@coxande I was able to reproduce your logcat error by deliberately misspelling:

com.manuelpeinado.refreshactionitem.RefreshActionItem

in the menu xml. Have you checked you have this line exactly:

android:actionViewClass="com.manuelpeinado.refreshactionitem.RefreshActionItem"

? It might not be this but it is best to check.

Have you tested your code on different versions of Android like devilmac?

intrications avatar Jun 13 '13 20:06 intrications

I have found de problem !

E/AndroidRuntime( 1900): android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01000f a=2}
E/AndroidRuntime( 1900):    at android.content.res.Resources.loadDrawable(Resources.java:1927)
E/AndroidRuntime( 1900):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime( 1900):    at com.manuelpeinado.refreshactionitem.RefreshActionItem.(RefreshActionItem.java:121)

Just edit file : com.manuelpeinado.refreshactionitem.RefreshActionItem and comment these two lines:

              case R.styleable.RefreshActionItem_refreshActionItemBackground:
//                Drawable drawable = a.getDrawable(attr);
//                mRefreshButton.setBackgroundDrawable(drawable);
                  break;

To get error in logcat I gave made this change in code :

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getSupportMenuInflater().inflate(R.menu.main, menu);
        MenuItem item = menu.findItem(R.id.refresh_button);
//        mRefreshActionItem = (RefreshActionItem)item.getActionView();
        mRefreshActionItem = new RefreshActionItem(getApplicationContext());
        item.setActionView(mRefreshActionItem);
        mRefreshActionItem.setMenuItem(item);
        mRefreshActionItem.setProgressIndicatorType(ProgressIndicatorType.INDETERMINATE);
        mRefreshActionItem.setRefreshActionListener(this);
        return true;
    }

alexandrepossebom avatar Jun 14 '13 11:06 alexandrepossebom

@coxande Thanks for helping out. It's not entirely clear to me, though, whether there is something I can change in the library to make your life easier with regard to this issue. If there is, please let me know.

ManuelPeinado avatar Jun 15 '13 05:06 ManuelPeinado

I had the same exact error as @coxande in a Galaxy Nexus running 4.2.2. My ABS is v4.3.1. May be it has something to do with the error. Anyway, his work-around is working fine for me. Thanks for sharing!

iturki avatar Jul 28 '13 06:07 iturki

Hi Manuel Peinado,

finally I got the same error (see start issue) on a device with Android 4.3. I hope you fix this problem soon.

error in android 4 3 error in android 4 3 - code error in android 4 3 - stack trace

devilmac avatar Aug 03 '13 20:08 devilmac

same problem here

marckaraujo avatar Mar 05 '14 19:03 marckaraujo