我在Windows中使用Net Beans创建了程序,它运行正常。当我将代码单独传输到HP-UX时,我遇到了以下错误。
对不起我的问题,我是java新手。
Exception in thread "main" java.lang.NoClassDefFoundError: javaapplication2/JavaApplication2
Caused by: java.lang.ClassNotFoundException: javaapplication2.JavaApplication2
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
Could not find the main class: javaapplication2.JavaApplication2. Program will exit.
编译代码给了我两个类:
JavaApplication2$1.class
JavaApplication2.class
MANIFEST.MF
Main-Class: javaapplication2.JavaApplication2
我还在class,manifest.mf和code所在的主目录中执行了jar命令。
/opt/java6/bin/jar -cvfm app.jar MANIFEST.MF *class
我想知道可能是遇到错误的原因。
package javaapplication2;
import java.io.File;
import java.io.FileReader;
import java.io.*;
import java.io.PrintStream;
public class JavaApplication2 {
/**
* @param args the command line arguments
* @return
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
File directory = new File("/idmp/MJMN/ICMS_to_ZERORATED/src");
//list only files
File files[] = directory.listFiles(new FileFilter() {
@Override
public boolean accept (File pathname) {
String name = pathname.getName();
return name.startsWith("S") && pathname.isFile();
}
}
);
//read files line by line
for (File d : files) {
FileReader fr;
fr = new FileReader(d);
BufferedReader br;
br = new BufferedReader(fr);
String line;
String file_name = d.getName();
PrintStream ps = new PrintStream("/idmp/MJMN/ICMS_to_ZERORATED/dst/" + file_name);
PrintStream orig = System.out;
System.setOut(ps);
while ((line = br.readLine()) != null){
String RCDTYP = line.substring(0,2);
int RCDTYP_int = Integer.parseInt(RCDTYP);
if (RCDTYP_int == 50 ){ //read line with '50
//System.out.println(line);
//String CALLING_NUMBER = "";
//String CALLED_NUMBER = "";
//GET BILLABLE_CALL_DUR_MIN
String tmp_emrtyp = line.substring(175,180);
String emrtyp = tmp_emrtyp.replaceAll("\\s+","");
int emrtyp_int = Integer.parseInt(emrtyp);
String emrtmm = line.substring(127,138);
String emrtss = line.substring(138,141);
String emrtmm_no_zero = emrtmm.replaceFirst("^0+(?!$)", "");
int emrtmm_int = Integer.parseInt(emrtmm_no_zero);
String emrtss_no_zero = emrtss.replaceFirst("^0+(?!$)", "");
int emrtss_int = Integer.parseInt(emrtss_no_zero);
int BCDM;
if (emrtyp_int == 1001){
BCDM = 1;
} else {
BCDM = emrtmm_int + emrtss_int;
}
//String tmp_BCDM = Integer.toString(BCDM);
String Space_20 = String.format("%20s", "");
String Space_29 = String.format("%29s", "");
String Space_9 = String.format("%9s", "");
String Space_5 = String.format("%5s", "");
String Space_2 = String.format("%2s", "");
String Space_1 = String.format("%1s", "");
String Space_8 = String.format("%8s", "");
String Space_7 = String.format("%7s", "");
//Leading zeros
String str_BCDM = String.format("%011d",BCDM);
String CALLING_NUMBER =line.substring(2,22);
String CALLED_NUMBER =line.substring(32,52);
String CALL_DATETIME =line.substring(92,107);
String SERVICE_NUMBER =Space_20;
String CUSTOMER_NUMBER =Space_9;
String RATE_PLAN_CODE =Space_5;
String BILLABLE_CALL_DUR_MIN =str_BCDM;
String BILLABLE_CALL_DUR_SEC ="000";
String ACTUAL_CALL_DUR_MIN =emrtmm;
String ACTUAL_CALL_DUR_SEC =emrtss;
String RATED_AMT ="000000000000000";
String JURISDICTION_CODE =Space_2;
String CALL_TYPE =tmp_emrtyp;
String PEAK_OFFPEAK_INDICATOR =Space_1;
String BILLING_CYCLE ="00";
String SERVICE_CODE =line.substring(57,59);
String UNIT_OF_MEASURE ="MIN ";
String CURRENCY_CODE ="PHP";
String FROM_CELL =Space_5;
String TO_CELL =Space_5;
String FROM_PLACE =Space_5 + Space_5;
String TO_PLACE =Space_5 + Space_5;
String BILLDATE =Space_8;
String BASESTATION =Space_5 + Space_5;
String DATE_LAST_UPDATE ="000000000";
String TIME_LAST_UPDATE ="0000000";
String USAGE_TYPE_GLCODE =Space_7;
String TOLLFILE =Space_8;
String Filler =Space_29 + "|";
System.out.println(CALLING_NUMBER +
CALLED_NUMBER +
CALL_DATETIME +
SERVICE_NUMBER +
CUSTOMER_NUMBER +
RATE_PLAN_CODE +
BILLABLE_CALL_DUR_MIN +
BILLABLE_CALL_DUR_SEC +
ACTUAL_CALL_DUR_MIN +
ACTUAL_CALL_DUR_SEC +
RATED_AMT +
JURISDICTION_CODE +
CALL_TYPE +
PEAK_OFFPEAK_INDICATOR +
BILLING_CYCLE +
SERVICE_CODE +
UNIT_OF_MEASURE +
CURRENCY_CODE +
FROM_CELL +
TO_CELL +
FROM_PLACE +
TO_PLACE +
BILLDATE +
BASESTATION +
DATE_LAST_UPDATE +
TIME_LAST_UPDATE +
USAGE_TYPE_GLCODE +
TOLLFILE +
Filler
);
//closing 'if'
}
//String emr = line.substring(0,2);
//System.out.println(emr);
} br.close();
fr.close();
System.setOut(orig);
ps.close();
}
/**read file **/
/** try {
FileInputStream fStream = new FileInputStream(args[10]);
BufferedReader in = new BufferedReader (new InputStreamReader(fStream));
while (in.ready()) {
System.out.println (in.readLine());
}
in.close();
} catch (IOException e) {
System.out.println("File input error");
} **/
}
}
答案 0 :(得分:0)
我只是通过删除包名来修复错误。