public class Pxto{
    public getOp(){
       String str1="xxxx";
       String str2="xxxx";
       boolean bl=OPwriter.createTxtFile(str1,str2);
       //.....
      }
OPwriter没有实例对象!

解决方案 »

  1.   

    确定是没有被调用应为我的类1:public class OPwriter{
        public static boolean createTxtFile(String content,String file)
        {     
           System.out.printl("The file is creating...");
           //do something...
         }
    }
    并没有打印出来,而其文件也没有被创建,也没有报错
      

  2.   

    类2:
    public class Pxto{
        public getOp(){
           String str1="xxxx";
           String str2="xxxx";
           boolean bl=OPwriter.createTxtFile(str1,str2);
           //.....
          }你上面的这个方法写错了。
    public getOp()
    这里如果没有返回值应该写为:
    public void getOp()
      

  3.   

    sorry! 原来类2是这样的,我的写漏了的:
    类2:
    public class Pxto{
        public void getOp(){
           String str1="xxxx";
           String str2="xxxx";
           boolean bl=OPwriter.createTxtFile(str1,str2);
           //.....
          }
      

  4.   

    应该不是这个问题的
    当执行到boolean bl=OPwriter.createTxtFile(str1,str2);时,一定会被调用
    楼主一定是还有什么地方遗漏了
      

  5.   

    我检查了,没发现什么不对的地方!是不是IDE问题?郁闷啊
      

  6.   

    代码看上去非常正确。找不到原因。可在
    boolean bl=OPwriter.createTxtFile(str1,str2);

      //do something...
    前输出打印语句
    看看结果到底是哪个没有执行说不定是getOp()
      

  7.   

    getOp()执行了,是createTxtFile()没有执行
      

  8.   

    我觉得程序没问题,不会是你把System.out输出流打印到别的地方去了吧?呵呵
      

  9.   

    问题解决了,不过依然郁闷中我贴出来:
    原来的代码:
    public static boolean createTxtFile(String content,String thefile)       //根据filename 创建以content 为内容的文件
        {
          String str = content;    //文件内容
          String filename=thefile; //文件名
          System.out.println("File creating begin...");
          if(str==null || str.length()<0 || filename==null || filename.length()<0) {
                 System.out.println("the String Content or File Name is null...");
                 return false;
           }     try
           {
            
                  File f = new File(filename);
                  if(!f.exists())    //如果文件不存,则建立
                        f.createNewFile();
                   PrintWriter pw = new PrintWriter(new FileOutputStream(filename));
                   System.out.println("The File is Created...");
                   pw.println(str);//写内容
                   pw.close();
               }catch(IOException e)
               {
                e.printStackTrace();
                return false;
                }
            return true;
       }
    以上代码使createTxtFile()没被执行该过以后:
    public static boolean createTxtFile(String content,String thefile)       //根据filename 创建以content 为内容的文件
        {
            String str = content;    //文件内容
            String filename=thefile; //文件名
            System.out.println("File creating begin...");     try
           {
            if(str==null || str.length()<0 || filename==null || filename.length()<0) {
                System.out.println("the String Content or File Name is null...");
                return false;
           }
           File f = new File(filename);
           if(!f.exists())    //如果文件不存,则建立
           f.createNewFile();
           PrintWriter pw = new PrintWriter(new FileOutputStream(filename));
           System.out.println("The File is Created...");
           pw.println(str);//写内容
           pw.close();
        }catch(IOException e){
            e.printStackTrace();
            return false;
        }
        return true;
      }一切OK!郁闷啊
      

  10.   

    debug  跟踪一下就什么都知道了