java实践过程中问题汇总1

正确事例:

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
  String arr[][]=null;
  
   urlprocess processUrlprocess =new urlprocess();  
  arr= processUrlprocess.ReArray("http://market.finance.sina.com.cn/downxls.php?date="+this.time+"&symbol="+this.code);
System.out.println(Arrays.deepToString(arr));

 }

 

}

 

 


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 String[][] ReArray(String url)
 {
  String[][] resultsa;
  StringToArray sta=new StringToArray("\t");  
  
  try {
   ArrayList<String> newurllist=urlprocess(url); 
   resultsa=new String[newurllist.size()][];
   for (int i = 0; i <newurllist.size(); i++) {   
     resultsa[i]=sta.str2array((String)newurllist.get(i));   
   // results[i]= Arrays.copyOf(results[i], results[i].length+2);  
   
    // results[i][results.length-2]=process.getcode();
      //results[i][results.length-1]=process.gettime();  
  }
  //System.out.println(Arrays.deepToString(results));
   return resultsa;                                         ++++++++++
  } catch (Exception e) {
   // TODO: handle exception
  }
  return null;                                                ++++++++++
  
  
  
  
 }
}


class StringToArray {
 
private String split;
public StringToArray(String split)
{
 this.split=split;
}

  public String[] str2array(String s)
  {

        String str2array=s;

        //1. First method with split()
        // split(String Delimiter)
        String[] arr=str2array.split(this.split);
        //System.out.println("Array :"+arr.length);
       return arr;

    }
}

 

错误事例:

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++) {   
    results[i]=sta.str2array((String)newurllist.get(i));   
   results[i]= Arrays.copyOf(results[i], results[i].length+2);  
  // System.out.println(process.getcode());
   // results[i][results.length-2]=process.getcode();
     //results[i][results.length-1]=process.gettime();  
  }
  //System.out.println(Arrays.deepToString(results));
  } catch (Exception e) {
   // TODO: handle exception
  }
 
  
  
 }
}


class StringToArray {
 
private String split;
public StringToArray(String split)
{
 this.split=split;
}

  public String[] str2array(String s)
  {

        String str2array=s;

        //1. First method with split()
        // split(String Delimiter)
        String[] arr=str2array.split(this.split);
        //System.out.println("Array :"+arr.length);
       return arr;

    }
}


 

上面这段代码,我现在需要在类urlprocess中的ReArray方法中调用process类中的gettime方法,但是rearray方法输出后的结果是null,而我在main函数中调用该方法就可以正常输出,问题出现在什么地方,出问题的地方我使用 the problem 进行了注释,the problem1是在main函数中调用,the problem2是在rearray方法中调用,第一个可以正常输出,第二个输出为空,但是我现在需要在rearray方法中调用gettime方法,请问该怎么写

 

错误原因:在类中建立了对象,而调用的方法,没有传值

 

你可能感兴趣的:(java实践过程中问题汇总1)