简体   繁体   中英

Error in Earthquake Report App

I am building an earthquake report app and getting this error. I searched all over Google + Stack OverFlow + udacity forums still didn't find the answer.

the error says String can't be converted into int .But I have used the exact code as mentioned in udacity.

[1]

The error says:

 getMagnitudeColor(int) in EarthquakeAdapter cannot be applied to (java.lang.String) 

Is it possibly because the JSON element that you are referencing has the number as a String datatype rather than an Integer? If so, you can fix it with the following:

int magnitudeColor = getMagnitudeColor(Integer.parseInt(currentEarthquake.getMagnitude());

The error I was getting was due to the return statement that I had placed above GradientDrawable. also,thanks Kevin Lee for parse method.Helped me :) and Dave Newton , please dont be rude while answering questions. I am very new to programming as well stack overflow site. This was my first question and i didnt think much of regulations on how should i post my Question. anyways, Ty to you. !!

Your getMagnitude() method returns a string. However, your getMagnitudeColor() method expects an integer for a parameter. You have to either change the return type of getMagnitude() or change the type of your parameter for getMagnitudeColor() so that they both match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM