How do I throw an exception when I receive a signal?

Why does the following multidimensional array in Java throw a null pointer exception?

  • int[][] mdArray = new int[5][]; int[][] msArray = new int[4][]; int[] singleDArray = {1,2,3,4,5}; int[] singleDArray2 = {6,7,8,9,}; mdArray[4] = singleDArray; msArray[3] = singleDArray2; System.out.println("Before assigning multi dimensional mdArray Array" + mdArray[4][0]); System.out.println("Before assigning multi dimensional msArray Array" + msArray[3][0]); msArray = mdArray; System.out.println("Before assigning multi dimensional mdArray Array" + mdArray[4][0]); System.out.println("Before assigning multi dimensional msArray Array" + msArray[3][0]);  // This line throws null pointer exception and I have no clue. Please help me.

  • Answer:

    You set mdArray[4], but mdArray[3] is null. So when you set msArray = mdArray and try to access msArray[3], nothing is there.

William Oliver at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.