这是个初学者非常容易遇到的问题,下面请看源代码:

public class Division {public static void main(String[] args) {String str = new String("abc,def,ghi,gkl");String[] newstr = str.split(",");for(int i=0;i<=newstr.length;i++) {System.out.println(newstr[i]);}}
}

运行之后出现这个问题:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4at text.Division.main(Division.java:8)

原因是因为在你进行String类型数组遍历时,定义的数组元素的第个下标越界(newstr[4]),即为零。也就是源代码的第行代码有错误,这时只要将数组遍历的条件修改为: newstr.length处理掉越界就OK了。

Exception in thread main java.lang.ArrayIndexOutOfBoundsException: 4 at text.Division.main(Divisi相关推荐

  1. Exception in thread main java.lang.ArrayIndexOutOfBoundsException: 0 at SimpleCalculator.main(Simp

    今天做Java资料书上一个实例,其中用到了int operand1=Integer.parseInt(args[0]);语句,但是执行时遇到了Exception in thread "mai ...

  2. Exception in thread http-bio-80exec-1 java.lang.OutOfMemoryError: PermGen s解决方案

    问题描述: Exception in thread ""http-bio-80"-exec-1" java.lang.OutOfMemoryError: Per ...

  3. Exception in thread http-bio-8081-exec-3 java.lang.OutOfMemoryError: PermGen space

    前言: 在http://www.cnblogs.com/wql025/p/4865673.html一文中我曾描述这种异常也提供了解决方式,但效果不太理想,现在用本文的方式,效果显著. 目前此项目只能登 ...

  4. 错误记录一:线程通信时抛出Exception in thread “Thread-0” java.lang.IllegalMonitorStateException异常

    错误记录一:线程通信时抛出Exception in thread "Thread-0" java.lang.IllegalMonitorStateException异常 完整异常: ...

  5. Exception in thread Spider-0 java.lang.NullPointerException - Gecco爬虫心得

    使用Gecco爬虫时偶尔遇到如下莫名其妙的异常而停止: Exception in thread "Spider-0" java.lang.NullPointerException ...

  6. 关于给java数组循环赋值时报错Exception in thread “main“ java.lang.ArrayIndexOutOfBoundsException: 5

    1.检查初始给数组分配的空间是否足够. 2查看循环限制是否超出限制, 假定数组为something, 数组长度为,something.length, 则指定循环限制要<something.len ...

  7. Exception in thread AWT-EventQueue-0 java.lang.IllegalThreadStateException

    在线程中出现这种错误的原因是多次启动start() 解决方法: 将start()改成 run() 转载于:https://www.cnblogs.com/IamThat/p/3142112.html

  8. java.lang.ArrayIndexOutOfBoundsException

    java.lang.ArrayIndexOutOfBoundsException is a runtime exception, so it's a unchecked exception and d ...

  9. Exception in thread main java.lang.Error: 无法解析的编译问题: 方法 main 不能声明为 static;只能在静态类型或顶级类型中才能声明静态方法

    Exception in thread "main" java.lang.Error: 无法解析的编译问题: 方法 main 不能声明为 static:只能在静态类型或顶级类型中才 ...

最新文章

  1. 【OpenCV 】反向投影
  2. Excel Sheet Column Number
  3. ps意外崩溃_充满意外的数学中考
  4. 给分类添加缓存并解释StringRedisTemplate
  5. TC工具后台模式_C++资深开发工程师带你深入浅出了解Linux后台开发
  6. 鼠标右键 移动选定的文件夹到指定位置_iRightMouse:一款免费Mac鼠标右键增强神器...
  7. 惯性制导精度是多少_航天装备的命中精度
  8. 02.改善深层神经网络:超参数调试、正则化以及优化 W1.深度学习的实践层面(作业:初始化+正则化+梯度检验)
  9. 求H21时的仿射变换要参考当前坐标系
  10. 机器学习十大经典算法之逻辑回归
  11. python写电商网站框架_Python学员感言:电商项目要先把框架搭起来
  12. Java8实战[1-4]章要义笔记
  13. SqlServer2012下载+安装+启动(资源+密钥)
  14. html中clear标签意义,html中的clear是什么意思
  15. 架构漫谈(八):从架构的角度看如何写好代码 + 我的思考
  16. 网络故障排障简单总结
  17. idea无法安装插件
  18. FCoin回来了?起死回生凭借何种“妙法”?
  19. 微信小程序 发布后强制更新版本 强制覆盖老版本
  20. VM中centos中设置共享文件夹

热门文章

  1. 2022天梯赛热身赛 浪漫侧影(什么原题)
  2. GridBagConstraints的gridx、gridy、gridwidth、gridheight、weightx、weighty解释
  3. python如何画动态海浪_python使用matplotlib画动态图
  4. (转链接)Linux 正则表达式
  5. 微信支付APPID MCHID APIKEY等配置方法
  6. 3ds Max: Advanced Lighting 3DS Max 教程之高级灯光 Lynda课程中文字幕
  7. Visual stdio2022选中翻译插件
  8. 技嘉Z690、B660主板VCCSA电压设计缺陷
  9. 抖音最火的五款手机修图软件,一秒变大片
  10. 无密码,删除压缩包密码?