Re: add new element in array
Quote:
i got error message java.lang.NullPointerException null
Please post the full text of the error message. Your edited version leaves out the source line number.
Look at the error message, find the line number where the error occurs and then look at that line in the source and find what variable on that line has a null value. Backtrack in your code to find why that variable does not have a valid value.
Re: add new element in array
You can basically also do as well
/* only for testing */
public class main{
public static void main (String[] args){
int array[]= {2, 5, 7, 8, 9}
System.out.println(array[2]);
}
}
Re: add new element in array
Another tip is to look at each controlling variable in turn, and check where it is being initialized, changed and used.
Do that with k, place and index, for example.
;-)