This program is to manipulate median of an array.it returns NullPointerException.i have tried it .plz any1 to rectify the bug.
thanxs in advance.
import java.io.*; public class media { @SuppressWarnings("null") public static void main(String[] args) { int i=0,j=0,n=0; float median; float t; int []a=null; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the number of items\n"); try { n=Integer.parseInt(br.readLine()); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Input values \n"); for( i=1;i<n;i++) try { a[i]=Integer.parseInt(br.readLine()); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } /* Reading items in array a */ /* Sorting begins */ for (i = 1 ; i <= n-1 ; i++) { /* Trip-i begins */ for (j = 1 ; j <= n-i ; j++) { if (a[j] <= a[j+1]) { /* Interchanging values */ t = a[j]; a[j] = a[j+1]; a[j+1] = (int) t; } else continue ; } } /* sorting ends */ /* calculation of median */ if ( n % 2 == 0) median = (float) ((a[n/2] + a[n/2+1])/2.0) ; else median = a[n/2 + 1]; /* Printing */ for (i = 1 ; i <= n ; i++) { System.out.println(a[i]); } System.out.println("\n\nMedian is " +median); } } Exception in thread "main" java.lang.NullPointerException at media.main(media.java:26)