Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-13-2008, 08:15 PM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
java.lang.NullPointerException
String arrays are initialized with null. I tried the following which didn't work for me. What caused this exception?

Code:
String s1[] = new String[5]; System.out.println(s1[0]); String str = s1[0].toUpperCase(); System.out.println(str);
Output:
Code:
Exception in thread "main" java.lang.NullPointerException
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-13-2008, 08:39 PM
Member
 
Join Date: Jan 2008
Posts: 24
afsina is on a distinguished road
because unlike primitive types, creating an array of Strings does NOT creates actual string objects. it creates only empty holders (references with null values) you will need to assign actual Strings before doing operaitons like toUpperCase();

Make a search with "initializing String Arrays Java" in google. or Read here, a very nice Java resource

Last edited by afsina : 01-13-2008 at 08:42 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
java.lang.NullPointerException stevemcc AWT / Swing 2 02-08-2008 10:01 AM
ArrayList: Exception in thread "main" java.lang.NullPointerException susan New To Java 1 07-16-2007 07:32 AM
AWT-EventQueue-0 java.lang.NullPointerException susan NetBeans 2 07-16-2007 07:21 AM
java.lang.NullPointerException Felissa Advanced Java 1 07-05-2007 07:02 AM
Error Java.lang.NullPointerException in JBuilder2006 Jack Other IDEs 2 07-02-2007 03:29 AM


All times are GMT +3. The time now is 09:32 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org