因此,我在其他地方查看了如何生成随机数,并将其放入 Android 应用程序中。我希望这可以工作,但遗憾的是,它与这个 LogCat 崩溃:
11-03 17:06:48.930: W/dalvikvm(8327): threadid=1: thread exiting with uncaught exception (group=0x41ff0300)
11-03 17:06:48.938: E/AndroidRuntime(8327): FATAL EXCEPTION: main
11-03 17:06:48.938: E/AndroidRuntime(8327): java.lang.IllegalArgumentException
11-03 17:06:48.938: E/AndroidRuntime(8327): at java.util.Random.nextInt(Random.java:187)
11-03 17:06:48.938: E/AndroidRuntime(8327): at com.spng453.randomnum.RandomNumber$1.onClick(RandomNumber.java:24)
11-03 17:06:48.938: E/AndroidRuntime(8327): at android.view.View.performClick(View.java:4084)
11-03 17:06:48.938: E/AndroidRuntime(8327): at android.view.View$PerformClick.run(View.java:16966)
11-03 17:06:48.938: E/AndroidRuntime(8327): at android.os.Handler.handleCallback(Handler.java:615)
11-03 17:06:48.938: E/AndroidRuntime(8327): at android.os.Handler.dispatchMessage(Handler.java:92)
11-03 17:06:48.938: E/AndroidRuntime(8327): at android.os.Looper.loop(Looper.java:137)
11-03 17:06:48.938: E/AndroidRuntime(8327): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-03 17:06:48.938: E/AndroidRuntime(8327): at java.lang.reflect.Method.invokeNative(Native Method)
11-03 17:06:48.938: E/AndroidRuntime(8327): at java.lang.reflect.Method.invoke(Method.java:511)
11-03 17:06:48.938: E/AndroidRuntime(8327): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-03 17:06:48.938: E/AndroidRuntime(8327): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-03 17:06:48.938: E/AndroidRuntime(8327): at dalvik.system.NativeStart.main(Native Method)
11-03 17:06:51.376: I/Process(8327): Sending signal. PID: 8327 SIG: 9
我已经尝试了我能想到的一切来让它工作,但没有任何效果。这是代码:
private OnClickListener Gen = new OnClickListener() {
public void onClick(View v) {
Random rand;
rand = new Random();
EditText maxin = (EditText)findViewById(R.id.max);
EditText minin = (EditText)findViewById(R.id.min);
TextView out = (TextView)findViewById(R.id.out);
int max = Integer.parseInt(maxin.getText().toString().trim());
int min = Integer.parseInt(minin.getText().toString().trim());
out.setText(Integer.toString(rand.nextInt(max-min) + min));
}
};