綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] (已解決)設計一個溫度轉換 遇到的問題

[複製連結] 查看: 3346|回覆: 12|好評: -1
跳轉到指定樓層
樓主
jacy008723 | 收聽TA | 只看該作者 回帖獎勵 |正序瀏覽 |閱讀模式
發表於 2013-5-5 14:32

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
本帖最後由 jacy008723 於 2013-5-6 22:45 編輯

各位大大們好:

小弟最近才開始寫程式,但是遇到一些問題想請教各位大大

就是我現在設計了一個溫度轉換的程式,讓攝氏轉為華氏,再轉回攝氏 可是不知道怎麼寫

目前遇到問題: 是輸入攝氏按下第一個轉換正常轉成華氏,在按下第二個轉換就當機了

另外我改成兩行: 攝氏=>轉換=>華氏
                      華氏=>轉換=>攝氏

都可以執行,但是又發現華氏=>轉換=>攝氏 (如果華氏輸入浮點數就當了)

懇請大大們幫幫小弟^^


以下是我先轉為華氏的程式

「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

13
 樓主| jacy008723 | 收聽TA | 只看該作者
發表於 2013-5-6 22:46
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

12
clotai | 收聽TA | 只看該作者
發表於 2013-5-6 19:01
jacy008723 發表於 2013-5-6 18:39
我現在發現只要不是整數就會當機  

但是把度C轉成度F的"度F"那個數值用成整數不就不能使用小數點了?

所有轉換都用 float 轉, 而不是用 Integer.parseInt,
使用 Float.parseFloat
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

11
 樓主| jacy008723 | 收聽TA | 只看該作者
發表於 2013-5-6 18:39
whl 發表於 2013-5-6 09:22
Caused by: java.lang.NumberFormatException: Invalid int: "212.0"
這就是問題點,212.0並不是整數,所 ...


我現在發現只要不是整數就會當機  

但是把度C轉成度F的"度F"那個數值用成整數不就不能使用小數點了?

有辦法從度C轉成度F為小數,小數再轉回度C嗎?
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

10
 樓主| jacy008723 | 收聽TA | 只看該作者
發表於 2013-5-6 18:26
本帖最後由 jacy008723 於 2013-5-6 18:31 編輯
clotai 發表於 2013-5-6 09:33
基本上, 你的程式好像不只一個錯誤,  另外把你的 Layout  xml 放上來吧.


請大大過目...

https://www.dropbox.com/s/fn0pz7tbtqx8ir7/main.xml
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

9
clotai | 收聽TA | 只看該作者
發表於 2013-5-6 09:33
基本上, 你的程式好像不只一個錯誤,  另外把你的 Layout  xml 放上來吧.
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

8
whl | 收聽TA | 只看該作者
發表於 2013-5-6 09:22
jacy008723 發表於 2013-5-6 08:54
是的 我有刪

我先貼 logcat 給你看看

Caused by: java.lang.NumberFormatException: Invalid int: "212.0"
這就是問題點,212.0並不是整數,所以丟出來異常。
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

7
 樓主| jacy008723 | 收聽TA | 只看該作者
發表於 2013-5-6 08:54
whl 發表於 2013-5-6 08:35
你貼出來的程式是不是有刪過?怎麼沒看到 setonClicklistener?


是的 我有刪

我先貼 logcat 給你看看

05-06 00:52:12.222: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:12.222: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:12.222: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:12.362: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:12.402: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:12.862: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:12.862: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:12.952: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.032: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.062: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.072: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.102: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.152: D/dalvikvm(784): GC_CONCURRENT freed 98K, 8% free 2688K/2904K, paused 18ms+23ms, total 152ms
05-06 00:52:13.162: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.162: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.172: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.172: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.172: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.182: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.192: D/gralloc_goldfish(784): Emulator without GPU emulation detected.
05-06 00:52:13.232: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.272: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.632: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.632: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.692: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:13.692: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.122: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.122: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.152: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.152: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.412: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.422: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.432: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.442: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.453: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.453: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.502: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.612: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.612: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.612: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.772: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.782: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.862: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.862: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.952: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:14.952: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:17.402: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:17.402: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:17.442: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:17.442: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:17.972: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:17.982: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:18.012: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:18.012: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:18.272: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:18.282: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:18.356: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:18.402: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:18.585: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:18.585: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:18.612: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:18.612: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.108: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.112: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.132: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.132: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.362: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.372: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.392: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.402: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.422: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.422: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.432: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.442: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.452: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.462: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.472: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.472: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.472: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.492: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.502: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.502: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.582: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.582: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.612: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.612: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.632: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.632: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.632: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:19.652: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.208: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.208: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.223: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.233: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.393: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.412: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.412: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.412: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.432: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.432: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.432: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.452: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.472: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.472: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.482: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.482: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.723: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.723: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.743: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:20.753: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:21.253: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:21.253: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:21.253: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:21.282: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:21.293: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:21.293: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:21.373: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:21.392: W/Trace(784): Unexpected value from nativeGetEnabledTags: 0
05-06 00:52:21.403: D/AndroidRuntime(784): Shutting down VM
05-06 00:52:21.403: W/dalvikvm(784): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
05-06 00:52:21.443: E/AndroidRuntime(784): FATAL EXCEPTION: main
05-06 00:52:21.443: E/AndroidRuntime(784): java.lang.IllegalStateException: Could not execute method of the activity
05-06 00:52:21.443: E/AndroidRuntime(784):         at android.view.View$1.onClick(View.java:3597)
05-06 00:52:21.443: E/AndroidRuntime(784):         at android.view.View.performClick(View.java:4202)
05-06 00:52:21.443: E/AndroidRuntime(784):         at android.view.View$PerformClick.run(View.java:17340)
05-06 00:52:21.443: E/AndroidRuntime(784):         at android.os.Handler.handleCallback(Handler.java:725)
05-06 00:52:21.443: E/AndroidRuntime(784):         at android.os.Handler.dispatchMessage(Handler.java:92)
05-06 00:52:21.443: E/AndroidRuntime(784):         at android.os.Looper.loop(Looper.java:137)
05-06 00:52:21.443: E/AndroidRuntime(784):         at android.app.ActivityThread.main(ActivityThread.java:5039)
05-06 00:52:21.443: E/AndroidRuntime(784):         at java.lang.reflect.Method.invokeNative(Native Method)
05-06 00:52:21.443: E/AndroidRuntime(784):         at java.lang.reflect.Method.invoke(Method.java:511)
05-06 00:52:21.443: E/AndroidRuntime(784):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-06 00:52:21.443: E/AndroidRuntime(784):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-06 00:52:21.443: E/AndroidRuntime(784):         at dalvik.system.NativeStart.main(Native Method)
05-06 00:52:21.443: E/AndroidRuntime(784): Caused by: java.lang.reflect.InvocationTargetException
05-06 00:52:21.443: E/AndroidRuntime(784):         at java.lang.reflect.Method.invokeNative(Native Method)
05-06 00:52:21.443: E/AndroidRuntime(784):         at java.lang.reflect.Method.invoke(Method.java:511)
05-06 00:52:21.443: E/AndroidRuntime(784):         at android.view.View$1.onClick(View.java:3592)
05-06 00:52:21.443: E/AndroidRuntime(784):         ... 11 more
05-06 00:52:21.443: E/AndroidRuntime(784): Caused by: java.lang.NumberFormatException: Invalid int: "212.0"
05-06 00:52:21.443: E/AndroidRuntime(784):         at java.lang.Integer.invalidInt(Integer.java:138)
05-06 00:52:21.443: E/AndroidRuntime(784):         at java.lang.Integer.parse(Integer.java:375)
05-06 00:52:21.443: E/AndroidRuntime(784):         at java.lang.Integer.parseInt(Integer.java:366)
05-06 00:52:21.443: E/AndroidRuntime(784):         at java.lang.Integer.parseInt(Integer.java:332)
05-06 00:52:21.443: E/AndroidRuntime(784):         at androidEx.ch13.Ch13_4_1Activity.button2_Click(Ch13_4_1Activity.java:34)
05-06 00:52:21.443: E/AndroidRuntime(784):         ... 14 more
05-06 00:53:07.693: I/Process(784): Sending signal. PID: 784 SIG: 9
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

6
whl | 收聽TA | 只看該作者
發表於 2013-5-6 08:35
你貼出來的程式是不是有刪過?怎麼沒看到 setonClicklistener?
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

5
clotai | 收聽TA | 只看該作者
發表於 2013-5-5 23:15
jacy008723 發表於 2013-5-5 21:08
修改完之後 按下第二個按鈕沒反應

然後只輸入華氏那一欄 按第二個轉換當機 跳出 ...

沒有 logcat ? 有的話應該很清楚問題 在哪邊吧.
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則