• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

java.lang.NullPointerException .. Why and How to fix it?

 
Greenhorn
Posts: 26
Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


It becomes problem when i want to input the name ..

example :
How many names do you want to input : 2

Name 1 : John Park
// enter ,, and the cmd will show :
Exception in thread "main" java.lang.NullPointerException at SearchingName.main(SearchingName.java:21)

How to fix it??
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you create an array of object references, the default value of each one is null.

In Java, you don't really have a multidimensional array. Instead you create an array where each element in the array is a reference to another array.

So when you define an array like String[][] temp = new String[3][3], for example, temp is a reference to an array containing 3 objects. Each of those objects is a reference to an array containing 3 Strings. But initially each of those referneces is null.
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic