TypeError:nextDouble():不能将self arg强制为java.util.Random.随机

2024-09-26 18:02:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我在jython中遇到了这个随机的java问题。我在用python编写bukkit插件。代码如下:

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

Tags: inself插件eventconfigisdefit
1条回答
网友
1楼 · 发布于 2024-09-26 18:02:55

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

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

^{}方法不是静态的,它不接受任何参数。您将不得不重新考虑如何使用“这个随机的java东西”(不清楚您在尝试做什么)。在

相关问题 更多 >

    热门问题