String 类型的 split(String) 方法未定义

发布于 2024-08-31 00:58:33 字数 419 浏览 4 评论 0原文

我正在使用 Pulse - Eclipse 的插件管理器并安装。我有用于移动开发(Pulsar)的 Eclipse 3.5 配置文件以及其他几个配置文件。

我意识到 split() 方法从如下代码调用字符串:

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

生成错误:“方法 split(String) 对于字符串类型未定义”。我知道 split() 方法在 Java 的 JRE 1.4 之前并不存在,这可能是问题的原因。 问题是我认为我没有安装 jre/sdk 版本。也许有一个内置的 Pulsar 配置文件需要编辑 - 但我不知道哪些设置(以及在哪里)需要调整。我检查了Windows>首选项>Java>安装的JRE,它设置为>= jre1.4。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

天荒地未老 2024-09-07 00:58:34

我注意到“Eclipse 3.5 for mobiledevelopment”。也许这个工具期望运行 J2ME,我认为这是 J2SE 背后的几个问题。

此页面提供指向 JME 中各种 API 的 JavaDoc 的链接。有几个版本(按照 CLDC 和 CDC 下的链接并查找 java.lang.String),但据我所知,它们都没有定义 String.split()。

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().

孤独陪着我 2024-09-07 00:58:34

String.split 方法是从 Java 1.4 版本开始引入的,如果你有同样的工作要做,你可以尝试一下:

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

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;
    }
忘年祭陌 2024-09-07 00:58:34

上次我查看时(在 Windows XP 安装中),我发现默认安装的 JVM 是 1.3 。

您可以弹出一个“DOS shell”(错误,命令提示符)并输入 java -version 来查看至少关于 PATH 上的 Java 的真相。

我绝对推荐安装最新的 JDK。 JDK 包括编译器和其他工具,这对开发人员来说比 JRE 更有用。然后,您需要返回 Eclipse 的首选项并将其 JDK/JRE 设置指向新安装的 JDK。

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.

蔚蓝源自深海 2024-09-07 00:58:34

字符串数据=“一、二、三、四”;
data.split(",");

您是否声明

String[] 变量

示例
String[] 变量 = data.split(",");
for(字符串值:变量){
System.out.println(值);
原理

我尝试了一下它的工作

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

迷路的信 2024-09-07 00:58:34

我遇到了同样的问题,但它适用于 ReplaceAll(arg1,arg2) 方法,并在我更改 jre 版本的顺序时解决。例如,我使用jre 8,那么顺序应该在java构建路径中:在“顺序和导出”中排名第一。 JRE库

i got the same issue but its for replaceAll(arg1,arg2) method and resolved when i changed order of jre version . for eg i m using jre 8 then order should in java build path: rank fiest in " order and export". JRE library

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文