gpt4 book ai didi

java - Android-无法解决java.lang.StringIndexOutOfBoundsException

转载 作者:行者123 更新时间:2023-12-03 08:54:28 24 4
gpt4 key购买 nike

我在寻找解决方案甚至找不到此错误的原因时遇到了麻烦。此错误在Eclipse中的同一代码中不存在(用于测试),但在Android Studio应用中使用时会因错误而崩溃。

从Logcat:

 java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:4020)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4015)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ExceptionInInitializerError
at com.bmc.thirdparty.org.apache.commons.lang.builder.ToStringStyle$MultiLineToStringStyle.<init>(ToStringStyle.java:2135)
at com.bmc.thirdparty.org.apache.commons.lang.builder.ToStringStyle.<clinit>(ToStringStyle.java:79)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:309)
at java.lang.Class.forName(Class.java:273)
at com.bmc.arsys.api.Config.if(Unknown Source)
at com.bmc.arsys.api.Config.applyDefaults(Unknown Source)
at com.bmc.arsys.apitransport.ApiConfig.<init>(Unknown Source)
at com.bmc.arsys.api.Config.<init>(Unknown Source)
at com.bmc.arsys.api.Config.<clinit>(Unknown Source)
at com.bmc.arsys.api.session.a.a(Unknown Source)
at com.bmc.arsys.api.session.a.<init>(Unknown Source)
at com.bmc.arsys.api.ARServerUser.<clinit>(Unknown Source)
at flashmanagment.app.ARS.initializeServer(ARS.java:41)
at flashmanagment.app.MainActivity.loadData(MainActivity.java:51)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at android.view.View$1.onClick(View.java:4015)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.StringIndexOutOfBoundsException: length=1; regionStart=0; regionLength=3
at java.lang.String.startEndAndLength(String.java:504)
at java.lang.String.substring(String.java:1333)
at com.bmc.thirdparty.org.apache.commons.lang.SystemUtils.getJavaVersionAsFloat(SystemUtils.java:1122)
at com.bmc.thirdparty.org.apache.commons.lang.SystemUtils.<clinit>(SystemUtils.java:818)
            at com.bmc.thirdparty.org.apache.commons.lang.builder.ToStringStyle$MultiLineToStringStyle.<init>(ToStringStyle.java:2135)
            at com.bmc.thirdparty.org.apache.commons.lang.builder.ToStringStyle.<clinit>(ToStringStyle.java:79)
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:309)
            at java.lang.Class.forName(Class.java:273)
            at com.bmc.arsys.api.Config.if(Unknown Source)
            at com.bmc.arsys.api.Config.applyDefaults(Unknown Source)
            at com.bmc.arsys.apitransport.ApiConfig.<init>(Unknown Source)
            at com.bmc.arsys.api.Config.<init>(Unknown Source)
            at com.bmc.arsys.api.Config.<clinit>(Unknown Source)
            at com.bmc.arsys.api.session.a.a(Unknown Source)
            at com.bmc.arsys.api.session.a.<init>(Unknown Source)
            at com.bmc.arsys.api.ARServerUser.<clinit>(Unknown Source)
            at flashmanagment.app.ARS.initializeServer(ARS.java:41)
            at flashmanagment.app.MainActivity.loadData(MainActivity.java:51)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at android.view.View$1.onClick(View.java:4015)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

我从bmc导入的库是否出错?

来自主 Activity 的相关代码,通过单击按钮调用:
   public void loadData(View v){
ARS.getInstance().initializeServer("username","password");
}

从Java类:
public class ARS {

public static ARS instance = new ARS();

public static ARServerUser server;
public static ARS getInstance(){
return instance;
}

public void initializeServer(String user, String password){
server = new ARServerUser(user,password,null,"serverStringHere",portNumberHere);

}

同样,在Eclipse中使用了相同的代码,没有错误。任何帮助将不胜感激。

编辑SystemUtils.java:1122
    1118    private static float More ...getJavaVersionAsFloat() {
1119 if (JAVA_VERSION_TRIMMED == null) {
1120 return 0f;
1121 }
1122 String str = JAVA_VERSION_TRIMMED.substring(0, 3);
1123 if (JAVA_VERSION_TRIMMED.length() >= 5) {
1124 str = str + JAVA_VERSION_TRIMMED.substring(4, 5);
1125 }
1126 try {
1127 return Float.parseFloat(str);
1128 } catch (Exception ex) {
1129 return 0;
1130 }
1131 }

最佳答案

您应该提供有关程序的更多信息,因为此代码不是完整的图片。您正在尝试调用按钮单击,但是您的应用程序处于不正确的状态。

关于java - Android-无法解决java.lang.StringIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31415436/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com