Method splitting (String) undefined for type String

I use Pulse - Plugin Manager for Eclipse and installed. I have an Eclipse 3.5 profile for mobile development (Pulsar) with several other profiles.

I realized that the split () method calls a line from the code, for example:

String data = "one, two, three, four";
data.split(",");

generates an error: "The split (String) method is undefined for the type String." I know that the split () method did not exist before Java JRE 1.4 and may possibly be the cause of the problem. The problem is that I don’t think I have jre / sdk versions installed. Perhaps one of them is built into the Pulsar profile and needs to be edited, but I could not determine which settings (and where) needed to be configured. I checked Windows> Preferences> Java> Installed JREs and set the value> = jre1.4.

+3
source share
4 answers

I mark "Eclipse 3.5 for mobile development." Perhaps this tool expects to launch J2ME, which, in my opinion, causes several problems behind J2SE.

This page contains JavaDoc links for various APIs in JME. There are several versions (follow the links in the CLDC and CDC and see java.lang.String), but as far as I can tell, none of them defines String.split ().

+2
source

String.split the method has been introduced since Java 1.4, if you are doing the same task, you can try:

public String[] splitStr(String str, String delim) {
        StringTokenizer stringTokenizer = new StringTokenizer( str, delim );
        String[] strArr = new String[stringTokenizer.countTokens()];
        int i = 0;
        while( stringTokenizer.hasMoreTokens() ) {
            strArr[i] = stringTokenizer.nextToken();
        }
        return strArr;
    }
+2
source

, ( Windows XP), JVM 1.3.

" DOS" (err, command prompt) java -version, , Java PATH.

I definitely recommend installing the updated JDK. The JDK includes a compiler and other tools that are more useful to the developer than just a JRE. Then you need to go back to the Eclipse settings and specify the JDK / JRE settings on your newly installed JDK.

+1
source

String data = "one, two, three, four"; data.split(",");

you announce

String variable []

Example String[] variable = data.split(","); for(String value: variable){      System.out.println(value); }

I tried his work on it.

0
source

Source: https://habr.com/ru/post/1743064/


All Articles