Hey guys I am working on a load class for my project that loads and pulls a info from a xml files. I have been following a few guides online but I am running into the error java.lang.NoClassDefFoundError: org/jaxen/JaxenException. I know the code is finding the save file because I can print out the name. But when I try to pull out the info I get that error. Snippet of code is below if there is no error in there let me know and Ill post more.
public void LoadProjects()
{
try
{
Files.walk(Paths.get("D:/workspace/Project Program/Projects/")).forEach(filePath ->
{
if(Files.isRegularFile(filePath))
{
System.out.println("Testing");
try
{
SAXReader reader = new SAXReader();
Document document = reader.read(filePath.toFile());
System.out.println(document.getName());
Node node = document.selectSingleNode("///Project/Info");
//String name = node.valueOf("#Name");
//String projNum = node.valueOf("#ProjectNumber");
//node = document.selectSingleNode("//Project/Dates");
//String dueBy = node.valueOf("#DueBy");
//CButton temp = new CButton(name, projNum, dueBy);
//Console.console.AddToList(temp);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
}
Did you add the jaxen jar to your servers lib?
Your code seems correct so far but please add as much information as possible from the beginning.
Ff you are using maven:
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
</dependency>
Related
Project Context
Currently trying to generate QR codes to implement some information within it, that includes data (such as a student ID number, first name, last name) and MAC address of local computer (testing on my desktop computer for now, but will be applied to individual raspberry Pis).
Error in Question
The Java Code
Ignore the data link input, this is for test purposes only.
public static void main(String[] args) throws Exception
{
MACFinder GM = new MACFinder();
GM.getMac();
System.out.println();
try
{
GM.generateQRCodeImage();
}
catch (WriterException e)
{
System.out.println("Couldn't generate QR code, WriterException...");
}
catch (IOException e)
{
System.out.println("Couldn't generate QR code, IOException...");
}
catch (NotFoundException e)
{
System.out.println("This library couldn't be found... (ZXing)");
}
}
public void generateQRCodeImage() throws WriterException, IOException, NotFoundException
{
String data = "https://www.youtube.com/watch?v=qzYpgbP8RHA";
String filepath = "C:\\Users\\JmJ23\\Documents\\Code\\Internship Code";
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix bitMatrix = qrCodeWriter.encode(data, BarcodeFormat.QR_CODE, 250, 250);
Path path = FileSystems.getDefault().getPath(filepath);
MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);
}
POM.xml Dependencies
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.0</version>
</dependency>
I understand that a NoClassDefFoundError is when a library/class is called but the class in question is not found at runtime... but why would this be the case if I have installed it into my Maven project? As a note I cleaned the project multiple times but with no progress. Any advice?
Your build looks fine. You didn't say how you build and run this, but I expect you just tried to build a .jar and run that .jar, without building all of its dependencies into it. You need something like the Maven assembly plugin.
I want to develop an application who can send direct messages look this:
public static void sendDirectMessage(Long recipientId, String message){
System.out.print("[Bot] Sending message to #"+recipientId+"... ");
try {
twitter.sendDirectMessage(recipientId, message);
System.out.println("done");
} catch (TwitterException e) {
System.out.println("fail");
e.printStackTrace();
System.err.println("[Error] "+e.getErrorMessage());
}
}
I call to this statement with:
private static String
customer_key = "",
Oth_key = "",
access_token = "",
access_key = "";
private static TwitterBot bot;
public static void main(String[] args) {
try {
bot = new TwitterBot(customer_key, Oth_key, access_token, access_key);
} catch (TwitterException e) {
e.printStackTrace();
} catch (InterruptedException e) {
System.err.println("[Err] "+e.getMessage());
}
bot.sendDirectMessage(bot.getUserData("AbA2L1").getId(), "Message test:!");
}
it's return error:
404:The URI requested is invalid or the resource requested, such as a user, does not exists. Also returned when the requested format is not supported by the requested method.
message - Sorry, that page does not exist.
code - 34
Note:
The functions search(), getHomeTimeline() and updateStatus() works.
I have activated Read, Write and Direct messages on twitter application permissions.
sorry for my bad english.
It's work with this vertion, add it into pom.xml file:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.twitter4j/twitter4j-core -->
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.0.7</version>
</dependency>
</dependencies>
Good luck.
Which version of Twitter4J are you using? The new Direct Message API is only a few weeks old so you may need a new version.
Use Twitter4j-core-4.0.7 version for Direct Message Functionality of Twitter.
Other Version of Twitter4j Library shows TwitterException of User Not Found or Page Does not exist.
i am not able to read the email id from the webpage below :
URL : https://targetstudy.com/university/2/acharya-ng-ranga-agricultural-university/
Here is my code
driver.navigate().to(URL);
String Email = driver.findElement(By.xpath("//*[#id="site-canvas"]/div[6]/div[2]/div[1]/div/div[1]/div/table/tbody/tr/td[2]/table/tbody/tr[4]/td[2]/img")).getText();
System.out.println(Email);
Selenium alone can't help you in this case, though your binding language would help you.
You need Java Tesseract API.
Code for extracting text :
public String getImgText(String imageLocation) {
ITesseract instance = new Tesseract();
try
{
String imgText = instance.doOCR(new File(imageLocation));
return imgText;
}
catch (TesseractException e)
{
e.getMessage();
return "Error while reading image";
}
}
If you are using maven for your Project, just add this dependency :
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.2.1</version>
</dependency>
More Reference : Extracting text from Image
I have created a Maven NetBeans project for Dropbox and I need to call up the files in a folder from Dropox and display them in a JList on the interface.
I am able to print them out in the output using (System.out.println()) the following:
public void GetFiles()
{
try
{
MainEmpOperations MEMPops = new MainEmpOperations();
// Get files and folder metadata from Dropbox root directory
ListFolderResult result = client.files().listFolder("/Employees");
while (true) {
for (Metadata metadata : result.getEntries()) {
System.out.println(metadata.getPathLower());
}
if (!result.getHasMore()) {
break;
}
result = client.files().listFolderContinue(result.getCursor());
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}
The coding that I have tried to use for loading the files into the JList is similar to the above coding where I will be using DefaultListModel.
Here is the coding that I have done so far but it does not list the files in the JList.
public void GetFiles()
{
try
{
MainEmpOperations MEMPops = new MainEmpOperations();
// Get files and folder metadata from Dropbox root directory
ListFolderResult result = client.files().listFolder("/Employees");
DefaultListModel modelListFiles = new DefaultListModel();
while (true) {
for (Metadata metadata : result.getEntries()) {
modelListFiles.addElement(metadata.getPathLower());
}
if (!result.getHasMore()) {
break;
}
result = client.files().listFolderContinue(result.getCursor());
MEMPops.List_CloudFiles.setModel(modelListFiles);
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}
Please could someone please help me out, and help me load the files names of the file into the JList.
Much appreciated
I managed to figure it out.
The way in which it needs to work is that the adding of the element and the setting of the model will need to be done straight after each other. placing the set model after the if statement results in the model being cleared or it becomes empty.
Therefore the following coding will work for listing of the files in a JList.
PLEASE NOTE: the rest of the other coding needed for connection and management from dropbox is on dropbox developers website.
CODING THAT WORKS:
public void GetFiles()
{
try
{
// Get files and folder metadata from Dropbox root directory
//please note the employees is a folder that is on dropbox
ListFolderResult result = client.files().listFolder("/Employees");
DefaultListModel modelListFiles = new DefaultListModel();
while (true) {
for (Metadata metadata : result.getEntries()) {
//get name just returns the name of the file and getPathLower() is used for getting the directory and the filename together.
modelListFiles.addElement(metadata.getName());
List_CloudFiles.setModel(modelListFiles);
}
if (!result.getHasMore()) {
break;
}
result = client.files().listFolderContinue(result.getCursor());
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}
Like (upvote or mark as helpful) if this answer that I posted to my own question helps you out as well.
In my Java program how can I find out where the Startup folder is on uers' PCs ? I know it's different on different versions of Windows. I only need my app to work on Windows. Any sample code ?
This should work:
System.getProperty("user.dir")
here you have an overviwe about system properties:
http://download.oracle.com/javase/tutorial/essential/environment/sysprop.html
With ShellLink creating shortcuts is very simple. https://github.com/BlackOverlord666/mslinks
Maven:
<dependency>
<groupId>com.github.vatbub</groupId>
<artifactId>mslinks</artifactId>
<version>1.0.5</version>
</dependency>
Refer answer by https://stackoverflow.com/a/38952899/4697928
private final String STARTUP_PATH = "/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup";
private void checkAutoStartPresent() {
File file = new File(System.getProperty("user.home") + STARTUP_PATH + "/YourShortcutFileName.lnk");
if (!file.exists()) { // shortcut not found
try {
ShellLink.createLink("/YourTargetProgramPath.exe", file.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
}