- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 NoClassDefFoundError 方面遇到了一些真正的麻烦,并且我正在努力了解原因以便修复它。我认为我已经正确设置了类路径,但也许我遗漏了一些东西。
这是我的错误:
这是我的代码(我已将所有对我的用户个人资料的直接引用替换为 [USER]):
此外,这通常是从我创建的 UI 而不是命令路径调用的,但由于没有收到错误,我将其修改为从命令窗口运行以进行测试......因为我还不能完全弄清楚 log4j。
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.*;
import java.sql.SQLException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.log4j.Logger;
public class FilePrepMainStart {
//declare variables on the class level
static String fullinpath, fulloutpath, inpath, outpath, infilename, outfilename, outorigfn, delimiter, logfn;
static boolean istextfile, isexcelfile, addrecid;
//static Logger log;
//Create contructor with arguments
public void FilePrepMainStart(String in, String out, boolean txt, boolean exl, boolean rec, String delim) {
this.fullinpath = in;
this.fulloutpath = out;
this.istextfile = txt;
this.isexcelfile = exl;
this.addrecid = rec;
this.delimiter = delim;
}
private static String getPath(String in) {
//Attempts to extract the directory path from the full file path
Pattern pathPattern = createPattern("^([a-z]\\:.*\\\\)([a-zA-Z0-9 \\_\\$\\!\\?\\+\\%\\#\\@\\)\\(\\-\\.]+\\.[a-zA-Z0-9]{3,4})$");
Matcher filePath = pathPattern.matcher(in);
if (filePath.find()){
return filePath.group(1);
}
else {
return null;
}
}
private static String getFileName(String in) {
//Attempts to extract the sile name from the full file path
Pattern namePattern = createPattern("^([a-z]\\:.*\\\\)([a-zA-Z0-9 \\_\\$\\!\\?\\+\\%\\#\\@\\)\\(\\-\\.]+\\.[a-zA-Z0-9]{3,4})$");
Matcher filename = namePattern.matcher(in);
if (filename.find()){
return filename.group(2);
}
else {
return null;
}
}
private static Pattern createPattern(String pattern){
//Creates a compiled Pattern object from a String pattern
//args- pattern: String containing regex pattern to be compiled
Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
return p;
}
public static String appendOut(String name, String append) {
//Adds the string "append" to the file name on output.
//First checks for a file extension
//Used to create a "_Clean" and "_Original" file
Pattern filePattern = createPattern("(.*)(\\.[a-z0-9]{3,4})$");
Matcher fileMatcher = filePattern.matcher(name);
String outfilename = name;
if (fileMatcher.find()) {
outfilename = fileMatcher.group(1) + append + fileMatcher.group(2);
}
else {
outfilename = outfilename + append;
}
return outfilename;
}
public static String appendOut(String name, String append, boolean excludeext) {
//Overloaded appendOut to allow prevention of adding extension back into the fn
//Adds the string "append" to the file name on output.
//First checks for a file extension
//Used to create a "_Clean" and "_Original" file
//boolean excludeext: True to exclude adding the file extension back into the file name
//False for default (non-overloaded) functionality
Pattern filePattern = createPattern("(.*)(\\.[a-z0-9]{3,4})$");
Matcher fileMatcher = filePattern.matcher(name);
String outfilename = name;
if (fileMatcher.find() && excludeext) {
outfilename = fileMatcher.group(1) + append;
}
else if (fileMatcher.find()) {
outfilename = fileMatcher.group(1) + append + fileMatcher.group(2);
}
else {
outfilename = outfilename + append;
}
return outfilename;
}
private static int chkEXLFile(String name) {
//Checks Excel file type
String pattern = "(.*)\\.([a-z0-9]{3,4})$";
String filename = name;
Pattern p = createPattern(pattern);
Matcher chkFile = p.matcher(filename);
if (chkFile.find()){
String file_ext = chkFile.group(2).toLowerCase();
if (file_ext.equals("xls")) {
//XLS file
return 0;
}
else if (file_ext.equals("xlsx")) {
//XLSX File
return 1;
}
else {
//Unrecognized - Not XLS or XLSX file
return -1;
}
}
else {
//Unrecognized - Not XLS or XLSX file
return -1;
}
}
public static void openXLSFileStream(String input, String output, boolean rec, String worksheet) throws FileNotFoundException, IOException {
//Opens input and output streams and kicks off processing
FileInputStream in = new FileInputStream(input);
HSSFWorkbook inbk = new HSSFWorkbook(in);
FileOutputStream out = new FileOutputStream(output);
HSSFWorkbook outbk = new HSSFWorkbook();
if (rec) {
processXLSFileWithRecID(in, inbk, out, outbk, worksheet);
}
else {
}
}
private static void processXLSFileWithRecID(FileInputStream in, HSSFWorkbook inbk, FileOutputStream out, HSSFWorkbook outbk, String worksheet) throws FileNotFoundException, IOException {
/* Reads in and loops through each excel cell to clean it
* Need to add functionality to create a new workook, could be added for each part of the loop
*/
Pattern pattern = createPattern("[^-a-z_0-9\"/\\t\\.#@\\|, ]");
int sheetnum = -1;
int sheets = inbk.getNumberOfSheets();
//Get the worksheet number for the worksheet requested
for (int i = 0; i < sheets; i++) {
if (worksheet.equals(inbk.getSheetName(i))) {
sheetnum = i;
break;
}
}
//To Do: If no worksheet is present, sheetnum will be -1, and an error should be raised
if (sheetnum == -1) {}
HSSFSheet sheet = inbk.getSheetAt(sheetnum);
int rows = sheet.getPhysicalNumberOfRows();
HSSFSheet outsheet = outbk.createSheet();
//Loop through each row of the sheet
for (int r = 0; r < rows; r++) {
HSSFRow row = sheet.getRow(r);
if (row == null) {
continue;
}
HSSFRow outrow = outsheet.createRow(r);
int cells = row.getPhysicalNumberOfCells();
//Loop through each cell of the sheet
for (int c = 0; c < cells; c++) {
HSSFCell cell = row.getCell(c);
String s = null;
HSSFCell outcell = outrow.createCell(c);
//Grab the cell value and assign it to variable s, based on the cell type
switch(cell.getCellType()) {
case HSSFCell.CELL_TYPE_FORMULA:
s = cell.getCellFormula();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
s = Double.toString(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_STRING:
s = cell.getStringCellValue();
break;
default:
}
Matcher matcher = pattern.matcher(s);
//If a match is found in the string:
if (matcher.find()) {
//Replace all matches
String repl = matcher.replaceAll(" ");
outcell.setCellValue(repl);
}
else {
outcell.setCellValue(s);
}
}
}
outbk.write(out);
out.close();
}
public static void run(String in, String out, boolean txt, boolean exl, boolean rec, String delim, String worksheet) {
//Primary run process
//Takes String args in, out, delim, and worksheet
//in, out are file names for input and output files; delim is delimiter for adding recid on txt files
//worksheet is the name of the worksheet that needs to be processed on Excel type files
//Takes boolean args txt, exl, and rec
//txt and exl indicate file type, diff file types have diff processing
//rec indicates is a record id is requested to be added to the file
try {
delimiter = delim;
outfilename = appendOut(out, "_Clean");
outorigfn = appendOut(out, "_Original");
//For when I add in logging
logfn = appendOut(in, "_LogFile.txt", true);
if (txt) {
openTXTStreams(in, outfilename, outorigfn, delimiter, rec);
}
else if (exl) {
int inflg = chkEXLFile(in);
int outflg = chkEXLFile(out);
if (inflg == 0) {
//throw new Exception("test");
openXLSFileStream(in, out, rec, worksheet);
}
else if (inflg == 1) {
}
else {
}
}
else {
}
}
catch(Exception ex){
ex.printStackTrace();
}
}
public static void main(String[] args) {
String in = "D:\\Users\\[USER]\\Documents\\Java\\FilePrep\\TestFiles\\Name Address Phone.xls";
String out = "D:\\Users\\[USER]\\Documents\\Java\\FilePrep\\TestFiles\\Name Address Phone_Out.xls";
boolean txt = false;
boolean exl = true;
boolean rec = false;
String delim = ",";
String worksheet = "Sheet1";
run(in, out, txt, exl, rec, delim, worksheet);
}
}
这是我用来编译的命令:
"C:\Program Files\Java\jdk1.7.0\bin\javac.exe" -d D:\Users\[USER]\Documents\Java\FilePrep\fileprep -classpath D:\Users\[USER]\Documents\Java\FilePrep\fileprep;D:\Users\[USER]\Documents\Java\FilePrep\fileprep\lib\log4j-1.2.13.jar;D:\Users\[USER]\Documents\Java\Libraries\Apache\poi-3.9\poi-ooxml-3.9-20121203.jar;D:\Users\[USER]\Documents\Java\Libraries\Apache\poi-3.9\poi-3.9-20121203.jar D:\Users\[USER]\Documents\Java\fileprep\sources\fileprep\FilePrepMainStart.java
最后,这是我当前用于从应用程序目录测试运行的命令:
java FilePrepMainStart -classpath D:\Users\[USER]\Documents\Java\FilePrep\fileprep;lib\log4j-1.2.13.jar;lib\poi-ooxml-3.9-20121203.jar;lib\poi-3.9-20121203.jar;lib\commons-codec-1.5.jar;lib\stax-api-1.0.1.jar;lib\commons-logging-1.1.jar;lib\xmlbeans-2.3.0.jar;lib\dom4j-1.6.1.jar
这是我尝试制作的第一个真正的 Java 程序。目的是一个简单的应用程序,用于清除数据文件中的特殊字符。我已经能够正确设置简单的文本文件清理,但是,我无法让该程序与 Apache POI for Excel 文件一起使用。
我正在使用 UltraEdit,因为我没有在工作时使用 Eclipse 或 NetBeans 等 IDE 的安装权限。不过,IDE 可能真的很有帮助,因为我对此还很陌生。我已经为此苦苦挣扎了一段时间,这是一个完全阻止我在 Java 方面取得进步的障碍。我研究了这个错误并尝试改变我的类路径。我无权更改 PATH 环境变量,但我不知道这是否会导致此问题。我还尝试过将 JAR 文件移动到其他位置。
任何人都可以帮助我确定我缺少什么或为我指出正确的方向吗?我对这个失去了理智。我觉得如果我是一名称职的程序员,我应该能够解决这个问题——但显然我还没有做到这一点。我很感激任何建议。
谢谢!
最佳答案
cd 到您的项目目录并尝试以下操作:
java -classpath .;lib\log4j-1.2.13.jar;lib\poi-ooxml-3.9-20121203.jar;lib\poi-3.9-20121203.jar;lib\commons-codec-1.5.jar;lib\stax-api-1.0.1.jar;lib\commons-logging-1.1.jar;lib\xmlbeans-2.3. 0.jar;lib\dom4j-1.6.1.jar FilePrepMainStart关于Java 错误 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21921196/
我一直在尝试在我的代码中使用 Jar 文件作为库,并且它编译得很好。但是,在运行时,我不断收到 NoClassDefFoundError信息。为什么会这样?我也在编译路径和运行时路径中包含了 Jar
关于Apache-Kafka messaging queue . 我已经从 Kafka 下载页面下载了 Apache Kafka。我已将其提取到 /opt/apache/installed/kafka
我正在尝试使用 Apache DefaultHttpClient 来执行 JSON POST 请求,当我尝试实例化它时它给我一个 NoClassDefFound 错误。 HttpClient clie
当我在模拟器(Nexus One API 22)上测试我的应用程序时,它运行顺利,没有失败。然而,当我在自己的个人手机(三星 Galaxy S5,Android 版本 5.0)上测试该应用程序时,它崩
我需要在python中使用java代码来减少,所以我选择了Jython。一段时间后,我设法弄清楚了如何运行我的代码,但我遇到了最奇怪的事情。当我写作时 from vohmm.corpus import
这是我的mybatis配置。这是我的pom.xml。。当我运行项目时,它显示了错误的原因:org/mybatis/spring/mapper/MapperScannerConfigurer.有没有人能
所以我正在尝试构建一个简单的gradle应用,当我运行它时, geb.ConfigurationLoader$UnableToLoadException: Unable to load configu
假设我有一个主类应用程序,它使用 URLClassLoader 加载子目录 plugins 中的所有 jar: public class App(){ public static void m
我在尝试运行 Netbeans (7.2) 时遇到一个反复出现的错误,上次遇到它时,我发现某个地方可以将所有文件移动到一个新项目。这可能会奏效,但我的项目的规模让这很麻烦。这是踪迹... Except
这个问题已经有答案了: Including all the jars in a directory within the Java classpath (25 个回答) 已关闭 6 年前。 我得到一个
在这里,我正在下载网页源代码,然后将其存储在文本文件中。然后我读取该文件并将其与正则表达式匹配以搜索特定字符串。 没有编译器错误。 Exception in thread "main" java.la
我正在一个“大”的 Maven/Java 项目中工作,无法理解运行应用程序时遇到的错误(它编译正常)。我得到的错误代码是: java.lang.NoClassDefFoundError: Could
对于学校的作业,我需要创建一个类 Blender 来实现一些预定义的东西。我收到了一个 JAR 文件 imagecompositor.jar,它可以完成所有操作并使用 Blender 类。 JAR 文
我遇到了一个问题,即抛出 NoClasDefFoundError。这让我感到困惑,因为我正在使用接口(interface),并且没有类定义应该可用。我已经阅读了一些指向类路径的帖子,但我不认为这是这里
我正在使用 hibernate,在使用 hibernate Connection 时出现如下错误 java.lang.NoClassDefFoundError: Could not initializ
我有一个使用 SubVersion 的 Android 项目。我使用 Subclipse 将项目导入我的 Eclipse Wordspace。 现在我有一个问题: java.lang.NoClass
我需要编译一个外部 java 文件(比如 a.java)。这是我为此编写的代码。 (字符串路径包含java和class文件的路径) command[0] = "javac"; comm
我正在尝试运行一个基本的 Hibernate 程序。当我运行它时,出现以下错误 java.lang.NoClassDefFoundError: org/jboss/logging/BasicLogge
标题:Eclipse插件开发由于java.lang.NoClassDefFoundError无法实例化类: 试图构建一个 eclipse 插件,但遇到一些运行时错误.. 我知道这是由于代码所依赖的类文
我是新手,我无法让它工作......:/ 我的 build.sbt: val apacheDeps = Seq( "commons-validator" % "commons-validator"
我是一名优秀的程序员,十分优秀!