This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java Arrays to display String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Arrays to display String " Watch "Java Arrays to display String " New topic
Author

Java Arrays to display String

Sriram Sreedhar
Greenhorn

Joined: Mar 24, 2012
Posts: 4
Java Gurus,

Running a simple Java program to display string values :

================Books.java============


==============CallBooks.java===============

=====================================

run:
B1[i].Title
is written by
B1[i].Author B1[i].Title
is written by
B1[i].Author BUILD SUCCESSFUL (total time: 0 seconds)
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 104

It gave you NullPointerException because you haven't create an instance of Book yet. You've just declare a Book typed array that can store 3 items in it.


Website: Learn Java by Examples
Paul Strachan
Greenhorn

Joined: Oct 24, 2004
Posts: 10

creates an array object with length == 3, however the elements are null.

creates an array object with length == 3, and each element is a "Books"

or...

etc

Also, your while loop will execute infinitely (u forgot to increment 'x').
Sriram Sreedhar
Greenhorn

Joined: Mar 24, 2012
Posts: 4
I edited the code above :-


Not sure what i am missing:-

I get the below result .

B1[i].Title
is written by
B1[i].Author B1[i].Title
is written by
B1[i].Author BUILD SUCCESSFUL (total time: 0 seconds)

Any clues ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Any clues to what? The program is printing out exactly what you told it to print out. You seem to have a question about that, so it would help if you asked it.
Sriram Sreedhar
Greenhorn

Joined: Mar 24, 2012
Posts: 4
Yea, Got the results :--

Title Java Complete Reference
is written by Author Herbert Schildt
Title Thinking in Java
is written by Author Bruce Eckel
Title Java for Dummies
is written by Author Barry Burd

Made changes to the code above
Sriram Sreedhar
Greenhorn

Joined: Mar 24, 2012
Posts: 4
Sriram Sreedhar wrote:Java Gurus,

Running a simple Java program to display string values :

================Books.java============


==============CallBooks.java===============

=====================================

run:
Title Java Complete Reference
is written by Author Herbert Schildt
Title Thinking in Java
is written by Author Bruce Eckel
Title Java for Dummies
is written by Author Barry Burd
BUILD SUCCESSFUL (total time: 1 second)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Arrays to display String
 
Similar Threads
Exercise of he book Head First Java
Problem with the main class!
Error message
How do you use code tags?