File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How Do I Pass a String Array to the Constructor of Another Class? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How Do I Pass a String Array to the Constructor of Another Class?" Watch "How Do I Pass a String Array to the Constructor of Another Class?" New topic
Author

How Do I Pass a String Array to the Constructor of Another Class?

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I have a String Array 'to':

and I am trying to pass this String array to the constructor of another class; Address is an abstract class and I use the javax.mail.internet.InternetAddress class:
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
You need to put in loop, then you will get an array of InternetAddresses... Like this...


Hope it helps...

Or am I misunderstanding you, since it's incredibly easy...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Ko Ko Naing:



That will give you a NullPointerException...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
NullPointerException is occured because you not init value size of array.

chage code like this



This will help you.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
It will fail to compile - (use of uninitialized local).
Therefore, it will not give you a NullPointerException.


Tony Morris
Java Q&A (FAQ, Trivia)
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Originally posted by Tony Morris:
It will fail to compile - (use of uninitialized local).
Therefore, it will not give you a NullPointerException.



Please post your code to more information to solve problem...
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8876

Originally posted by somkiat puisungnoen:



Please post your code to more information to solve problem...




Why code? Tony is saying that the code above with uninitialized array will not compile and so NullPointerException will *not* be thrown beacuse program cannot run.
[ October 15, 2004: Message edited by: Pradeep Bhat ]

Groovy
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Ok, i'm wrong.

Question

Please post your error in compile time...
 
jQuery in Action, 2nd edition
 
subject: How Do I Pass a String Array to the Constructor of Another Class?
 
Similar Threads
UDP
declare a variable
Passing a recordset to a class
inheritance homework assignment - im stuck
Constructor