TypeError:nextDouble():不能将self arg强制转换为java.util.Random [英] TypeError: nextDouble(): self arg can't be coerced to java.util.Random

查看:99
本文介绍了TypeError:nextDouble():不能将self arg强制转换为java.util.Random的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jython中遇到了有关Random Java的问题.我正在用python编写bukkit插件.这是代码:

I'm having problem with this Random java thing in jython. I'm coding bukkit plugins in python. Here's the code:

class hween(PythonPlugin):
   def CandyChance(self):
       chance = self.cfg.getDouble("main.candydropchance", 50) / 100 #in config, it's 10, so I must do this to get it like 0.1...
       return chance

   @hook.event("block.BlockBreakEvent", "HIGHEST")        
   def onBlockBreakEvent(event):
       chance = pyplugin.CandyChance()
       print chance #When I print chance out, it's 0.1 (10 is in config) which is good I believe
       if(Random.nextDouble("%s"%chance)):
          #do something

推荐答案

这是一个交互式Jython会话,它会重现您的错误:

Here is an interactive Jython session that reproduces your error:

Jython 2.7b1 (default:ac42d59644e9, Feb 9 2013, 15:24:52)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_25
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.util import Random
>>> Random.nextDouble("0.1")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: nextDouble(): self arg can't be coerced to java.util.Random
>>> Random.nextDouble()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: nextDouble(): expected 1 args; got 0
>>> Random().nextDouble()
0.3442604857098639
>>>

nextDouble() 方法不是静态的,并且不接受任何参数.您将不得不重新考虑如何使用这个随机的Java东西"(尚不清楚您要做什么).

The nextDouble() method is not static and it does not take any arguments. You'll have to rethink how you use "this Random java thing" (it is not clear what you are trying to do).

这篇关于TypeError:nextDouble():不能将self arg强制转换为java.util.Random的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆