jjzjj

StringIndexOutOfBoundsException

全部标签

java - 当 char 没有值时,如何避免 StringIndexOutOfBoundsException?

抱歉,如果标题没有意义,但我不知道如何表达。问题:我正在制作一个多项选择问答游戏,它可以从用户那里获得a、b、c或d。如果他们按照他们的指示去做,这没有问题,但是如果他们不输入任何内容而只是按回车键,我会得到一个StringIndexOutOfBoundsException。我明白为什么会这样,但我是Java的新手,想不出修复它的方法。我目前拥有的:System.out.println("EntertheAnswer.");response=input.nextLine().charAt(0);if(response=='a'){System.out.println("Correct"

android - 来自 SpannableStringInternal 的 StringIndexOutOfBoundsException

我不断收到来自市场的以下错误报告:java.lang.StringIndexOutOfBoundsException:length=51;regionStart=37;regionLength=-15atjava.lang.String.startEndAndLength(String.java:593)atjava.lang.String.getChars(String.java:902)atandroid.text.SpannableStringInternal.getChars(SpannableStringInternal.java:70)atandroid.text.Text

java - 压缩类错误 - 线程异常 "main"java.lang.StringIndexOutOfBoundsException : String index out of range: -1

我已经为客户端服务器TCP数据连接创建了这个简单的压缩类,它在我看来一切正常,没有构建错误,但是我遇到了一个我无法更正的运行时错误。我得到的错误是线程“主”java.lang.StringIndexOutOfBoundsException中的异常:字符串索引超出范围:-1。代码:importjava.io.Serializable;importjava.util.ArrayList;publicclassCompressedMessageimplementsSerializable{//thisinstancevariablewillstoretheoriginal,compresse

java - jboss 上的 Yui 压缩器 StringIndexOutOfBoundsException

当使用2.4.6最小化yui时,我遇到了这个问题:java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:232atjava.lang.String.substring(String.java:1934)atcom.yahoo.platform.yui.compressor.JavaScriptCompressor.printSourceString(JavaScriptCompressor.java:267)atcom.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(Ja

java.lang.StringIndexOutOfBoundsException: String index out of range: 0

        该错误表示字符串的索引超出了范围。这种错误通常发生在尝试访问字符串中不存在的索引位置的时候。        这个错误可能有多种原因,具体取决于代码逻辑和使用字符串的方式。以下是一些常见的导致此错误的情况以及相应的解决方法:一、空字符串:        当字符串为空时,访问索引位置0会导致StringIndexOutOfBoundsException错误。确保在使用索引之前,先检查字符串是否为空。Stringstr="";//空字符串if(!str.isEmpty()){charfirstChar=str.charAt(0);}二、未初始化的字符串:如果字符串没有被正确初始化,尝

java.lang.StringIndexOutOfBoundsException : index=0 length=0 in get sqlite database 异常

我正在尝试用这段代码打开一个可写的SQLite数据库...publicDataAdapterForServieClassopen()throwsSQLException{db=DBHelper.getWritableDatabase();returnthis;}但是我在db=DBHelper.getWritableDatabase();行中收到以下错误...06-1011:58:13.995:ERROR/AndroidRuntime(548):FATALEXCEPTION:main06-1011:58:13.995:ERROR/AndroidRuntime(548):java.lang

java.lang.StringIndexOutOfBoundsException : index=0 length=0 in get sqlite database 异常

我正在尝试用这段代码打开一个可写的SQLite数据库...publicDataAdapterForServieClassopen()throwsSQLException{db=DBHelper.getWritableDatabase();returnthis;}但是我在db=DBHelper.getWritableDatabase();行中收到以下错误...06-1011:58:13.995:ERROR/AndroidRuntime(548):FATALEXCEPTION:main06-1011:58:13.995:ERROR/AndroidRuntime(548):java.lang

java - 了解 java.lang.StringIndexOutOfBoundsException : length=X; regionStart=Y; regionLength=Z

如何解释java.lang.StringIndexOutOfBoundsException:length=30278;regionStart=6877;regionLength=-12或者更好的方法是如何在中重现这样的异常length为正,regionStart为正且小于lengthregionLength是否为负数?这些属性究竟意味着什么?此异常的文档中未提及它们。我只知道java.lang.StringIndexOutOfBoundsException:Stringindexoutofrange:X其中X是一个负整数。可重现:Strings="helloworld";Stringc

java - 如何在 android 中解决 StringIndexOutOfBoundsException

这是我的logcat报告:java.lang.StringIndexOutOfBoundsException:length=0;regionStart=0;regionLength=2atjava.lang.String.startEndAndLength(String.java:583)atjava.lang.String.substring(String.java:1464)atcom.buzzador.profile.getValidPhoneNumber(profile.java:1966)atcom.buzzador.profile.setDataForServer(prof

java - 当我尝试将 `\\` 替换为 `\` 时,为什么会出现 StringIndexOutOfBoundsException?

我必须在Java中用\替换\\。我使用的代码是System.out.println((MyConstants.LOCATION_PATH+File.separator+myObject.getStLocation()).replaceAll("\\\\","\\"));但我不知道为什么会抛出StringIndexOutOfBoundsException。它说Stringindexoutofrange:1可能是什么原因?我猜这是因为第一个参数replaceAll接受了一个模式。可能的解决方案是什么?堆栈跟踪Exceptioninthread"main"java.lang.StringIn
12