everything else in my app works, but when I add
public void onClickRandomColor(View v) {
Random rRed = null;
Random rGreen = null;
Random rBlue = null;
int min = 0, max = 255;
int randomRed = rRed.nextInt(max - min + 1) + min;
int randomGreen = rGreen.nextInt(max - min + 1) + min;
int randomBlue = rBlue.nextInt(max - min + 1) + min;
Rset = randomRed;
Gset = randomGreen;
Bset = randomBlue;
}
to MainActivity.java and the ONCLICK line to activity_main.xml
<Button
android:id="@+id/btnRandom"
android:layout_below="@+id/btnChoose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:onClick="onClickRandomColor"
android:text="@string/random"/>
She force closes on me. There are plenty of other controls, the sliders use the Rset, Gset, and Bset just fine. It has to be something with my method of obtaining random integers.
new Random()instead of assigning null. You can’t call anything on null, you have to create the object.Your corrected code would look like this: