• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ko Ko Naing:



That will give you a NullPointerException...
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NullPointerException is occured because you not init value size of array.

chage code like this



This will help you.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will fail to compile - (use of uninitialized local).
Therefore, it will not give you a NullPointerException.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, i'm wrong.

Question

Please post your error in compile time...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!