2

I am having a problem using RecyclerView and ParseQuery; the .get(i) in my MainActvity keeps giving me these errors:

Error:(102, 67) error: incompatible types: int cannot be converted to String

and:

non-static method 'get(java.lang.String)' cannot be referenced from a static context

and:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

I have done a lot of research and not much is out there about using the RecyclerView along with ParseQuery

This is my MainActivity:

import com.parse.FindCallback;
import com.parse.GetCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;


public class MainActivity extends AppCompatActivity implements WeatherServiceCallback {

    // Defining Variables
    private Toolbar toolbar;
    private NavigationView navigationView;
    private DrawerLayout drawerLayout;
    protected Button mButtonHeader;
    private TextView mDayOfTheWeek;
    private TextView mDate;
    // protected Context context;
    // private long pageId = 137317903012386L;
    // private List<Data> data;
    private RecyclerView mRecyclerView;

    // New Variables
    private CustomAdapter mAdapter;
    private Context context;

    // Weather variables
    private ImageView weatherIconImageView;
    private TextView temperatureTextView;
    private TextView conditionTextView;
    private TextView locationTextView;

    private YahooWeatherService service;
    private ProgressDialog dialog;

    final List<Information> data = new ArrayList<>();
    Information current = new Information();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initializing Toolbar and setting it as the actionbar
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new CustomAdapter(getApplicationContext(), data);

        //RecyclerView with Parse

        Parse.initialize(this, "9eLoLJ1NvoDiW8kv9VIWspFrukz5imtvASpxLRwV", "ThOQN59Uulim5YgFfYQ9LwH5NTX6bKahbbfjTcuv");

        ParseQuery<ParseObject> query = ParseQuery.getQuery("news");
        query.findInBackground( new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> objects, ParseException e) {
                if (e == null) {
                    for (int i = 0; i < objects.size(); i++) {
                        Information information = new Information();
                        information.mNewstTitle = ParseObject.get(i).getString("name");
                        information.mNewsStory = ParseObject.get(i).getString("shortinfo");
                        //information.partyCost = parseObject.getString("partyName");
                        //information.flyerPic = parseObject.getParseFile("partyFlyerImage");
                        //information.partyPromoterPic = parseObject.getParseFile("partyPromoterImage");
                        //information.mNewsPhotoIcon = R.drawable.newsitem));

                        data.add(information);
                    }
                } else {
                    // something went wrong
                }

                mRecyclerView.setAdapter(mAdapter);
            }
        });
    }
}

This is my Class with the data for my Adapter:

public class Information {
    String mNewstTitle;
    String mNewsStory;
    int mNewsPhotoIcon;

    /*
     * Information(String mNewstTitle, String mNewsStory, int mNewsPhotoIcon) {
     *     this.mNewstTitle = mNewstTitle; this.mNewsStory = mNewsStory;
     *     this.mNewsPhotoIcon = mNewsPhotoIcon; 
     * }
     */
}
Equivocal
  • 912
  • 2
  • 14
  • 27
  • Can you remove the Adapter code, and much of the headers in the Main activity? They take a lot of space, and do not help in clarifying your question. By doing so, your question has better chances of being upvoted and answered. – SwiftArchitect Sep 08 '15 at 02:24
  • See also [this](http://stackoverflow.com/questions/25517908/compilation-error-incompatible-types) for the first error and [this](http://stackoverflow.com/questions/4922145/non-static-method-cannot-be-referenced-from-a-static-context-error) for the second error – Dennis Meng Sep 08 '15 at 02:51
  • Oh okay thanks, i will edit it – Equivocal Sep 08 '15 at 02:58

1 Answers1

1

You are invoking the method statically:

ParseObject.get(i)...

From the documentation:

If you don't know what type of data you're getting out, you can call get(key), but then you probably have to cast it right away anyways. In most situations you should use the typed accessors like getString.

Correct:

<instance>.get()

Incorrect:

<class>.get()

SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
  • Thanks for the fast reply i had solved my own error and you are correct, i was mistakenly using the Class instead of an instance of the class. Thanks for your response nonetheless it is greatly appreciated – Equivocal Sep 08 '15 at 03:01
  • sorry about the + .. unfortunately according to the policies of stackoverflow i have to earn "15 reputation" before i can increase your score. So until then the √ is all i can do – Equivocal Sep 08 '15 at 03:21
  • for sure. Thanks again – Equivocal Sep 08 '15 at 03:31
  • Hey i have another issue if you could possibly help out it would be much appreciated? I haven't been able to solve this http://stackoverflow.com/questions/32594038/displaying-multiple-images-from-parse-com-using-recyclerview-is-only-displaying – Equivocal Sep 16 '15 at 00:34