This question already has answers here:
can not access a member of class org.springframework.aop.TruePointcut with modifiers public
(3 answers)
Closed 10 months ago.
This is my code (I removed a lot of graphics logic as to see if it would run a most basic file)
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
class Client extends Application {
public static String host = "127.0.0.1";
public BufferedReader fromServer;
public PrintWriter toServer;
public Scanner consoleInput = new Scanner(System.in);
public Client() {
}
public static void main(String[] args) {
launch(args);
}
public void start(Stage displayStage) {
try {
System.out.println("HELLO");
} catch (Exception e) {
System.err.println("Client connection error!");
e.printStackTrace();
}
}
}
but the error messages are really bizarre and I'm not sure what exactly it means; it mentions a public access but afaik, public means anything can access it and I don't use reflection but its throwing errors regarding reflection and I'm really stumpted as to what could be causing this error.
Exception in Application constructor
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class eHillsClient.Client
at javafx.graphics#18/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:891)
at javafx.graphics#18/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access a member of class eHillsClient.Client with modifiers "public"
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:489)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at javafx.graphics#18/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:803)
at javafx.graphics#18/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics#18/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics#18/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics#18/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics#18/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics#18/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
... 1 more
Make Client class public because a main class in JavaFX Applicaions must have a public access modifier to be picked by getConstructor() method in Application class.In normal cases it wouldn't cause an error but your main class will not be an entry point to the program(in JavaFx Applicaions the entry points is Applicaion class).
You can further read here
Related
I am trying to run a simple bdd test using behave and serenity but i am getting a initialization error. It seems as though there is a package class which is null but i cannot figure out which one or is there something wrong with way i am initialising my code.
I have been serenity bdd documentation online
https://serenity-bdd.github.io/theserenitybook/latest/jbehave.html
directory tree
new output
Appreciate the help :)
Below is the stack trace and code.
ava.lang.NullPointerException
at net.serenitybdd.jbehave.RootPackage.forPackage(RootPackage.java:8)
at net.serenitybdd.jbehave.SerenityStories.getRootPackage(SerenityStories.java:220)
at net.serenitybdd.jbehave.SerenityStories.stepsFactory(SerenityStories.java:88)
at org.jbehave.core.ConfigurableEmbedder.configuredEmbedder(ConfigurableEmbedder.java:130)
at net.serenitybdd.jbehave.runners.SerenityReportingRunner.<init>(SerenityReportingRunner.java:68)
at net.serenitybdd.jbehave.runners.SerenityReportingRunner.<init>(SerenityReportingRunner.java:62)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28)
at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
test.class
import net.thucydides.core.annotations.Managed;
import net.thucydides.core.annotations.Steps;
import org.jbehave.core.annotations.When;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
public class test {
#Managed()
WebDriver webDriver;
#Steps
GoogleSteps googleSteps;
#When("I open the page $value")
public void itest(String value) {
googleSteps.sendvalue(value);
}
}
GooglePage.class
import net.serenitybdd.core.annotations.findby.By;
import net.thucydides.core.annotations.DefaultUrl;
import net.thucydides.core.annotations.Step;
import net.thucydides.core.pages.PageObject;
import org.openqa.selenium.Keys;
#DefaultUrl("http://www.google.com")
public class GooglePage extends PageObject {
public void searchGoogle (String q) {
find(By.name("q")).sendKeys(q, Keys.ENTER);
}
}
GoogleSteps.class
import net.thucydides.core.annotations.Step;
public class GoogleSteps {
GooglePage googlePage;
#Step
public void open_page() {
googlePage.open();
}
#Step
public void sendvalue (String value) {
googlePage.searchGoogle(value);
}
}
GoogleRunner.class
import net.serenitybdd.jbehave.SerenityStory;
public class GoogleRunner extends SerenityStory {
}
serenity.properties file
webdriver.driver=chrome
webdriver.chrome.driver = /Users/aneesaiqbal/Downloads/chromedriver-2.exe
login.story
Narrative:
Testing google
Scenario: lets google
When I open the page hello
I'm trying to log into a website with HtmlUnitDriver and I keep getting a java.lang.error.
Ive added multiple jars to fix my com.gargoylesoftware.htmlunit.browserversion error which fixed that but caused another problem.
import org.jsoup.Connection;
import org.jsoup.Connection.Response;
import org.jsoup.Connection.Method;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import java.io.IOException;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.HasInputDevices;
public class selenium
public static void main ( String[] args ) throws IOException {
HtmlUnitDriver driver = new HtmlUnitDriver(true); // line that shows a error
String baseUrl = "website";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(baseUrl);
driver.findElement(By.name("username")).clear();
driver.findElement(By.name("username")).sendKeys("username");
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("password");
driver.findElement(By.cssSelector("input[type='submit']")).click();
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
HtmlUnitDriver cannot be resolved to a type
HtmlUnitDriver cannot be resolved to a type
Syntax error, insert "}" to complete ClassBody
I have written a code which will play music when a link on a webpage is found.
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javafx.application.*;
// * #author Archit
public abstract class WebCrawl extends Application{
public static void main(String[] args) throws IOException {
Application.launch(args);
int a=0;
try {
Document doc = Jsoup.connect("https://in.bookmyshow.com/ranchi").get();
org.jsoup.select.Elements links = doc.select("a");
for (Element e: links) {
if ((e.attr("abs:href").equals("https://in.bookmyshow.com/ranchi/movies/fan/ET00025074"))) {
try {
File f = new File("/Users/Archit/Documents/Music/campbell.wav");
Media hit = new Media(f.toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(hit);
mediaPlayer.play();
} catch(Exception ex) {
System.out.println("Exception");
}
}
}
}
The error I am getting is this:
Exception in Application constructor java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class webcrawl.WebCrawl
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:819)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application webcrawl.WebCrawl
A window seems to open when I run the application but is automatically closed and this error appears.
I would really appreciate the help. Thank you.
You are starting an application from the WebCrawl class using Application.launch(String[]), so launch tries to create a WebCrawl instance, which it can't, since WebCrawl is abstract.
BTW: Placing code after the Application.launch call won't work, since after Application.launch is finished, the JavaFX platform will already have exited.
You can read about the application lifecycle in the Life-cycle section of the Application javadoc.
You need to call the code form the start method or later.
You can find a tutorial for a simple JavaFX application here: https://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm
I am currently stuck with the following prob. The JAR & Pi4J Lib gets executed on a RasPi B+. I've been searching the web for hours without a result. Curiously looking forward to your reponses and support ;-)
Stacktrace:
Exception in thread "main" java.lang.RuntimeException: Unable to open GPIO direction interface for pin [1]: No such file or directory
at com.pi4j.wiringpi.GpioUtil.export(Native Method)
at com.pi4j.io.gpio.RaspiGpioProvider.export(RaspiGpioProvider.java:108)
at com.pi4j.io.gpio.impl.GpioPinImpl.export(GpioPinImpl.java:158)
at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionPin(GpioControllerImpl.java:517)
at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:669)
at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:681)
at com.test.RemoteImpl.fahreVorwaerts(RemoteImpl.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:178)
at sun.rmi.transport.Transport$1.run(Transport.java:175)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:174)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:557)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:812)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:671)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:744)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy0.fahreVorwaerts(Unknown Source)
at com.client.RMIClient.main(RMIClient.java:19)
package com.test;
The Code:
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import com.interf.test.TestRemote;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPin;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinDirection;
import com.pi4j.io.gpio.PinMode;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.io.gpio.trigger.GpioCallbackTrigger;
import com.pi4j.io.gpio.trigger.GpioPulseStateTrigger;
import com.pi4j.io.gpio.trigger.GpioSetStateTrigger;
import com.pi4j.io.gpio.trigger.GpioSyncStateTrigger;
import com.pi4j.io.gpio.event.GpioPinListener;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
import com.pi4j.io.gpio.event.PinEventType;
public class RemoteImpl extends UnicastRemoteObject implements TestRemote {
protected RemoteImpl() throws RemoteException {
super();
}
private static final long serialVersionUID = 1L;
#Override
public boolean isloginvalid(String username) throws RemoteException {
if (username.equals("test")) {
return true;
}
return false;
}
#Override
public void fahreVorwaerts(int dauer) throws RemoteException {
System.out.println("----- EXTCMD: VORWAERTS FAHREN "+"("+ dauer +"ms)" + "-----");
// GPIO CODE SECTION BEGINS
final GpioController gpio = GpioFactory.getInstance();
final GpioPinDigitalOutput pin_gpio01 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "MyLED", PinState.LOW);
pin_gpio01.pulse(dauer, true);
System.out.println("----- INFO: VORWAERTS FAHREN ENDE -----");
}
}
Life could have been so much easier if I'd just had a look on the GPIO numbering. There is no GPIO01!
Anyway, now it works by choosing an existing GPIO. Cheers :-)
Raspberry pi 3 B GPIO
pi4j; GPIO Input Error? "Unable to open GPIO edge interface for pin ??: No such file or directory"
-Solution-
Coding; gpio.setShutdownOptions(true) instead of myButton.setShutdownoptions(true) or gpio.shutdown()
Compile; Next, use the following command to compile this example program:
$ javac -classpath .:classes:/opt/pi4j/lib/'*' -d . ListenGpioExample.java
Execute the following command will run this example program:
$ sudo java -classpath .:classes:/opt/pi4j/lib/'*' ListenGpioExample
Run with sudo command
sudo java -jar yourjarname.jar
I have added the poi-bin-3.9-20121203 jar to my Eclipse Java Project.
This is my java code
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
public class Exce
{
public static void main(String argds[]) throws InvalidFormatException,FileNotFoundException, IOException{
FileInputStream fis;
fis = new FileInputStream("D:\\Sample.xlsx");
Workbook wb=WorkbookFactory.create(fis);
String un=wb.getSheet("Sheet1").getRow(1).getCell(0).getStringCellValue();
String pw=wb.getSheet("Sheet1").getRow(1).getCell(1).getStringCellValue();
System.out.println("Value 1 : " + un);
System.out.println("Value 2 :" + pw);
}
}
it is giving me the following error :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlOptions
at org.apache.poi.POIXMLDocumentPart.<clinit>(POIXMLDocumentPart.java:53)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:72)
at Exce.main(Exce.java:26)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlOptions
Can anyone help me how this can be solved
Try adding XMLBeans jar to your project.