[英]Error using split method in Codenameone
I have created a new Codenameone project. 我创建了一个新的Codenameone项目。 It contains the following code:
它包含以下代码:
String values = "one, two, tree"; String[] v = values.split(",");
When I build the project, I got this error: 构建项目时,出现以下错误:
location: variable definition of type String error: cannot find symbol String[] v = values.split(","); symbol: method split(String)
However, if I take the sample project "MapsDemo" and use the split method, everything is ok. 但是,如果我使用示例项目“ MapsDemo”并使用split方法,则一切正常。
What can be the problem? 可能是什么问题?
Thanks. 谢谢。
Codename One supports a subset of Java 5 and String.split()
isn't there. 代号One支持Java 5的子集,而
String.split()
不存在。 Its much harder to change the VM implementation code across all platforms than just add a portable library in the codename one package space. 在所有平台上更改VM实现代码要比在一个包空间的代号中添加一个可移植库要困难得多。 Its also harder to make all the edge cases 100% compatible and it makes the executable larger (you pay for String.split even if you don't use it!).
使所有边缘情况都100%兼容也更加困难,并且使可执行文件更大(即使您不使用它,也要为String.split付费!)。
We have StringUtils
and StringTokenizer
, there is also a regex package in the cn1lib section. 我们有
StringUtils
和StringTokenizer
,在cn1lib部分中还有一个regex包。
Why don't you try this? 你为什么不试试这个?
import java.util.StringTokenizer;
... ...
String fruits = "apple:pear:grape";
String delimiter = ":";
StringTokenizer fruitsTokenizer = new StringTokenizer(fruits, delimiter);
while (fruitsTokenizer.hasMoreTokens()) {
String fruit = fruitsTokenizer.nextToken();
//
// Do here something you want...
//
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.