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