hi i write a java app about bluetooth
when i run in eclipse console it ran ok
but when i run in command line it occur error
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.LocalDevice;
public class main {
/**
* #param args
* #throws BluetoothStateException
*/
public static void main(String[] args) throws BluetoothStateException {
// TODO Auto-generated method stub
LocalDevice local=null;
local = LocalDevice.getLocalDevice();
System.out.printf("this is some text");
}
}
errors occur
C:\Users\HUNGSON\workspace\Java_Test\bin>java main
Exception in thread "main" java.lang.NoClassDefFoundError: main
Caused by: java.lang.ClassNotFoundException: main
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: main. Program will exit.
please help me !!
Related
I'm trying to write a java application to change my desktop wallpaper using cmd.
The code I have written so far:
package me.kaes3kuch3n.main;
import java.util.HashMap;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.WinDef.UINT_PTR;
import com.sun.jna.win32.*;
public class WallpaperUpdater {
public static void main(String[] args) {
if(args.length != 1) {
System.err.println("Usage: java -jar WallpaperUpdater.jar <path_to_wallpaper>");
} else {
String path = args[0];
SPI.INSTANCE.SystemParametersInfo(
new UINT_PTR(SPI.SPI_SETDESKWALLPAPER),
new UINT_PTR(0),
path,
new UINT_PTR(SPI.SPIF_UPDATEINIFILE | SPI.SPIF_SENDWININICHANGE));
}
}
public interface SPI extends StdCallLibrary {
//from MSDN article
long SPI_SETDESKWALLPAPER = 20;
long SPIF_UPDATEINIFILE = 0x01;
long SPIF_SENDWININICHANGE = 0x02;
SPI INSTANCE = (SPI) Native.loadLibrary("user32", SPI.class, new HashMap<Object, Object>() {
/**
*
*/
private static final long serialVersionUID = 1L;
{
put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
}
});
boolean SystemParametersInfo(
UINT_PTR uiAction,
UINT_PTR uiParam,
String pvParam,
UINT_PTR fWinIni
);
}
}
It works just fine when I'm running it using Eclipse but after exporting it to a jar file it throws an error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/win32/StdCallLibrary
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at me.kaes3kuch3n.main.WallpaperUpdater.main(WallpaperUpdater.java:17)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.win32.StdCallLibrary
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
I've added both the jna.jar and the jna-platform.jar to the build path, but it won't work. What am I missing?
trying to run simple test selenium Web Driver program which is mentioned below:
package com.abc;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Mock_Exam {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/");
}
}
after running as java application getting the below error :
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/JsonSyntaxException
at org.openqa.selenium.firefox.Preferences.readDefaultPreferences(Preferences.java:95)
at org.openqa.selenium.firefox.Preferences.<init>(Preferences.java:65)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:87)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:77)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:66)
at org.openqa.selenium.firefox.FirefoxDriver.getProfile(FirefoxDriver.java:262)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at com.kesdee.ia.Mock_Exam.main(Mock_Exam.java:14)
Caused by: java.lang.ClassNotFoundException: com.google.gson.JsonSyntaxException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
FireFox version: 36.0.1
Selenium: selenium-java-2.45.0
You miss the gson-<version>.jar: in your classpath. Download add add it.
Good evening, I tried to use the JADE platform (official site -> http://jade.tilab.com/)
I followed tutorials that I found on youtube
Here's the code
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.util.ExtendedProperties;
import jade.util.leap.Properties;
import jade.wrapper.AgentContainer;
import jade.wrapper.ControllerException;
public class MainContainer {
public static void main(String[] args) {
try {
Runtime rt = Runtime.instance();
Properties p = new ExtendedProperties();
p.setProperty(Profile.GUI, "true");
ProfileImpl pc = new ProfileImpl(p);
AgentContainer container = rt.createAgentContainer(pc);
container.start();
} catch (ControllerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
But when I run the program I get errors like:
Exception in thread "main" java.lang.NoClassDefFoundError: jade/wrapper/ControllerException
****at java.lang.Class.getDeclaredMethods0(Native Method)
****at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
****at java.lang.Class.getMethod0(Unknown Source)
****at java.lang.Class.getMethod(Unknown Source)
****at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
****at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: jade.wrapper.ControllerException
****at java.net.URLClassLoader$1.run(Unknown Source)
****at java.net.URLClassLoader$1.run(Unknown Source)
****at java.security.AccessController.doPrivileged(Native Method)
****at java.net.URLClassLoader.findClass(Unknown Source)
****at java.lang.ClassLoader.loadClass(Unknown Source)
****at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
****at java.lang.ClassLoader.loadClass(Unknown Source)
****... 6 more
How To fix it please !
PS: I'm on windows7
You are missing jade's jar from your classpath. You could add it to the -cp parameter of java. E.g.:
java -cp JADE-all-4.3.2.zip MainContainer
When using google api to translate the text I am getting the following error.
com.google.api.GoogleAPIException: java.lang.Exception: [google-api-translate-java] Error retrieving translation.
at com.google.api.translate.TranslateV2.execute(TranslateV2.java:68)
at GoogleTranslator.main(GoogleTranslator.java:16)
Caused by: java.lang.Exception: [google-api-translate-java] Error retrieving translation.
at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:99)
at com.google.api.translate.TranslateV2.execute(TranslateV2.java:62)
... 1 more
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://www.googleapis.com/language/translate/v2?key=AIzaSyAmtyPllqBCXu5rVikedZw8IErGCCfEdtw&q=How+are+you%3F&target=hi&source=en
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:93)
... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://www.googleapis.com/language/translate/v2?key=AIzaSyAmtyPllqBCXu5rVikedZw8IErGCCfEdtw&q=How+are+you%3F&target=hi&source=en
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:89)
... 2 more
and my code is:
import com.google.api.GoogleAPI;
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
public class GoogleTranslator {
/**
* #param args
* the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try {
// Translate.setHttpReferrer(“en-fr”);
GoogleAPI.setHttpReferrer("http://www.google.com");
GoogleAPI.setKey("my key");
String translatedText = Translate.DEFAULT.execute("How are you?",
Language.ENGLISH, Language.HINDI);
System.out.println(translatedText);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Please need your help in resolving this.
I'm working though a book SWT/JFace IN ACTION by Manning Press.
When I added JFace, Eclipse for some reason could not find the main class though it is plainly present.
Here is the code
package com.swtjface.ChTwo;
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class HelloSWT_JFace extends ApplicationWindow{
/**
* #param args
*/
public HelloSWT_JFace(){
super(null);
}
protected Control createContents(Composite parent){
Text helloText = new Text(parent, SWT.CENTER);
helloText.setText("Hello SWT and JFace!");
parent.pack();
return parent;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
HelloSWT_JFace awin = new HelloSWT_JFace();
awin.setBlockOnOpen(true);
awin.open();
Display.getCurrent().dispose();
}
}
The reject message I get from Eclipse is...
Could not find the main class: com.swtjface.ChTwo.HelloSWT_JFace.
Program will exit.
Here is the exception...
java.lang.NoClassDefFoundError: org/eclipse/core/runtime/IProgressMonitor
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.IProgressMonitor
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Exception in thread "main"
You need at least 2 more jars to use JFace:
org.eclipse.equinox.common
org.eclipse.core.commands
See Using JFace outside the Eclipse platform for more details.
You need to add jar file for "org.eclipse.core.runtime.IProgressMonitor class"
Check this link.