java 一个类中的方法调用另一个类的方法返回空值,怎么解决?
本帖最后由 ewili 于 2013-02-18 12:20:24 编辑
我现在需要在类urlprocess中的ReArray方法中调用process类中的gettime方法,但是rearray方法输出后的结果是null,而我在main函数中调用该方法就可以正常输出,问题出现在什么地方,出问题的地方我使用 the problem 进行了注释,the problem1是在main函数中调用,the problem2是在rearray方法中调用,第一个可以正常输出,第二个输出为空,但是我现在需要在rearray方法中调用gettime方法,请问该怎么写 下面是代码
package myown;
import java.lang.reflect.Array;
import java.net.*;
import java.util.ArrayList;
import java.util.Arrays;
//import java.util.Set;
//import java.util.StringTokenizer;
//import java.util.concurrent.ForkJoinPool.ManagedBlocker;
import java.io.*;
public class urlgetcontent {
/**
* @param args
*/
public static void main(String[] args) {
//System.out.println(arr);
process process=new process();
process.setcode("sh600000");
process.Settime("2013-02-08");
System.out.println(process.gettime()); // the problem1
process.pracess();
}
}
class process
{
private String time;
private String code;
public void Settime(String time)
{
this.time=time;
}
public void setcode(String code)
{
this.code=code;
}
public String gettime()
{
return this.time;
}
public String getcode()
{
return this.code;
}
public void pracess() {
// TODO Auto-generated constructor stub
urlprocess processUrlprocess =new urlprocess();
processUrlprocess.ReArray("http://market.finance.sina.com.cn/downxls.php?date="+this.time+"&symbol="+this.code);
}
}
class urlprocess
{
public ArrayList<String> urlprocess(String url) throws Exception
{
URL oracle = new URL(url);
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String inputLine;
ArrayList<String> man=new ArrayList<String>();
while ((inputLine = in.readLine()) != null)
{
man.add(inputLine);
}
man.remove(0);
return man;
}
// #pointer
public void ReArray(String url)
{
process process=new process();
StringToArray sta=new StringToArray("\t");
try {
System.out.println(process.gettime()); //the problem2
ArrayList<String> newurllist=urlprocess(url);
String[][] results=new String[newurllist.size()][];
for (int i = 0; i <newurllist.size(); i++) {