简体   繁体   中英

Error calling function from another fragment Java

I have an app for Android and I need to call a specific function to update my GridAdapter of the gallery that I made

my update function that I want to call it in other classes is this one

GrideAdapter.class

public void updateGride(){
}

the code works right of the update function but everytime I call that function from another class it gives me an error and app stop working this is how I do call the function from the other class

GridAdapter ab;
ab.updateGride();

what I do wrong? why I can't use the updateGride function in other fragment classes?

Its already been answered in the comments.

You need to initialize an object before using any of its members (non-static). This is basics of oop, its not specific to android or java. This is what you need,

    GridAdapter ab = new GridAdapter(/*arguments*/);
    ab.updateGride();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM