Hello guys..
I am new to jave and looking for some help...
// here is the application
import javax.swing.JOptionPane;
public class rainfall
{
public static void main(String args[])
{
//the first array 4 weeks
int a[][]=new int[4][]; //the user should determine the second array which is the reading of rainfall amount per week.
int rainfall_per_week, reading,total_rain_month=0, avg_rainfall_per_week;
int i,j,k; //loops
for(i=0;i<a.length;i++){
JOptionPane.showMessageDialog(null,"Week "+(i+1));
rainfall_per_week=Integer.parseInt(JOptionPane.sho wInputDialog("Enter the number of rainfall for week "+(i+1)+" "));
for(j=0; j<rainfall_per_week; j++){
reading=0;
k=0;
//reset k and reading to 0
while(k<rainfall_per_week){ //quit when the user enters the amount in the required cols
reading=Integer.parseInt(JOptionPane.showInputDial og("Enter the reading for " + (j+1)));
reading++;
k++;
}
a[i][j]=reading; //asssign the total rainfall per week to row i col j
avg_rainfall_per_week=a[i][j]/rainfall_per_week; //calculate the average per week
total_rain_month+=a[i][j]; //calculate the total amount for the whole month
// break;
}
}
for(i=0;i<a.length;i++){
for(j=0;j<a[i].length;j++){
JOptionPane.showMessageDialog(null,"Per Week "+a[i][j]);
}
JOptionPane.showMessageDialog(null,"The average rainfall for week " +(i+1)+" :");
}
JOptionPane.showMessageDialog(null,"The total rainfall for the whole month is :"+total_rain_month);
}
}
i can run it but the prog terminates after the while loop...
Error: Exception in thread "main" java.lang.NullPointerException
at rainfall.main(rainfall.java:44)
Thanks :)
