程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> string-從EditText中獲取單個字符

string-從EditText中獲取單個字符

編輯:編程綜合問答
從EditText中獲取單個字符
String PT = pt.getText().toString(); 
int len = PT.length(); 
char chars[] = PT.toCharArray(); 
for(int i=0;i<len;i++)
{ Toast.makeText(encrypt.this,chars[i], 0).show(); }

這段代碼是用在EditText中讀取字符串,獲取單個字符的。但是結果出了一個logcat錯誤信息:

11-28 12:41:01.228: E/AndroidRuntime(1632):     at android.app.ActivityThread.main(ActivityThread.java:3683)
11-28 12:41:01.228: E/AndroidRuntime(1632):     at java.lang.reflect.Method.invokeNative(Native Method)
11-28 12:41:01.228: E/AndroidRuntime(1632):     at java.lang.reflect.Method.invoke(Method.java:507)
11-28 12:41:01.228: E/AndroidRuntime(1632):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-28 12:41:01.228: E/AndroidRuntime(1632):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-28 12:41:01.228: E/AndroidRuntime(1632):     at dalvik.system.NativeStart.main(Native Method)
11-28 12:46:43.688: W/KeyCharacterMap(1674): No keyboard for id 0
11-28 12:46:43.688: W/KeyCharacterMap(1674): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-28 12:46:54.442: W/ResourceType(1674): No package identifier when getting value for resource number 0x00000061
11-28 12:46:54.448: D/AndroidRuntime(1674): Shutting down VM
11-28 12:46:54.448: W/dalvikvm(1674): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-28 12:46:54.459: E/AndroidRuntime(1674): FATAL EXCEPTION: main
11-28 12:46:54.459: E/AndroidRuntime(1674): android.content.res.Resources$NotFoundException: String resource ID #0x61
11-28 12:46:54.459: E/AndroidRuntime(1674):     at android.content.res.Resources.getText(Resources.java:201)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at android.widget.Toast.makeText(Toast.java:258)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at com.project.DENCrypt.encrypt$1.onClick(encrypt.java:33)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at android.view.View.performClick(View.java:2485)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at android.view.View$PerformClick.run(View.java:9080)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at android.os.Handler.handleCallback(Handler.java:587)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at android.os.Looper.loop(Looper.java:123)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at android.app.ActivityThread.main(ActivityThread.java:3683)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at java.lang.reflect.Method.invokeNative(Native Method)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at java.lang.reflect.Method.invoke(Method.java:507)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-28 12:46:54.459: E/AndroidRuntime(1674):     at dalvik.system.NativeStart.main(Native Method)

最佳回答:


Toast.makeText(encrypt.this,chars[i] + "", 0).show();

原錯誤在於char會轉換成int導致尋找int對應的resource。

suannai0314
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved