You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

第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 (like 9.0/5 instead of integer 9/5) will produce a Double result. If you’re trying to store this in an Int variable 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 Int instead of Double. Since Fahrenheit conversions often result in decimals (e.g., 1°C = 33.8°F), you’ll likely want to use Double for 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 Double values, or explicitly convert the value to Int (using something like Int(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 horizontal orientation (vertical will stack everything in one column). For more structured columns, use a GridLayout (define 2 columns upfront) or TableLayout (with two dedicated TableColumn elements).
  • 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 to wrap_content or use layout_weight to 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 new TableRow for each pair, then add two TextViews (one per scale) to that row—don’t dump all elements into a single vertical list.

内容的提问来源于stack exchange,提问作者Sophia Green

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:37:35