wood burning stoves 2.0*
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 Spring in Action this week in the Spring 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: 105

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: 18669
    
    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)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Java Arrays to display String