双击之后老是出现:could not find the main class.    Program will exit.其它程序打包都没有问题,就单单这一个出现问题,我不知道是为什么,麻烦各位高手指点,我也手工打包过,还是不行,程序如下:package yuebao;import java.io.*;
import java.text.*;import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;public class CallRecord
{
public static void main(String[] args)
{
int b=0;
POIFSFileSystem pfs=null;
HSSFWorkbook hwb=null;
try
{
pfs=new POIFSFileSystem(new FileInputStream("CallRecord(Running).xls"));
hwb=new HSSFWorkbook(pfs);
HSSFSheet sheet=hwb.getSheetAt(0);
int rowNum;
int i;
  String[] date=new String[3100];
  double[] record=new double[3100];
  double[] percent=new double[3100];
  rowNum = sheet.getLastRowNum();
  //System.out.println(rowNum);
  for (i = 4; i <= rowNum; i++) {
  //System.out.println(sheet.getRow(i).getCell((short)0).getDateCellValue().toLocaleString());
   date[i]=sheet.getRow(i).getCell((short)0).getDateCellValue().toLocaleString();
   HSSFCell cl=sheet.getRow(i).getCell((short)1);
   record[i]=Double.parseDouble(cl.toString().trim());
   HSSFCell c2=sheet.getRow(i).getCell((short)2);
   percent[i]=Double.parseDouble(c2.toString().trim());
   //System.out.println(i+"---"+date[i]+"---"+record[i]+"---"+percent[i]);
   }
  
  HSSFWorkbook wb=new HSSFWorkbook();
FileOutputStream fo=new FileOutputStream("callRecord.xls");
HSSFSheet ht=wb.createSheet("彩铃月报");
HSSFRow r1 = ht.createRow((short)0);
        HSSFCell c1 = r1.createCell((short)0);
        c1=r1.getCell((short)0);
        c1.setCellValue("日期1");
        HSSFCell c2 = r1.createCell((short)1);
        c2=r1.getCell((short)1);
        c2.setCellValue("日期2");
        HSSFCell c3 = r1.createCell((short)2);
        c3=r1.getCell((short)2);
        c3.setCellValue("忙时试呼次数");
        HSSFCell c4 = r1.createCell((short)3);
c4=r1.getCell((short)3);
c4.setCellValue("忙时应答率");
  double[] result1=new double[93];
  int start=4;
  int end=96;
  int n=0;
  for(int j=start;j<=end;j++)
  {
  int m=n++;
  result1[m]=0;
  //System.out.println(m);
  for(int k=0;k<4;k++)
  {
  result1[m]=result1[m]+record[j+k];
  
  }
  //System.out.println("result1["+m+"]:"+result1[m]);
  //System.out.println("j:"+j);
  if((end-j)==0)
  {
  b++;
  float max=(float)result1[0];
  float per=(float)0;
  int l1=0;
  for(int l=1;l<result1.length;l++)
  {
  if(max<result1[l])
  {
  max=(float)result1[l];
  l1=l;
  }
  }
  for(int t=0;t<4;t++)
  {
  per=(float)(per+percent[96*((j/96)-1)+4+l1+t]);
  //System.out.println(date[96*((j/96)-1)+4+l1+t]+"---"+record[96*((j/96)-1)+4+l1+t]+"---"+percent[96*((j/96)-1)+4+l1+t]);
  }
  DecimalFormat df=new DecimalFormat("##.00");
  //System.out.println("max-----"+max+"per:"+df.format(per*100/4));
  
  if(end+3<=rowNum){
  HSSFRow r2 = ht.createRow((short)b);
        HSSFCell hc1 = r2.createCell((short)0);
        hc1=r2.getCell((short)0);
        hc1.setCellValue(date[96*((j/96)-1)+4+l1]);
        HSSFCell hc2 = r2.createCell((short)1);
        hc2=r2.getCell((short)1);
        String[] s=date[96*((j/96)-1)+4+l1].split(" ");
        hc2.setCellValue(s[0]);
        HSSFCell hc3 = r2.createCell((short)2);
        hc3=r2.getCell((short)2);
        hc3.setCellValue(max);
        HSSFCell hc4 = r2.createCell((short)3);
hc4=r2.getCell((short)3);
hc4.setCellValue(df.format(per*100/4)+"%");
  end=j+96;
  }
  else
  {
  break;
  }
  j=j+3;
  //System.out.println("come in");
  n=0;
  }
  }
  

wb.write(fo);
fo.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}

解决方案 »

  1.   

    你采用了 Apache POI 的外置包,需要自己创建 MANIFEST.MF 文件,在里面写上Manifest-Version: 1.0
    Created-By: 1.5.0_01 (Sun Microsystems Inc.)
    Main-Class: yuebao.CallRecord
    Class-Path: lib/poi-3.0-rc4-20070503.jar(写上POI jar的文件名,我这里仅作示例,若还有其他的使用空格分开)建好后,在这个文件下敲几个回车。使用 Eclipse 的 Export 功能,在你按了三次“Next”(JAR Manifest Specification)后,选择 Use existing manifest from workspace,Browse 找到刚才新建的那个文件。按 Finish 结束。找到生成的 jar 文件,与该文件平级建一个 lib(名字与 Class-Path 中的一致)目录,将外置的 jar 包拷进去,再退回上一层,这个 jar 文件就可以运行了。不知道我啰嗦了那么多,明白了吗?
      

  2.   

    看懂了,也试了,产生的那个jar文件可以运行,但就是没有按预期产生一个excel文件
    源文件是没有错误的,已经验证
      

  3.   

    http://www.jopener.cn/category/installers-generators/
      

  4.   

    pfs=new POIFSFileSystem(new FileInputStream("CallRecord(Running).xls"));---------------------------------------------------------------------------你都打成jar包了~这个文件还怎么生成~
    你最好改用绝对路径~
      

  5.   

    这个你在命令行下用 java -jar xxx.jar 运行看看,是否有异常显示。
      

  6.   

    to: daniel_kaka相对路径文件可以生成的,我试过,生成的位置与 jar 同级。
      

  7.   

    其实在之前我已经打包过一次了,不过是很久以前了,那个时候的jar是可以正确运行并产生结果的,但是今天我只是改了一下程序中的一个数字,就是把原来的
                        String[] date=new String[3000];
      double[] record=new double[3000];
      double[] percent=new double[3000];里的3000改成3100后,再翻译,导出jar,然后jar就不能正确运行了,真不知道是怎么一回事
      

  8.   

    可能有异常产生了,用我上面说到的 java -jar xxx.jar 运行看看,若有异常会在控制台上显示的。你直接点击 jar 文件是调用 javaw 进行处理的,哪怕有异常也是以几乎看不到的速度一闪而过的。
      

  9.   

    java.io.IOException: Invalid header signature; read 7011577315731788834, expecte
    d -2226271756974174256
            at org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockRead
    er.java:100)
            at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSyste
    m.java:84)
            at yuebao.CallRecord.main(CallRecord.java:18)
    产生了以上错误
      

  10.   

    对吧,还是有错吧~~,不大使用 POI,不好意思,没有办法帮你查错了。