使用eclipse運行項目的過程中,出現如下問題:
但是主要的問題根源已做標記,從網上查閱資料:
java.lang.IllegalStateException: Could not excute method of the activity
在java環境和應用尚未處於某個方法的合法調用狀態時,而調用改方法時,拋出該異常。
java.lang.NumberFormatException: Invalid int:"09a0ds" (錯誤源頭,並數字類型)
字符串轉換為數字異常
其實,通過第二個已經可以定位問題的所在了。接下來主要來簡要的說明下java數據類型中String,Integer,int之間的相互轉換:
(1) String -> Integer: Integer.valueOf(str)
(2) String -> Int: Integer.valueOf(str).intValue()
(3) Integer -> String:
Integer it = new Integer(10);
String str = it.toString();
(4) int -> String:
1. String s = String.valueOf(i);
2. String s = Integer.toString(i);
(5) Integer ->int: i.intValue()
(6) int -> Integer: Integer it = new Integer(i);
通過(5)(6)其實,已經可以看到 int與Integer 的區別來,但是還是簡單的進行下總結,算是加深記憶吧。
int: 基本數據類型,直接存儲數值,初始化為0
integer: 復雜數據類型,使用引用指向這個對象,因為初始化為null。且Integer是int的封裝類。
參考於:
http://my.oschina.net/u/1861837/blog/335581?p={{currentPage+1}}
哎,扯遠了,我這邊的問題實質上是測試數據時,將int型變量寫成了“09a0ds”,這是什么呀。