同一段代码,在JSE没问题,在JME中出错!nextInt(int n)!

sandeel 2011-04-15 10:31:16
/*
Random rm = new Random();
int x = rm.nextInt(255);
System.out.println(x);
*/

JME 环境是Pulsa +SDK3.0

在调试时,nextInt()没问题,但就是不支持nextInt(int x)!
"The method nextInt() in the type Random is not applicable for the arguments (int)"
...全文
238 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
sandeel 2011-04-25
  • 打赏
  • 举报
回复
在Google上查询,终于等到解决方案如下:
http://stackoverflow.com/questions/4172010/j2me-error-the-method-nextint-in-the-type-random-is-not-applicable-for-the-ar

nextInt(int) is only available since CLDC 1.1, so you have to specify CLDC 1.1 instead of 1.0

if you specified cldc 1.1 an still get this error its most likely an error of eclipse. took me hours to find: in Eclipse go to Windows -> Preferences -> Java ME -> Device Management -> choose your Default Device -> Edit -> Libraries -> There you have to remove the cldc_1.0.jar

按以上设置后,同时删除了midp_2.0.jar,然后关闭Pulsa,再启动,报错信息消失,可以正确编译!
结贴!
谢谢Mailbomb,pdw_jsp!各感谢20分!
也谢谢raoyongchao,lliiqiang,afgasdg,fanyuanwai!
java爱好者 2011-04-21
  • 打赏
  • 举报
回复
我的没有问题 编译通过
网络咖啡 2011-04-20
  • 打赏
  • 举报
回复
这个方法要求CLDC1.1,手机肯定是不支持CLDC1.1的,手机太老了吧?
Dongo2 2011-04-19
  • 打赏
  • 举报
回复
而且你可以查看API的里面也有使用rm.nextInt(int)的例子的
Dongo2 2011-04-19
  • 打赏
  • 举报
回复
肯定的说这个事支持的。rm.nextInt(255) 这个表示的是 0 - 254 的一个随机数

我没有用Pulsa ,不过应该也不是环境的问题,你可以尝试一下把255改小点试看呢。比如10
凡员外 2011-04-19
  • 打赏
  • 举报
回复
J2ME支持的类库有限哦
lliiqiang 2011-04-18
  • 打赏
  • 举报
回复
nextInt方法没有参数
raoyongchao 2011-04-16
  • 打赏
  • 举报
回复
这个问题也遇到过...尽量不要用nextInt(int n),有时编译不通过...
sandeel 2011-04-15
  • 打赏
  • 举报
回复
刚才,单独在SDK3.0里面试了试,可以使用 nextInt(int n)!

应该是Eclipse的问题,我用的版本是:
Pulsar for Mobile Developers.
Version: Helios Service Release 2
Build id: 20110301-1815

(c) Copyright Pulsar Committers and others. 2011. All rights reserved.
Visit http://www.eclipse.org/pulsar/
sandeel 2011-04-15
  • 打赏
  • 举报
回复
查Java(TM) ME Platform SDK 3.0文档了,里面说有的:

nextInt(int n)
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
Gray_Sky 2011-04-15
  • 打赏
  • 举报
回复
不太了解me,但是应该是没有nextInt(int x)方法吧!~

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧