一直崩溃啊T^T 先把字符串Array转为字符数组,然后,用Toast显示每个字母

Peyton_ 2017-12-13 08:52:19
char EveryEnd[];
EveryEnd = Array.toCharArray();
//Toast.makeText(getApplicationContext(), Integer.toString(Array.length()), Toast.LENGTH_SHORT).show();
for(i = 0;i<=Array.length();i++){
Toast.makeText(getApplicationContext(),EveryEnd[i],Toast.LENGTH_SHORT).show();
//写成String.valueOf(EveryEnd[i])都不可以
}

再次点了一队大佬T^T

好像这是报错?
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.guyun.fundamentals_of_compiling/com.example.guyun.fundamentals_of_compiling.DFA_3}: android.content.res.Resources$NotFoundException: String resource ID #0x31
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x31
at android.content.res.Resources.getText(Resources.java:338)
at android.widget.Toast.makeText(Toast.java:304)
at com.example.guyun.fundamentals_of_compiling.DFA_3.onCreate(DFA_3.java:48)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
...全文
233 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
android.content.res.Resources$NotFoundException: String resource ID #0x31 你把一个int 输入到String类型的参数了 Toast.makeText(getApplicationContext(),EveryEnd[i],Toast.LENGTH_SHORT).show(); 至于//写成String.valueOf(EveryEnd[i])都不可以 这个问题就不清楚了 需要更多信息
jklwan 2017-12-14
  • 打赏
  • 举报
回复
用String.valueOf(EveryEnd[i]),EveryEnd[i]默认转为int了
Peyton_ 2017-12-14
  • 打赏
  • 举报
回复
引用 7 楼 cxz003 的回复:
java.lang.ArrayIndexOutOfBoundsException: length=3; index=3 数组下标越界 长度3的数组A 没有A[3]
谢谢大佬!
  • 打赏
  • 举报
回复
java.lang.ArrayIndexOutOfBoundsException: length=3; index=3 数组下标越界 长度3的数组A 没有A[3]
Peyton_ 2017-12-14
  • 打赏
  • 举报
回复
引用 4 楼 cxz003 的回复:
for(i = 0;i<=Array.length();i++) 去掉等于
哇真的就可以了!谢谢大佬!这报错什么意思呢
Peyton_ 2017-12-14
  • 打赏
  • 举报
回复
引用 4 楼 cxz003 的回复:
for(i = 0;i<=Array.length();i++) 去掉等于
好~
  • 打赏
  • 举报
回复
for(i = 0;i<=Array.length();i++) 去掉等于
Peyton_ 2017-12-14
  • 打赏
  • 举报
回复
引用 2 楼 cxz003 的回复:
android.content.res.Resources$NotFoundException: String resource ID #0x31 你把一个int 输入到String类型的参数了 Toast.makeText(getApplicationContext(),EveryEnd[i],Toast.LENGTH_SHORT).show(); 至于//写成String.valueOf(EveryEnd[i])都不可以 这个问题就不清楚了 需要更多信息
前面用Toast是可以把这个字符串Array正确输出的。 Toast.makeText(getApplicationContext(), Array, Toast.LENGTH_SHORT).show(); 传入的字符串是1,2 这个是用了String.valueOf(EveryEnd[i])之后的报错 java.lang.ArrayIndexOutOfBoundsException: length=3; index=3

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧