Bookmark Topic Watch Topic
  • New Topic

copying string arrays returned from function(urgent)

 
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.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Report post to moderator
I don't think this is really an I/O or Streams issue, but we'll dig a bit deeper and find out the problem anyway.
I take it that these are static members in B, right? So B.cards_output won't work.
Also, where are you getting the NullPointerException exactly? Are you creating new instances of B and then doing someBInstance.copy_sv?
 
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!