• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

just check this...

 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
guess the error/exception generated in this code:
//code
1 ublic class Base{
2:
3: int array[];
4:
5: private void test() {
6: System.out.println("Value is: " + array[0]);
7: }
8:
9: static public void main(String[] a) {
10: new Base().test();
11: }
12:
}
//code end
i wasn't exactly expecting this exception. any comments....
 
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right now i can think of 2 exceptions
one is ArrayIndexOutOfBounds and the other one is can't call that method because void type does not return a value.
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh another one is static is before public , don't know about that type of error though
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
scratch my previouse replys to this didn't look well you'll get an error saying that it's not been initilized so the reference is null since arrays are considered to be objects in java .
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem I see is that the array doesn't know it's size...
 
Anshuman Acharya
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well val got it! it is a NullPointerException...
well done, val! if you did it without the compiling...
 
Anshuman Acharya
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that this error comes coz in line 6 the toString() method of the array[0] is called but since it is a null...
i was just curious about what other exceptions/errors can be thrown in different operations with uninitialized arrays...
any comments?
 
reply
    Bookmark Topic Watch Topic
  • New Topic