Loop Moon Error Problem During Android Java Development

Asked 2 years ago, Updated 2 years ago, 39 views

private void playCode(String code) {  
    String tmp;  
    while(code != "") {  
        If(code.indexOf("f") == 2) { //Read Code  
            tmp = code.substring(0, 3);  
            code = code.substring(3);  
        } } else {  
            tmp = code.substring(0, 2);  
            code = code.substring(2);  
           }  
    }  
}  

To explain, there is a string called code (for example, C4D4D4D4f is configured in this way)

Until the code in the while statement leaves no text, Cut two or three characters each and store them in a variable called tmp I'm trying to erase as many parts of the existing code variable as the part stored in tmp through substring.

However, if you compile after coding as above, there will be an error when running the Android app If you erase the code inside the while statement, the execution will be normal... What's wrong with this?

android java eclipse

2022-09-22 19:33

1 Answers

I repeatedly substring the code value.

If the code length at the time of the error is less than 2 or 3, the error will occur.


2022-09-22 19:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.