第20行类型错误:要求Int却检测到Double,温度显示列数异常求助
Troubleshooting Your Temperature Converter Issues
Hey Sophia, let's work through your two main problems step by step to get that temperature table working as intended:
1. Fixing the Required 'Int' found Double Error (Line 20)
This error pops up because you’re passing a floating-point value (Double) to a spot that expects an integer (Int). Here’s where to start debugging:
- Look directly at line 20: Check what variable assignment, function call, or calculation is happening here. For example, if you’re calculating Fahrenheit with
C * 9/5 + 32, using floating-point division (like9.0/5instead of integer9/5) will produce aDoubleresult. If you’re trying to store this in anIntvariable or pass it to a function that requires an integer, you’ll hit this error. - Audit your variable types: Double-check if your Fahrenheit value is declared as
Intinstead ofDouble. Since Fahrenheit conversions often result in decimals (e.g., 1°C = 33.8°F), you’ll likely want to useDoublefor both temperature scales to keep precision. - Check UI bindings: If line 20 involves updating a UI element (like a text view), make sure the component accepts
Doublevalues, or explicitly convert the value toInt(using something likeInt(fahrenheitValue)if you don’t need decimal places).
2. Fixing the Single-Column Layout Problem
To get your Celsius and Fahrenheit values to display side-by-side in two columns, try these checks:
- Review your layout container: If you’re using a linear layout, ensure it’s set to
horizontalorientation (vertical will stack everything in one column). For more structured columns, use aGridLayout(define 2 columns upfront) orTableLayout(with two dedicatedTableColumnelements). - Adjust component width settings: If your text views or data containers are set to
match_parent(full width), they’ll take up the entire row and push the next element below. Set their width towrap_contentor uselayout_weightto split the row space evenly between the two columns. - Check your dynamic rendering logic: If you’re generating UI elements for each temperature pair, make sure you create two elements (one for Celsius, one for Fahrenheit) and add them to the same row in your layout. For example, in a
TableLayout, create a newTableRowfor each pair, then add twoTextViews(one per scale) to that row—don’t dump all elements into a single vertical list.
内容的提问来源于stack exchange,提问作者Sophia Green
相关产品推荐
相关产品推荐

