Когда я пытаюсь добавить данные в arraylist(
Код: Выделить всё
listModels
Код: Выделить всё
FetchStockApi
Код: Выделить всё
FetchStockApi
MainActivity.java
Код: Выделить всё
public class MainActivity extends AppCompatActivity {
EditText suggestSearch;
RecyclerView suggestionList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
suggestSearch = findViewById(R.id.searchBar);
suggestionList = findViewById(R.id.suggestionList);
// FetchStockApi Class
FetchStockApi fetchStockApi = new FetchStockApi();
// Adapter
suggestListAdapter adapter = new suggestListAdapter();
adapter.setStringArrayList(fetchStockApi.listModels);
suggestionList.setLayoutManager(new LinearLayoutManager(this));
suggestionList.setAdapter(adapter);
Код: Выделить всё
package com.example.stockapipractice2;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
public class FetchStockApi {
ArrayList listModels = new ArrayList();
String stockName = "Nifty 50";
String stockSymbol = "NFTY";
String exchange = "NSI";
String type = "Index";
suggestListModel SuggestListModel = new suggestListModel(stockName, stockSymbol,exchange,type);
listModels.add(SuggestListModel);
// This above add is showing the Error
}
Источник: https://stackoverflow.com/questions/781 ... -arraylist