Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am using Netbeans 7. I was provided with a class file (MT.class), that I need to test. I put it under build>classes.
I created a java class with main method. When I declare a new object using MT class, I get compiler error. Please let me know how to resolve this.
package mypack;
public class MyTest {
public static void main(String[] args) {
MyTest.avgTest();
}
public static void avgTest()
{
double res;
MT mt=new MT();
res=mt.avg(9,4);
System.out.println("The average is " + res);
}
}
If your .class file was compiled under a specific package hierarchy / dir structure, just create this structure under /libs . So if you class full name is foo.bar.MT then create /libs/foo/bar/ and put the .class file inside.
Then right click on your project in NetBeans > Properties > Libraries > Add JAR/Folder > then select the the libs folder from the above example.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to open MATLAB File(.m) using Java
I know MATLAB API.
It's a shame, but I don't know how to use it. How can I open MATLAB File(.m) using MATLAB API?
What should I do?
If possible, can you show an example code?
Thank you.
calling matlab function in java
1-first, add matlab as an Environment variable in windows.
in win10: search Environment variable, Edit environment variable, system variables, path, edit, new, ...
add [matlabroot]/bin/win64 to the path variables.
2-import matlab engine in your java class and use MatlabEngine and its functions :(eval,evalAsync,feval,...) :
import com.mathworks.engine.*; //import engine
public class javaEvalFunc {
public static void main(String[] args) throws Exception {
try{
MatlabEngine eng = MatlabEngine.startMatlab();
eng.evalAsync("[X, Y] = meshgrid(-2:0.2:2);");
eng.evalAsync("Z = X .* exp(-X.^2 - Y.^2);");
Object[] Z = eng.getVariable("Z");
eng.close();
}catch(Exception e){}
}
}
3-to call a specific .m routine, call it with its full path with eval,...
eng.eval("c:\temp\myroutine");
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have been working on a small program and I'm new to Java. But it keeps raising filenotfound exception.
Here's my code:
import java.io.FileNotFoundException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
* Don't forget your file header comment here!
*/
public class WordSearch {
/*
* This is how you declare constants in Java. You can now type
* 'MIN_WORD_LENGTH' anywhere you want to refer to it.
*/
private static final int MIN_WORD_LENGTH = 3;
public static void main(String[] args) throws FileNotFoundException {
// Remember, to access command-line arguments, you use args[0],
// args[1],...
// See CommandLine.java and Stdin.java in the Class Examples github for examples.
List<String> dictList= new ArrayList<>();
dictList = dictRead(args[0]);
}
public static List<String> dictRead (String filePath) throws FileNotFoundException{
Scanner dictScan = null;
dictScan = new Scanner(new File(filePath));
List<String> dictList = new ArrayList<>();
int i=0;
while (dictScan.hasNext()) {
dictList.add(i, dictScan.nextLine());
i+=1;
}
return dictList;
}
}
This I don't know why I keep getting this exception. I changed my run configuration and put TestCases/dictionary.txt as my first argument.
Here's a picture of my directory and I'm running WordSearch.java:
Your folder structure has project within project. In you IDE, if you have only PA1-WordSearch imported as a project, it will work.
I hope it will work for you
dictList = dictRead("./FileFolder/aaa.txt");
The file is not in the place where Java expects it.
TestCases/dictionary.txt is a relative path. To find the file on your drive, it gets interpreted relative to some "working directory". You can probably find that in the run configuration.
But it's more robust to specify the file with an absolute path, one that begins with C:\ or similar if you are on a Windows machine. Using the absolute path makes you independent of the working directory.
So: find the absolute path of your file using the Windows Explorer, and insert that path as the argument in your run configuration.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Please suggest How can I improve my question
I ran my code but it throws cannot find main class error. I know this error comes when name of class with main method is different from file name. I tried to solve this error for an hour. I need help.
CountRows.java
import java.io.*;
import java.sql.*;
public class CountRows
{
public static void main(String args[])
{
System.out.println("Count number of rows in a specific table!");
Connection con = null;
int count = 0;
try
{
//Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial","root","dics");
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Execution
>javac -classpath "e:\softwares\java\jar files\mysql-connector-java-8.0.19.jar" CountRows.java
E:\user\java\jdbc\test>java -classpath "e:\softwares\java\jar files\mysql-connector-java-8.0.19.jar" CountRows
Error: Could not find or load main class CountRows
Edit: Although the solution works but I still don't understand what was wrong with my way of executing code
Your Code is working perfectly fine there is no issue in it.
I suggest you set classpath initially before using javac and java tools.
Set your classpath via CMD
set classpath="<EXTERNAL_JAR_FILES_PATH>"
I hope this might help you. If you are still facing the same issue you can ping me back. I will be happy to help you.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have the following code:
public static void main(String[] args) {
String prop1 = System.getProperty("test.prop", "missing");
System.out.println("test.prop: " + prop1);
String prop2 = System.getProperty("otherprop", "missing");
System.out.println("otherprop: " + prop2);
String cmd = System.getProperty("sun.java.command");
System.out.println("cmd: " + cmd);
}
I invoke the built jar using PowerShell:
> java -jar TestApp.jar -Dtest.prop=value1 -Dotherprop=value2
test.prop: missing
otherprop: missing
cmd: TestApp.jar -Dtest .prop=value1 -Dotherprop=value2
> java -Dtest.prop=value1 -Dotherprop=value2 -jar TestApp.jar
Error: Could not find or load main class .prop=value1
Why does PowerShell not pass the command line arguments as custom properties to Java and how do I make it work?
The correct call is:
java -Dtest.prop=value1 -Dotherprop=value2 -jar TestApp.jar
When properties are passed after your jar file name, they are passed as program arguments to your main method, instead of being set as system properties.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am trying to follow the instructions for installing javaCV from here: https://code.google.com/p/javacv/. I ve already built opencv. Actually I locate the java folder with .jar file and .dll in opencv folder and I add them in the path of my project. When I am trying to run the SimpleSample.java I am receiving Error: Could not find or load main class FaceRecognition. Is there something else I ve got to follow in order to install javaCV? My simple Code
package simplesample;
/**
*
* #author snake
*/
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
public class SimpleSample{
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
EDIT2: I add some jar files (javacv-windows-x86.jar, javacpp.jar, javacv.jar) and I finally got it running. But when I am trying to read a simple jpg image:
public static void main(String[] args) {
// TODO code application logic here
System.out.println("soul makosa");
IplImage image = cvLoadImage("ef.jpg");
if (image != null) {
cvSmooth(image, image, CV_GAUSSIAN, 3);
cvSaveImage("ef1.jpg", image);
cvReleaseImage(image);
}
}
I am reveiving the following errors:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopencv_highgui in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1088)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:711)
at com.googlecode.javacpp.Loader.load(Loader.java:586)
at com.googlecode.javacpp.Loader.load(Loader.java:540)
at com.googlecode.javacv.cpp.opencv_highgui.<clinit>(opencv_highgui.java:79)
at projectcv.ProjectCV.main(ProjectCV.java:28)
Caused by: java.lang.UnsatisfiedLinkError: C:\Documents and Settings\chrathan\Local Settings\Temp\javacpp101399456657827\jniopencv_highgui.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1851)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1062)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:700)
... 4 more
Java Result: 1
I also add .dll file in properties->run->VM optimize as instructed here giving 'java.library.path' in netbeans for .dll/.so files. However I am still receiving the above message.
SOLVED:Ok my problems was due to the fact that I had to install specific version of javaCV. So for openCV version 2.4.6.1 I ve installed 0.6 java_CV and now works like a charm.
You need to add native class library path while adding opencv jar file into the project
Goto the buildpath>>libraries>>opencv >> click on expand and edit " native library location" to
C:/opencv/build/java/x86
for face FaceRecognition you need to add all jar files from that site
javacv-0.7-bin.zip
javacv-0.7-cppjars.zip
ffmg, etc....
it will work ....
Its working for me