jcurses errors while try to import in IntelliJ - java

I`m trying to import jcurses library to IntelliJ but get an error.
File -> Project Structure -> Modules -> import jar file.
Then in code:
import jcurses.widgets.Window;
class main {
public static void main(String[] args){
Window win = new Window(800, 600, true, "test");
win.setVisible(true);
}
Exception in thread "main" java.lang.ExceptionInInitializerError
at jcurses.system.InputChar.<clinit>(InputChar.java:25)
at jcurses.widgets.Window.<clinit>(Window.java:209)
at main.main(main.java:7)
Caused by: java.lang.RuntimeException: couldn't find jcurses library
at jcurses.system.Toolkit.getLibraryPath(Toolkit.java:121)
at jcurses.system.Toolkit.<clinit>(Toolkit.java:37)
Could someone point out where is my mistake?
Thanks in advance!

The answer is that dll must be in the same directory as jar file. Thanks to everyone!

Libray download url
https://sourceforge.net/projects/javacurses/files/javacurses/0.9.5/
The path of the library is in the root directory of the project
dynamically add the library
import java.io.File;
import java.lang.reflect.Field;
import java.util.Arrays;
public class LoadLibrary {
public static void main(String cor[]) throws Exception {
// Cargando librerias necesarias
loadLibraryJCourses();
}
public static void loadLibraryJCourses() throws Exception{
loadDynamicLibrary(new File("lib/bin/jcourses/").getAbsolutePath(),"libjcurses64");
}
private static void addLibraryPath(String pathToAdd) throws Exception {
final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
usrPathsField.setAccessible(true);
//get array of paths
final String[] paths = (String[]) usrPathsField.get(null);
//check if the path to add is already present
for (String path : paths) {
if (path.equals(pathToAdd)) {
return;
}
}
//add the new path
final String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
newPaths[newPaths.length - 1] = pathToAdd;
usrPathsField.set(null, newPaths);
}
private static void loadDynamicLibrary(String pathLibraryDirectory, String libraryName) throws Exception{
File pathLibraryFile = new File(pathLibraryDirectory);
addLibraryPath(pathLibraryFile.getAbsolutePath());
System.loadLibrary(libraryName);
}
}

Related

Copy all the files from a directory to another

i'm trying to copy all the files inside a directory to another(but i want it to not copy the folders). I'm trying to use Files.copy but i'm getting this error:
Exception in thread "main" java.nio.file.FileAlreadyExistsException:
Here's my actual code:
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Exercici1 {
public static void copiarArchivos(String pathSource,String pathOutcome, String sufix) throws IOException {
File origen = new File(pathSource);
String[] contenidoOrigen = origen.list();
for(String string:contenidoOrigen){
File interno = new File(origen,string);
if (interno.isDirectory()){
copiarArchivos(interno.getPath(),pathOutcome,sufix);
} else {
Path targetOutcome = Paths.get(pathOutcome);
Path targetSource = Paths.get(interno.getPath());
Files.copy(targetSource,targetOutcome);
}
}
}
public static void main(String[] args) throws IOException {
copiarArchivos("Vampiro_Mascarada","pruebaPDF",".pdf");
}
}
My folder structure is like this:
/out
/pruebasPDF
/src
/Vampiro_Mascarada
/1.pdf
/2.pfdf
/Images
/1.png
/2.png
You need to use to Files.copy(source,dest,CopyOption) with the REPLACE_EXISTING option.

How to successfully return the metadata off of an mp3 file while avoiding a null pointer exception

When I attempt to run the program that takes the metadata and prints it from an mp3 file, I am returned with an "Exception in thread "main" java.lang.NullPointerException at project.mp3MetaData.main(musicdj.java:18)". For this class you need the jid3lib jar. How do I avoid this exception and do I need to pass any variables through the tags at the bottom?
package 1234;
import java.io.File;
import java.io.IOException;
import org.farng.mp3.MP3File;
import org.farng.mp3.TagException;
import org.farng.mp3.id3.ID3v1;
public class mp3MetaData {
public static void main(String[] args) throws IOException, TagException {
// TODO Auto-generated method stub
File sourceFile = new File("/Users/JohnSmith/Desktop/MusicTester/1234.mp3");
MP3File mp3file = new MP3File(sourceFile);
ID3v1 tag = mp3file.getID3v1Tag();
System.out.println(tag.getAlbum());
System.out.println(tag.getAlbumTitle());
System.out.println(tag.getTitle());
System.out.println(tag.getComment());
}
}
Any help will be greatly appreciated.
Your MP3 file might not contain an ID3 tag. So check whether tag is null or not, before using it. Something like this:
public static void main(String[] args) throws IOException, TagException
{
File sourceFile = new File("/Users/JohnSmith/Desktop/MusicTester/1234.mp3");
final MP3File mp3file = new MP3File(sourceFile);
final ID3v1 tag = mp3file.getID3v1Tag();
if (null == tag)
{
System.out.println("No ID3 tag found!");
}
else
{
System.out.println(tag.getAlbum());
System.out.println(tag.getAlbumTitle());
System.out.println(tag.getTitle());
System.out.println(tag.getComment());
}
}

JAVE Library for Mac

I'm actually trying to launch my Unix code on my Mac.
I know that I have to build ffmpeg on my Mac.
I used a Github script for that :
Script
My code :
package test1;
import it.sauronsoftware.jave.*;
import test1.MyFFMPEGExecutableLocator;
import java.io.*;
public class Test1 {
public static void main (String[] zero) throws IllegalArgumentException, InputFormatException, EncoderException{
File source = new File("/Users/Mokeight/Desktop/Test2.mp3");
File target = new File("/Users/Mokeight/Desktop/target2.wav");
System.out.println("START");
AudioAttributes audio = new AudioAttributes();
EncodingAttributes attrs = new EncodingAttributes();
//codec de wav
audio.setCodec("pcm_s16le");
attrs.setFormat("wav");
attrs.setAudioAttributes(audio);
//System.out.println(new MyFFMPEGExecutableLocator().toString());
Encoder encoder = new Encoder(new MyFFMPEGExecutableLocator());
encoder.encode(source, target, attrs);
System.out.println("END");
}
}
My second class is :
package test1;
import it.sauronsoftware.jave.FFMPEGLocator;
public class MyFFMPEGExecutableLocator extends FFMPEGLocator{
#Override
protected String getFFMPEGExecutablePath() {
// TODO Auto-generated method stub
String path = "/Users/Mokeight/Desktop/ffmpeg_mac/ffmpeg-build/workspace/bin/ffmpeg" ;
return path;
}
}
When i'm running that , i have this error :
START
Exception in thread "main" it.sauronsoftware.jave.EncoderException: Metadata:
at it.sauronsoftware.jave.Encoder.encode(Encoder.java:863)
at it.sauronsoftware.jave.Encoder.encode(Encoder.java:713)
at test1.Test1.main(Test1.java:27)
Please, help
Thanks !!

Where does Java save files to?

I ran the below code and created a file. Where can I find it in my filesystem?
import java.io.*;
public class FileReaderDemo {
public static void main(String args[]) throws Exception {
File f = new File ("wayback.txt");
f.createNewFile();
System.out.println(f.exists());
}
}
Add the following to your program, run it and it'll show you the expected location:
System.out.println(f.getCanonicalFile());

Accessing resource from a jar shared library

From test.java, how can I access for reading the Contact.xml file located in the contacts.jar library ?
The bellow code returns null.
package views;
import fr.hznteam.contacts.Contact;
import fr.hznteam.errors.ResourceException;
import java.io.InputStream;
public class Test {
private static final String TAG = "Test ";
public static void main(String[] args) throws ResourceException {
InputStream is = Contact.class.getResourceAsStream("/fr/hznteam/contacts/sql/Contact.xml");
System.out.println(TAG + "resource from jar " + is);
}
The package structure :
this works (see above comment). Inside an object instance use
getClass().getResourceAsStream("/absolute/class_path/to/resource.file"))

Categories

Resources