Bookmark Topic Watch Topic
  • New Topic

copying string arrays returned from functions(urgent)  RSS feed

 
sharath kv
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi
I have 2 classes as follows:
public class A
{
String sv[] = new String[1000];
// Add values into sv.............
.........................
.........................
.........................
B k = new B(); // Call Class B
B.cards_output(sv); // invoke a method in Class B
} // End of Class A
public class B
{
// general declaration
public String copy_sv[] = new String[1000];
......
......
......
......
public void cards_output(String sv[]) // function in class B
{
for(int i=0;i<sv.length();i++)
{
copy_sv=sv;
}
}
} // End of Class B
I can only use copy_sv[] only in the functions that i pass that value to, I need copy_sv[] to be accessible everywhere in the program.
Now when ever I try to make a reference to copy_sv[] elsewhere in the program I am getting a Null pointer exception.
I tried using cloneable interface with clone method but again got a null pointer exception.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi sharath ,
Welcome to JavaRanch, the absolute best site on the www for Java information. We don't have many rules around here, but we do have one. Please change your display name to a first and last name to comply with the JavaRanch Naming Policy. You can change it here.
Thank you for your cooperation.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Report post to moderator
Shareth:
Is this your actual code or did you retype it when you posted (I'm asking because I see several places where it won't compile...)
That being said, I don't see a problem in the code that you posted. Perhaps you inadvertently corrected it while retyping?
Perhaps if you cut-and-pasted the original code, we might be able to help a little better. And dont forget to surround your code with [ CODE ] and [ /CODE ] tags (It makes it easier to read....)
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Report post to moderator
Sharath, please don't post the same question in multiple forums. It wastes time for evceryone involved if they aren't aware of other answers that have been posted. Please post follow-ups here. Thanks.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!