Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Arrays to display String

 
Sriram Sreedhar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 105
IntelliJ IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Strachan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic