編輯:關於Android編程
問題描述:
從一個XML文件中獲取字符串,內容大概就是262626這樣。現在需要將字符串轉換到 MB (/1024)形式。但是不能轉換int或者長整型。我的測試代碼:
[java]
String size = parser.getValue(e, parser.KEY_FileSizeInByte);
Log.i("menuItems",size);
try {
int s = Integer.parseInt(size);
Log.i("s", getString(s));
}
catch (Exception e1) {
Log.i("error", e1.getMessage());
}
String size = parser.getValue(e, parser.KEY_FileSizeInByte);
Log.i("menuItems",size);
try {
int s = Integer.parseInt(size);
Log.i("s", getString(s));
}
catch (Exception e1) {
Log.i("error", e1.getMessage());
}我還測試了:
[java]
nteger.valueOf(str);
Integer.valueOf(str);
得到的錯誤:
[java]
04-15 23:06:17.652: I/menuItems(6819): 97035
04-15 23:06:17.652: W/ResourceType(6819): No package identifier when getting value for resource number 0x00017b0b
04-15 23:06:17.652: I/error(6819): String resource ID #0x17b0b
04-15 23:06:17.692: I/menuItems(6819): 2957
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00000b8d
04-15 23:06:17.692: I/error(6819): String resource ID #0xb8d
04-15 23:06:17.692: I/menuItems(6819): 559711
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00088a5f
04-15 23:06:17.692: I/error(6819): String resource ID #0x88a5f
04-15 23:06:17.692: I/menuItems(6819): 153651
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00025833
04-15 23:06:17.692: I/error(6819): String resource ID #0x25833
04-15 23:06:17.692: I/menuItems(6819): 1733630
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x001a73fe
04-15 23:06:17.692: I/error(6819): String resource ID #0x1a73fe
04-15 23:06:17.692: I/menuItems(6819): 532105
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00081e89
04-15 23:06:17.692: I/error(6819): String resource ID #0x81e89
04-15 23:06:17.702: I/menuItems(6819): 28817
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x00007091
04-15 23:06:17.702: I/error(6819): String resource ID #0x7091
04-15 23:06:17.702: I/menuItems(6819): 90787
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x000162a3
04-15 23:06:17.702: I/error(6819): String resource ID #0x162a3
04-15 23:06:17.702: I/menuItems(6819): 33556
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x00008314
04-15 23:06:17.702: I/error(6819): String resource ID #0x8314
04-15 23:06:17.702: I/menuItems(6819): 122145
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x0001dd21
04-15 23:06:17.702: I/error(6819): String resource ID #0x1dd21
04-15 23:06:17.702: I/menuItems(6819): 323312
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x0004eef0
04-15 23:06:17.702: I/error(6819): String resource ID #0x4eef0
04-15 23:06:17.702: I/menuItems(6819): 532676
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x000820c4
04-15 23:06:17.702: I/error(6819): String resource ID #0x820c4
04-15 23:06:17.712: I/menuItems(6819): 49133
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x0000bfed
04-15 23:06:17.712: I/error(6819): String resource ID #0xbfed
04-15 23:06:17.712: I/menuItems(6819): 622507
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x00097fab
04-15 23:06:17.712: I/error(6819): String resource ID #0x97fab
04-15 23:06:17.712: I/menuItems(6819): 57333
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x0000dff5
04-15 23:06:17.712: I/error(6819): String resource ID #0xdff5
04-15 23:06:17.712: I/menuItems(6819): 17265
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x00004371
04-15 23:06:17.712: I/error(6819): String resource ID #0x4371
04-15 23:06:17.652: I/menuItems(6819): 97035
04-15 23:06:17.652: W/ResourceType(6819): No package identifier when getting value for resource number 0x00017b0b
04-15 23:06:17.652: I/error(6819): String resource ID #0x17b0b
04-15 23:06:17.692: I/menuItems(6819): 2957
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00000b8d
04-15 23:06:17.692: I/error(6819): String resource ID #0xb8d
04-15 23:06:17.692: I/menuItems(6819): 559711
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00088a5f
04-15 23:06:17.692: I/error(6819): String resource ID #0x88a5f
04-15 23:06:17.692: I/menuItems(6819): 153651
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00025833
04-15 23:06:17.692: I/error(6819): String resource ID #0x25833
04-15 23:06:17.692: I/menuItems(6819): 1733630
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x001a73fe
04-15 23:06:17.692: I/error(6819): String resource ID #0x1a73fe
04-15 23:06:17.692: I/menuItems(6819): 532105
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00081e89
04-15 23:06:17.692: I/error(6819): String resource ID #0x81e89
04-15 23:06:17.702: I/menuItems(6819): 28817
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x00007091
04-15 23:06:17.702: I/error(6819): String resource ID #0x7091
04-15 23:06:17.702: I/menuItems(6819): 90787
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x000162a3
04-15 23:06:17.702: I/error(6819): String resource ID #0x162a3
04-15 23:06:17.702: I/menuItems(6819): 33556
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x00008314
04-15 23:06:17.702: I/error(6819): String resource ID #0x8314
04-15 23:06:17.702: I/menuItems(6819): 122145
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x0001dd21
04-15 23:06:17.702: I/error(6819): String resource ID #0x1dd21
04-15 23:06:17.702: I/menuItems(6819): 323312
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x0004eef0
04-15 23:06:17.702: I/error(6819): String resource ID #0x4eef0
04-15 23:06:17.702: I/menuItems(6819): 532676
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x000820c4
04-15 23:06:17.702: I/error(6819): String resource ID #0x820c4
04-15 23:06:17.712: I/menuItems(6819): 49133
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x0000bfed
04-15 23:06:17.712: I/error(6819): String resource ID #0xbfed
04-15 23:06:17.712: I/menuItems(6819): 622507
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x00097fab
04-15 23:06:17.712: I/error(6819): String resource ID #0x97fab
04-15 23:06:17.712: I/menuItems(6819): 57333
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x0000dff5
04-15 23:06:17.712: I/error(6819): String resource ID #0xdff5
04-15 23:06:17.712: I/menuItems(6819): 17265
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x00004371
04-15 23:06:17.712: I/error(6819): String resource ID #0x4371
解決方案:
報這個warning的不是你的轉換,而是你接下來的這句getString()
你改測試就簡單的好好測,看如下
[java]
try {
int s = Integer.parseInt(size);
System.out.println("Got num is:"+s);//正確
//Log.i("s", getString(s));
.....
try {
int s = Integer.parseInt(size);
System.out.println("Got num is:"+s);//正確
//Log.i("s", getString(s));
.....
關於getString()的用法解釋是:
Return a localized string from the application's package's default string table.
你可以在values下的strings.xml下定義一個
[java]
<string name="my_str">abc123456</string>
<string name="my_str">abc123456</string>
然後這樣去得到它:
[java]
Log.i("s", getString(R.string.my_str));//s abc123456
Log.i("s", getString(R.string.my_str));//s abc123456
我已經介紹了如何快速集成MOB短信驗證SDK,那今天我們講什麼呢?我們今天講一下如何不使用SDK中的GUI界面。對!我們今天來學習怎麼自定義GUI,說的直白點就是自定義界
寫在前面現在,越來越多的App裡面使用了模糊效果,這種模糊效果稱之為高斯模糊。大家都知道,在Android平台上進行模糊渲染是一個相當耗CPU也相當耗時的操作,一旦處理不
今天學習的新內容是側滑導航欄,我想大家肯定都比較熟悉了,因為這個效果在qq裡面也有,最近一直跟室友們玩的游戲是快速讓自己的頭像的點贊量上千。當然我的效果跟qq是沒有辦法比
一、前言Android 實現衛星式菜單也叫弧形菜單,主要要做的工作如下:1.動畫的處理2.自定義ViewGroup來實現衛星式菜單View(1)自定義屬性 &n