Question

I am using Pulse - the Plugin Manager for Eclipse and installed. I have the Eclipse 3.5 for mobile development(Pulsar) profile with a couple other profiles.

I realized that the split() method called on a string from code such as below:

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

generates the error: "The method split(String) is undefined for the type String". I am aware that the split() method did not exist before Java's JRE 1.4 and perhaps could be the cause of the problem. The problem is I don't think I have jre/sdk versions installed. Perhaps there's one in-built with the Pulsar profile and needs editing - but I couldn't tell what settings (and where) needs tweaking. I have checked Windows>Preferences>Java>Installed JREs and it's set to >= jre1.4.

Was it helpful?

Solution

I note "Eclipse 3.5 for mobile development". Maybe this tool expects to run J2ME, which I believe is several issues behind J2SE.

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

OTHER TIPS

String.split method is introduced from Java version 1.4 onward, if you have same job to be done you may give a try to this:

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;
    }

Last time I looked (in a Windows XP installation), I found the default installed JVM to be 1.3 .

You could pop open a "DOS shell" (err, command prompt) and type java -version to see the truth at least about whatever Java is on the PATH.

I would definitely recommend installing an up-to-date JDK. The JDK includes a compiler and other tools, that's more useful to a developer than just a JRE. You then need to go back into Eclipse's preferences and point its JDK/JRE settings at your newly installed JDK.

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

are you declaring

String[] variable

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

I tried it its working on it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top