import javax.swing.JOptionPane;
public class ArrayExceptionDemo
{
double num[] = new double[15];
int howManyNums;
String sHowMany;
String title = "Array Exception Demo";
public ArrayExceptionDemo()
{
fillArray();
{
public void fillArray() //MY ERRORS ARE HERE WITH IT PUBLIC, I Have it typed out just like my book says and have gone over the spelling with a fine tooth comb
{
sHowMany + JOptionPane.showInputDialog(null,
"How many random numbers do you wish to place in the array (15 max).",
title, JOptionPane.QUESTION_MESSAGE);
//Now we put the code that might generate an error inside a try block
try
{
//The parseInt will throw an exception if it doesn't get a valid int.
howManyNums = Integer.parseInt(sHowMany);
//If we try to go beyond our array bounds we will ger an exception!
//(This is a good example why we should use number.length
//in for loops that traverse arrays.)
for(int i = 0; i < howManyNums; ++i)
{
num[i] = Math.random();
System.out.println( num[i] );
}
}
//We use the superclass exception to catch everything!
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Error happened ",
"In the catch", 2);
//printStackTrace prints the exception to the command window.
e.printStackTrace();
}
}
public static void main(String args[] )
{
ArrayExceptionDemo theApp = new ArrayExceptionDemo();
System.exit(0);
}
}//It is also expecting a ";" at the end here.