Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RefreshActionItem object in activity is null #7

Open
devilmac opened this issue Jun 8, 2013 · 13 comments
Open

RefreshActionItem object in activity is null #7

devilmac opened this issue Jun 8, 2013 · 13 comments

Comments

@devilmac
Copy link

devilmac commented Jun 8, 2013

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???

@intrications
Copy link
Contributor

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"

@devilmac
Copy link
Author

devilmac commented Jun 9, 2013

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
Copy link
Author

devilmac commented Jun 9, 2013

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.

@ManuelPeinado
Copy link
Owner

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

@ManuelPeinado
Copy link
Owner

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

@devilmac
Copy link
Author

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.

@alexandrepossebom
Copy link

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)

@intrications
Copy link
Contributor

@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?

@alexandrepossebom
Copy link

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

@ManuelPeinado
Copy link
Owner

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

@iturki
Copy link

iturki commented Jul 28, 2013

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!

@devilmac
Copy link
Author

devilmac commented Aug 3, 2013

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

@marckaraujo
Copy link

same problem here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants