Link to home
Start Free TrialLog in
Avatar of Neha Ninave
Neha Ninave

asked on

Android ArrayList Issue

I have generated ArrayList from class like

coinArrayList=  ShowDash.getCoins();

Open in new window


and When I check the output of this Array I got
Log.d("coinArrayList", "" + String.valueOf(coinArrayList) );

Open in new window


I get an output like
D/coinArrayList: [{CoinName=COIN1, CoinBal=0.0, CoinPrice=8919.52}, {CoinName=COIN2, CoinBal=0.0, CoinPrice=101200.0}, {CoinName=COIN3, CoinBal=0.0, CoinPrice=112603.0}, {CoinName=COIN4, CoinBal=0.0, CoinPrice=226263.0}]

Open in new window


Now I need first value CoinName from this ArrayList so I wrote
Log.d("coinArrayList", "" + String.valueOf(coinArrayList.get(0).getCoinName()));

Open in new window

But here I always get null value.  Why?
Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

What objects do you have in your List? Is it an object you implemented yourself? If so, look closely at the implementation of the getCoinName() method, and make sure it's doing as you expect. (Maybe compare it to the toString() method, and see if they are both referencing the same CoinName field.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.