[英]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.
我在Google + Stack OverFlow + udacity论坛上进行了搜索,但仍然找不到答案。
the error says String can't be converted into int .But I have used the exact code as mentioned in udacity. 错误提示String无法转换为int。但是我使用了udacity中提到的确切代码。
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? 是否可能是因为您所引用的JSON元素具有作为String数据类型而不是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. 我收到的错误是由于我将返回语句放在GradientDrawable上方。 also,thanks Kevin Lee for parse method.Helped me :) and Dave Newton , please dont be rude while answering questions.
同样,感谢Kevin Lee的解析方法。对我有帮助:)和Dave Newton,请不要在回答问题时不客气。 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.
无论如何,请Ty。 !!
!!
Your getMagnitude()
method returns a string. 您的
getMagnitude()
方法返回一个字符串。 However, your getMagnitudeColor()
method expects an integer for a parameter. 但是,您的
getMagnitudeColor()
方法需要一个整数作为参数。 You have to either change the return type of getMagnitude()
or change the type of your parameter for getMagnitudeColor()
so that they both match. 你必须要么改变的返回类型
getMagnitude()
或更改参数的类型getMagnitudeColor()
使它们都匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.