Equivocal
Equivocal

Reputation: 932

Getting two compilation errors when trying to use a RecyclerView with Parse.com's ParseQuery to pull data from database

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

Upvotes: 2

Views: 130

Answers (1)

SwiftArchitect
SwiftArchitect

Reputation: 48542

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()

Upvotes: 1

Related Questions