Eclipse cannot find the main class in JFace? - java

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.

Related

Run testNG programatically in Eclipse using maven without a plugin

I want to run TestNG without using the "TestNG eclipse plugin" in a normal maven quickstart project.
Whatever I read from http://testng.org/doc/documentation-main.html#running-testng-programmatically & other sources, I got idea of using classes as:
MessageUtil.java
package com.mytests.testng;
public class MessageUtil {
private String message;
public MessageUtil(String message){
this.message = message;
}
public String printMessage(){
System.out.println(message);
return message;
}
}
TestNGExample.java
package com.mytests.testng;
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestNGExample {
String message = "Hello World";
MessageUtil messageUtil = new MessageUtil(message);
#Test
public void testPrintMessage() {
Assert.assertEquals(message,messageUtil.printMessage());
}
}
App.java
package com.mytests.testng;
import org.testng.TestListenerAdapter;
import org.testng.TestNG;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testNG = new TestNG();
#SuppressWarnings("rawtypes")
Class[] testClasses = new Class[]{
TestNGExample.class
};
testNG.setTestClasses(testClasses);
testNG.addListener(tla);
testNG.run();
}
}
But here I am getting exceptions as:
Exception Box 1
Exception Box 2
Exception in Console
Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/ITestListener
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.testng.ITestListener
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)
... 7 more
I am not getting why there is a problem even though I don't get any compile time error. The TestNG dependency is successfully downloaded and helps in writing the code. But the class doesn't load on run time I guess. What can be done?
If not using any XML is causing an error, I can use it as well, but not the eclipse plugin for TestNG.
P.S.: I am new to TestNG and this is my first program
This issue is happening because at runtime, testng jar is not available in classpath. You can resolve this by using <scope>compile</scope> instead of <scope>test</scope> in your testng pom dependency.

selenium web driver java.lang.NoClassDefFoundError: com/google/gson/JsonSyntaxException

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.

AbstractUIPlugin causing NoClassDefFoundError

I am writing an Eclipse plugin that supports automated testing like JUnit. I have a Launch Configuration Delegate that launches my Main class, which will run the tests on the class the user provides.
I want to programmatically show a custom View from my Eclipse plugin when I launch it with my Launch Configuration Delegate. I keep getting a NoClassDefFoundError for the AbstractUIPlugin class when I try to launch it even though I have included both org.eclipse.ui and org.eclipse.core.runtime in my plugin dependencies.
Stack Trace
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/ui/plugin/AbstractUIPlugin
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 eoo.thefamilycoder.specj.internal.launching.delegate.SpecJMain.main(SpecJMain.java:8)
Caused by: java.lang.ClassNotFoundException: org.eclipse.ui.plugin.AbstractUIPlugin
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
MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SpecJ
Bundle-SymbolicName: eoo.thefamilycoder.specj;singleton:=true
Bundle-Version: 1.0.0.alpha
Bundle-Activator: eoo.thefamilycoder.specj.internal.Activator
Require-Bundle: org.eclipse.ui;bundle-version="3.105.0",
org.eclipse.core.runtime;bundle-version="3.9.0",
org.eclipse.jdt.launching;bundle-version="3.7.0",
org.eclipse.debug.core;bundle-version="3.8.0",
org.eclipse.jdt.core;bundle-version="3.9.1",
org.eclipse.debug.ui;bundle-version="3.9.0",
org.eclipse.jdt.ui;bundle-version="3.9.1",
org.eclipse.jdt.debug.ui;bundle-version="3.6.200"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Main class
import eoo.thefamilycoder.specj.internal.Activator;
public class SpecJMain {
public static void main(String[] args) {
Activator.getDefault().showView();
}
}
What is causing the error, and how can I fix it?
Edit: Adding launch code
Launch Configuration Delegate
public class SpecJLaunchConfigurationDelegate extends AbstractJavaLaunchConfigurationDelegate {
private static final int UNITS_OF_WORK = 4;
#Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch,
final IProgressMonitor monitor) throws CoreException {
final IProgressMonitor pm = monitor != null ? monitor : new NullProgressMonitor();
pm.beginTask(configuration.getName(), UNITS_OF_WORK);
if (pm.isCanceled()) return;
try {
preLaunchCheck(configuration, mode, pm);
if (pm.isCanceled()) return;
final VMRunnerConfiguration runConfig =
new VMRunnerConfigurationFactory().create(configuration, monitor, this);
if (pm.isCanceled()) return;
getVMRunner(configuration, mode).run(runConfig, launch, pm);
if (pm.isCanceled()) return;
} finally {
pm.done();
}
}
#Override
public String[] getClasspath(ILaunchConfiguration configuration) throws CoreException {
final String[] initialClasspath = super.getClasspath(configuration);
final String pluginClasspath = new SpecJClasspathLocator().getClasspath();
System.out.println(pluginClasspath);
if (pluginClasspath == null) return initialClasspath;
final String[] classpath = new String[initialClasspath.length + 1];
classpath[0] = pluginClasspath;
System.arraycopy(initialClasspath, 0, classpath, 1, initialClasspath.length);
return classpath;
}
}
VMRunnerConfigurationFactory
public class VMRunnerConfigurationFactory {
public VMRunnerConfiguration create(final ILaunchConfiguration configuration, final IProgressMonitor monitor,
final AbstractJavaLaunchConfigurationDelegate delegate) throws CoreException {
final ExecutionArguments execArgs = new ExecutionArguments(delegate.getVMArguments(configuration), "");
// Activator.MAIN_TYPE_NAME is the main class above
final VMRunnerConfiguration runConfig = new VMRunnerConfiguration(Activator.MAIN_TYPE_NAME,
delegate.getClasspath(configuration));
runConfig.setBootClassPath(delegate.getBootpath(configuration));
runConfig.setEnvironment(delegate.getEnvironment(configuration));
runConfig.setProgramArguments(new ProgramArgumentsFactory().create(configuration, monitor));
runConfig.setVMArguments(execArgs.getVMArgumentsArray());
runConfig.setVMSpecificAttributesMap(delegate.getVMSpecificAttributesMap(configuration));
runConfig.setWorkingDirectory(getWorkingDirectoryName(delegate.verifyWorkingDirectory(configuration)));
return runConfig;
}
private String getWorkingDirectoryName(final File workingDir) throws CoreException {
return workingDir != null ? workingDir.getAbsolutePath() : null;
}
}
AbstractUIPlugin is in the org.eclipse.ui.workbench plug-in so you need that in your dependencies.
Edit.
Just noticed you are using a main method - this an Eclipse plugin you can't run this is as a normal Java program. You must either run it in an existing Eclipse RCP or create a RCP.
Edit 2
Your launch does nothing to properly initialize Eclipse to run a plugin. You must start an Eclipse app through the org.eclipse.equinox.launcher.Main entry point (normally via the eclipse executable). You must specify an application or product to run (like in the Run Configuration for an Eclipse Application).

Possible causes of "java.lang.ClassFormatError: Invalid pc in LineNumberTable"

Today I started coding a project that uses sqlite and when I tried to test it I received the java.lang.ClassFormatError: Invalid pc in LineNumberTable. Hope you can help me with it, because I'm just lost. I'v searched about this error, and came across some weird solutions to some weird causes. As I understand, none of them was causing my problem.
I'm using "sqlitejdbc-v056" wich is inserted in my classpath.
Edit: My JDK version is 1.7.0_03-b05
StackTrace:
Exception in thread "main" java.lang.ClassFormatError: Invalid pc in LineNumberTable in class file Controllers/FuncionariosController
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 Main.main(Main.java:13)
Code giving the error:
public class Main {
public static void main(String[] args) {
DatabaseController db=new DatabaseController();
FuncionariosController f=new FuncionariosController(db);
...
}
}
Class FuncionarioController:
package Controllers;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import Models.Funcionario;
public class FuncionariosController {
private DatabaseController db;
public FuncionariosController(DatabaseController db){
this.db=db;
}
public void render(String cargo){
...
}
public List<Funcionario> selectAll(){
...
}
public Funcionario select(String login){
...
}
}
Thanks in advance,
I had a simmilar problem.
It occured that it was caused by switch that haven't got cases code.
While the error occured it looked somtheing like this:
switch(e.getActionCommand()) {
case ACTION_OPEN_PID:
break;
case ACTION_OPEN_PPID:
break;
default:
}
After adding simple console output to the cases the error was gone.
switch(e.getActionCommand()) {
case ACTION_OPEN_PID:
System.out.println(ACTION_OPEN_PID);
break;
case ACTION_OPEN_PPID:
System.out.println(ACTION_OPEN_PPID);
break;
default:
}
Thanks to Luiggi Mendoza I solved it by using JDK 1.6 instead of 1.7. That did the trick, but I had to comment out a lot of code to compile it. Not that good a solution....

Bluetooth does not run in window PC

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 !!

Categories

Resources