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.
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 is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am trying to create a program where it takes simple input and writes it to a file. Problem is, when it tries to open the file to write to it, I get the error: "java.io.FileNotFoundException: C:\Users\bobdu\eclipse-workspace\SHIPTesting.txt (The filename, directory name, or volume label syntax is incorrect)." I even have a very simple program where I get the same error:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
public class OutputTesting {
public static void main(String[] args)
{
try
{
PrintWriter outputStream = new PrintWriter(new FileOutputStream("C:\\Users\\bobdu\\eclipse-workspace\\SHIPTesting.txt"));
outputStream.println("Output line 1");
outputStream.println("Output line 2");
outputStream.close();
}
catch (FileNotFoundException e)
{
System.err.println(e.getMessage());
e.printStackTrace(System.err);
System.exit(0);
}
}
}
The file does exist for sure, I can find it in my directory. Thank you in advance for helping me.
You have an extra non-printable character in your path string. It survived the copy paste as well, so i was able to reproduce your error. Here is a test:
String yours = "C:\\Users\\bobdu\\eclipse-workspace\\SHIPTesting.txt";
String retyp = "C:\\Users\\bobdu\\eclipse-workspace\\SHIPTesting.txt";
System.out.println("yours len="+yours.length()+", retype=" + retyp.length());
The output is
yours len=49, retype=48
You have a bad character in your path. When I try to paste it into eclipse, I get:
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 8 years ago.
Improve this question
This code works in Eclipse, but when I try to submit the 'Test' problem on the SPOJ site, it gives me a compilation error.
Can you please tell me why?
public class Test{
public static void main(String [] args)
{
java.util.Scanner input=new java.util.Scanner(System.in) ;
int n ;
while(true )
{
n =input.nextInt() ;
if(n==42)
break ;
else
System.out.println(n) ;
}
}
}
You have to name your class "Main" for it to work on SPOJ.
See this forum post for more information: https://www.spoj.com/forum/viewtopic.php?t=37
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
my code is :
import ir.sbu.nlp.wordnet.data.model.FNSense;
import ir.sbu.nlp.wordnet.data.model.FNSynset;
import ir.sbu.nlp.wordnet.data.model.FNSynsetsRelation;
import ir.sbu.nlp.wordnet.service.FNSynsetService;
import java.util.Vector;
public class sample2 {
public static void main(String[] args) {
FNSynsetService service=new FNSynsetService();
service.findAll();
}
}
and when I run it display this error
Data Load Started...
Exception in thread "main" java.lang.NullPointerException
at ir.sbu.nlp.wordnet.data.dao.FNWordDao.getTextNode(FNWordDao.java:513)
at ir.sbu.nlp.wordnet.data.dao.FNWordDao.loadWords(FNWordDao.java:438)
at ir.sbu.nlp.wordnet.data.dao.FNWordDao.<init>(FNWordDao.java:76)
at ir.sbu.nlp.wordnet.data.dao.FNDaoManager.<init>(FNDaoManager.java:25)
at ir.sbu.nlp.wordnet.data.dao.FNDaoManager.getInstance(FNDaoManager.java:40)
at ir.sbu.nlp.wordnet.service.FNSynsetService.<init>(FNSynsetService.java:51)
at sample2.main(sample2.java:12)
Can every one help me?
I copy every file needed for installation
Seems like you need to set some object before calling service.findAll();
While this method is executing it might be trying to access some object which is turning out to be null. Debug and find out the exact line which is throwing NPE.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can I play module music (.it, .mod, .xm or .s3m files) in a Java application? (Standard Java for desktop machines)
I tried looking at the open source JavaMod, but it had too many files so I didn't know where to start, and the pre-built .jar file wouldn't even run on my machine.
Add javamod.jar to the application class path and try with this code:
public static void main(String[] args) {
try {
Helpers.registerAllClasses();
File music = new File("c:\\test3.XM");
Properties props = new Properties();
props.setProperty(ModContainer.PROPERTY_PLAYER_ISP, "3");
props.setProperty(ModContainer.PROPERTY_PLAYER_STEREO, "2");
props.setProperty(ModContainer.PROPERTY_PLAYER_WIDESTEREOMIX, "FALSE");
props.setProperty(ModContainer.PROPERTY_PLAYER_NOISEREDUCTION, "FALSE");
props.setProperty(ModContainer.PROPERTY_PLAYER_NOLOOPS, "FALSE");
props.setProperty(ModContainer.PROPERTY_PLAYER_MEGABASS, "TRUE");
props.setProperty(ModContainer.PROPERTY_PLAYER_BITSPERSAMPLE, "16");
props.setProperty(ModContainer.PROPERTY_PLAYER_FREQUENCY, "48000");
MultimediaContainerManager.configureContainer(props);
URL modUrl = music.toURI().toURL();
MultimediaContainer multimediaContainer = MultimediaContainerManager.getMultimediaContainer(modUrl);
Mixer mixer = multimediaContainer.createNewMixer();
mixer.startPlayback();
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(3);
} catch (Exception e) {
e.printStackTrace();
}
}
Works fine for me. But I would also suggest to try running javamod stand-alone in order to make sure it works on your system.
To get JavaMod to run on your machine, you have to run it with the java -jar command.
This screenshot illustrates how to do this:
Whoa, cool that JavaMod even exists to play old school modules in Java. I doubt you're going to find much better support these days. Honestly you're best bet is probably going to be to figure out how to call into that library, or just use the source code directly. You'll likely have to look through the code to determine how to integrate with it. By the way, I'm able to run it fine by just double clicking on the .jar file (I'm using Java 6 Update 24 on Windows 7).