Отображение ошибки красного цвета .add() при добавлении данных в ArrayListJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Гость
 Отображение ошибки красного цвета .add() при добавлении данных в ArrayList

Сообщение Гость »


Когда я пытаюсь добавить данные в arraylist(

Код: Выделить всё

listModels
) in another class which is

Код: Выделить всё

FetchStockApi
it is showing red Error .add()(Cannot resolve symbol 'add'). But If I don't use

Код: Выделить всё

FetchStockApi
, and without taking it's instance, Add stuff in some ArrayList Created in MainActivity and use it for adapter it works and program works.
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);

FetchStockApi.java

Код: Выделить всё

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
}
I just want to add Data in FetchStockApi and later use it in MainActivity for Recycler View adapter.


Источник: https://stackoverflow.com/questions/781 ... -arraylist
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»