Appium unable to retrieve webelement using TestNG - appium

We have developed an app and we would like to configure automated tests with Appium and TestNG. The app contains both native and web pages, but the header where reside logo, hamburger (in homepage) and back button is always native.
I get the web resources id from Chrome Inspector, but the command:
WebElement usernameEditText = driver.findElement(By.id("username"));
or
WebElement login = driver.findElement(By.xpath("//input[#id='login-ico']"));
fails with this error:
org.openqa.selenium.NoSuchElementException: An element could not be
located on the page using the given search parameters. (WARNING: The
server did not provide any stacktrace information)
Command duration or timeout: 309 milliseconds
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.46.0', revision:
'61506a4624b13675f24581e453592342b7485d71', time: '2015-06-04 10:22:50'
System info: host: 'stefano', ip: '127.0.0.1', os.name: 'Mac OS X',
os.arch: 'x86_64', os.version: '10.11.4', java.version: '1.7.0_79'
*** Element info: {Using=xpath, value=//input[#id='login-ico']}
Session ID: 18098de4-ee19-42b5-9f91-30f6f7e01552
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{automationName=Appium, platform=LINUX,
javascriptEnabled=true,
appActivity=com.UnipolSaiApp.activity.MainActivity,
networkConnectionEnabled=true, desired={automationName=Appium,
platformVersion=5.0.1, platformName=Android, deviceName=Android,
appActivity=com.UnipolSaiApp.activity.MainActivity, device=Android,
appPackage=com.UnipolSaiApp}, locationContextEnabled=false,
appPackage=com.UnipolSaiApp, platformVersion=5.0.1,
databaseEnabled=false, deviceName=9b984ca9, platformName=Android,
webStorageEnabled=false, device=Android, warnings={},
takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:43)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:358)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:455)
at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:129)
at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
at org.openqa.selenium.By$ByXPath.findElement(By.java:358)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:350)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:51)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at pages.LoginPage.login_success(LoginPage.java:25)
at scenarios.AppiumTest.loginTest(AppiumTest.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:673)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:842)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1166)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.runWorkers(TestRunner.java:1178)
at org.testng.TestRunner.privateRun(TestRunner.java:757)
at org.testng.TestRunner.run(TestRunner.java:608)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1158)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1083)
at org.testng.TestNG.run(TestNG.java:999)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:74)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Instead, the retrieving of native elements occur with success.
Here the code of my AndroidSetup:
public class AndroidSetup {
protected AndroidDriver driver;
protected void prepareAndroidForAppium() throws MalformedURLException {
File appDir = new File("/path_of_apk");
File app = new File(appDir,"*****.apk");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("deviceName","Android");
dc.setCapability("platformVersion","5.0.1");
dc.setCapability("platformName","Android");
//dc.setCapability(CapabilityType.BROWSER_NAME, "browser");
dc.setCapability("device","Android");
dc.setCapability("appPackage","com.*******");
dc.setCapability("appActivity","com.*******.MainActivity");
//other caps
//dc.setCapability("app",app.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), dc);
Set<String> contexts = driver.getContextHandles();
for (String ctx : contexts) {
System.out.println(ctx);
}
}
}
Here the AppiumTest:
public class AppiumTest extends AndroidSetup {
#BeforeClass
public void setUp() throws Exception {
prepareAndroidForAppium();
}
#AfterClass
public void tearDown() throws Exception {
driver.quit();
}
#Test
public void loginTest() throws InterruptedException
{
new LoginPage(driver).login_success();
}
}
Here the BaePage class:
public class BasePage {
protected WebDriver driver;
String app_package_name = "com.****:id/";
public BasePage(WebDriver driver) {
this.driver = driver;
}
protected void waitForVisibilityOf(By locator) {
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
}
protected void waitForClickabilityOf(By locator) {
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(locator));
}
}
And here the LoginPage:
public class LoginPage extends BasePage {
public LoginPage(WebDriver driver) {
super(driver);
}
public LoginPage login_success() throws InterruptedException {
Thread.sleep(30000);
WebElement login = driver.findElement(By.xpath("//input[#id='login-ico']"));
login.click();
WebElement usernameEditText = driver.findElement(By.id("usernameET"));
usernameEditText.sendKeys("****");
WebElement passwordEditText = driver.findElement(By.id("passwordET"));
passwordEditText.sendKeys("*****");
WebElement loginButton = driver.findElement(By.id("submitBtn"));
loginButton.click();
return new LoginPage(driver);
}
}
The following code:
Set<String> contexts = driver.getContextHandles();
for (String ctx : contexts) {
System.out.println(ctx);
}
returns just NATIVE_APP entry.
Can you explain me what's wrong? It's an error about the Appium configuration?

Related

java.lang.ExceptionInInitializerError while running the Appium test

I am getting java.lang.ExceptionInInitializerError error when I ran the Appium script. I am using Page Factory.
Using Java-client v6.1.0 & Appium v1.9.1
Error:
[RemoteTestNG] detected TestNG version 6.14.2
Dec 06, 2018 12:59:41 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: OSS
FAILED: Tests1
java.lang.ExceptionInInitializerError
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:215)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:107)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at com.****.pages.MainScreen.<init>(MainScreen.java:25)
at com.****.tests.smoke.Test.Tests1(Test.java:32)
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:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:580)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:79)
at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:49)
at net.sf.cglib.core.DefaultGeneratorStrategy.getClassVisitor(DefaultGeneratorStrategy.java:30)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329)
at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93)
at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91)
at net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at net.sf.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
at net.sf.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:174)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:153)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73)
... 36 more
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
Automation Code:
DriverSetup code:
package com.****.utils;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.****.config.Config;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.appmanagement.ApplicationState;
public class DriverSetup{
private Config config = new Config();
private AndroidDriver<MobileElement> driver;
public AndroidDriver<MobileElement> getDriver()
{
if (driver == null) {
driver = initDriver();
} else {
driver.queryAppState(config.APP_PACKAGE);
if (ApplicationState.NOT_RUNNING != null) {
Activity activity = new Activity(config.APP_PACKAGE, "SplashActivity");
activity.setAppWaitPackage(config.APP_PACKAGE);
activity.setAppWaitActivity("SplashActivity");
driver.startActivity(activity);
} else if (ApplicationState.RUNNING_IN_BACKGROUND != null) {
driver.launchApp();
}
}
return driver;
}
public AndroidDriver<MobileElement> initDriver()
{
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("automationName", config.AUTOMATION_NAME);
caps.setCapability("browserName", config.BROWSER_NAME);
caps.setCapability("deviceName", config.DEVICE_NAME);
caps.setCapability("platformName", config.PLATFORM_NAME);
caps.setCapability("platformVersion", config.PLATFORM_VERSION);
caps.setCapability("app", System.getProperty("user.dir") + config.APP_PATH);
caps.setCapability("newCommandTimeout", config.NEW_COMMAND_TIMEOUT);
caps.setCapability("autoAcceptAlerts", config.AUTO_ACCEPT_ALERTS);
caps.setCapability("noReset", config.NO_RESET);
caps.setCapability("autoGrantPermissions", config.AUTO_GRANT_PERMISSIONS);
try {
driver = new AndroidDriver<MobileElement>(new URL(config.APPIUM_SERVER_URL), caps);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return driver;
}
}
Test Method Code:
package com.****.tests.smoke;
import org.testng.annotations.BeforeMethod;
import com.****.pages.MainScreen;
import com.****.utils.DriverSetup;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class Test {
AndroidDriver<MobileElement> driver;
#BeforeMethod
public void setUp()
{
DriverSetup com = new DriverSetup();
driver = com.getDriver();
}
#org.testng.annotations.Test
public void Tests1() throws InterruptedException
{
MainScreen mainScreen = new MainScreen(driver);
Thread.sleep(10000);
mainScreen.allowAccessToUSBDevice();
}
}
Page Objectes class
public class MainScreen {
AndroidDriver<MobileElement> driver;
public MainScreen(AndroidDriver<MobileElement> driver) {
this.driver = driver;
PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(5)), this);
}
#AndroidFindBy(xpath = "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.Button[2]")
private MobileElement accessUSBDeviceAlertButton;
public void allowAccessToUSBDevice() {
accessUSBDeviceAlertButton.click();
}
}
Can anyone please let me know where the problem is? Is it with code or the libraries or tools?
Thanks in advance,
Shiva

JavaFX with OpenCV start/pause webcam. FXMLLoader

I am trying to learn JavaFX with the library OpenCV for my degree. I want to make a program that detects people. We can name it people counter. I saw some videos already and I want to do that too.
The problem is that I have to start to learn JavaFX and the library OpenCV.
So I started to create a simple project that starts / pause the webcam and take a snapshot. I saw someone on youtube doing this and I started to recreate it.
The problem is that I have this error:
Exception in Application start method
java.lang.reflect.InvocationTargetException
My code is:
Main
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.fxml.FXMLLoader;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
BorderPane root = (BorderPane) FXMLLoader.load(getClass().getResource("Camera.fxml"));
Scene scene = new Scene(root, 400, 400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
CameraController
package application;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import javax.imageio.ImageIO;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.videoio.VideoCapture;
public class CameraController {
// definitions
#FXML
private Button btn_start, btn_pause, btn_snapshot;
#FXML
private ImageView imgView;
private DaemonThread myThread = null;
int count = 0;
VideoCapture webSource = null;
Mat frame = new Mat();
MatOfByte mem = new MatOfByte(); /// start button
#FXML
protected void startClick(ActionEvent event) {
webSource =new VideoCapture(0);
myThread = new DaemonThread();
Thread t = new Thread(myThread);
t.setDaemon(true);
myThread.runnable = true;
t.start();
btn_start.setDisable(true);
btn_pause.setDisable(false); // stop button
}
#FXML
protected void pauseClick(ActionEvent event) {}
#FXML
protected void snapshotClick(ActionEvent event) {}
class DaemonThread implements Runnable {
protected volatile boolean runnable = false;
#Override
public void run() {
synchronized (this) {
while (runnable) {
if (webSource.grab()) {
try {
webSource.retrieve(frame);
Imgcodecs.imencode(".bmp", frame, mem);
Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
BufferedImage buff = (BufferedImage) im;
imgView.setImage(SwingFXUtils.toFXImage(buff, null));
if (!runnable) {
System.out.println("Going to wait()");
this.wait();
}
} catch (Exception ex) {
System.out.println("Error");
}
}
}
}
}
}
/////////////////////////////////////////////////////////
}
}
The problem is on this line:
BorderPane root = (BorderPane) FXMLLoader.load(getClass().getResource("Camera.fxml"));
Scene scene = new Scene(root,400,400);
Full console error:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat()J
at org.opencv.core.Mat.n_Mat(Native Method)
at org.opencv.core.Mat.<init>(Mat.java:24)
at application.CameraController.<init>(CameraController.java:34)
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 java.lang.Class.newInstance(Unknown Source)
at sun.reflect.misc.ReflectUtil.newInstance(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at application.Main.start(Main.java:15)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
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)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
Exception running application application.Main
Thank you in advance!
Try this it worked for me nu.pattern.OpenCV.loadShared();
I fixed the problem by just adding System.loadLibrary(Core.NATIVE_LIBRARY_NAME):
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
launch(args);
}

OpenSessionInViewInterceptor Spring WebSocket

Has anyone implemented OpenSessionInView yet on Spring WebSocket messages yet? I need to implement this and was hoping for some existing material.
I created some test stuff such as below, but I ran into TransactionExceptions, presumably because when you send back a reply, your session needs to cover both sending and receiving messages
public class OpenSessionInViewChannelInterceptor extends ChannelInterceptorAdapter{
#Inject
private SessionFactory sessionFactory;
#Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
SessionFactory sf = sessionFactory;
if (!TransactionSynchronizationManager.hasResource(sf)) {
// New Session to be bound for the current method's scope...
Session session = openSession();
try {
TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
return super.preSend(message, channel);
}
finally {
SessionFactoryUtils.closeSession(session);
TransactionSynchronizationManager.unbindResource(sf);
}
}
else {
// Pre-bound Session found -> simply proceed.
return super.preSend(message, channel);
}
}
protected Session openSession() throws DataAccessResourceFailureException {
try {
Session session = sessionFactory.openSession();
session.setFlushMode(FlushMode.MANUAL);
return session;
}
catch (HibernateException ex) {
throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
}
}
}
Exception
[MSA] DEBUG [2016-06-21T18:40:05,054] SimpAnnotationMethodMessageHandler.processHandlerMethodException(468) | Searching methods to handle HibernateException
[MSA] ERROR [2016-06-21T18:40:05,057] SimpAnnotationMethodMessageHandler.processHandlerMethodException(478) | Unhandled exception
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134) ~[spring-orm-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
at org.appfuse.dao.hibernate.GenericDaoHibernate.flush(GenericDaoHibernate.java:165) ~[classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]

SecurityException even after giving uses-permission tag for vibration

I am trying to make an Android app which starts vibration on button click.
below is the code related to vibration, I have added uses-permission tag in Android manifest file, still the app terminates giving SecurityException
public class MainActivity extends AppCompatActivity {
private Vibrator v;
TimerTask timerTask;
int n=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
}
public void startTimer(View view) {
final Handler handler = new Handler();
Timer mTimer = new Timer();
v.vibrate(2000);
timerTask = new TimerTask() {
#Override
public void run() {
boolean post = handler.post(new Runnable() {
#Override
public void run() {
TextView timer = (TextView) findViewById(R.id.timer);
timer.setText(n);
n++;
}
});
}
};
mTimer.schedule(timerTask, 0, 100);
}
logcat:
06-17 03:41:12.962 8851-8851/com.neuroapp.ojas.neuroapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40c3ba68)
06-17 03:41:13.022 8851-8851/com.neuroapp.ojas.neuroapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3099)
at android.view.View.performClick(View.java:3571)
at android.view.View$PerformClick.run(View.java:14247)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3094)
at android.view.View.performClick(View.java:3571)
at android.view.View$PerformClick.run(View.java:14247)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.SecurityException: Requires VIBRATE permission
at android.os.Parcel.readException(Parcel.java:1327)
at android.os.Parcel.readException(Parcel.java:1281)
at android.os.IVibratorService$Stub$Proxy.vibrateMagnitude(IVibratorService.java:290)
at android.os.Vibrator.vibrate(Vibrator.java:88)
at android.os.Vibrator.vibrate(Vibrator.java:57)
at com.neuroapp.ojas.neuroapp.MainActivity.startTimer(MainActivity.java:48)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3094)
at android.view.View.performClick(View.java:3571)
at android.view.View$PerformClick.run(View.java:14247)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)

Neo4 Example does not work - Class not found

I have copied and pasted a simple neo4j example from the tutorial section but currently i got the messages:
[INFO] Surefire report directory: /home/kama/ws-git/neo4jexample/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNGMapConfigurator#17bd6a1
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 2.995 sec <<< FAILURE!
Results :
Failed tests: firstTest(com.soebes.tutorials.Neo4JAppTest): com/soebes/tutorials/neo4jexample/RelationTypes
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
The detailed error message:
java.lang.NoClassDefFoundError: com/soebes/tutorials/neo4jexample/RelationTypes
at com.soebes.tutorials.neo4jexample.Neo4JApp.createDb(Neo4JApp.java:44)
at com.soebes.tutorials.neo4jexample.Neo4JApp.main(Neo4JApp.java:25)
at com.soebes.tutorials.Neo4JAppTest.firstTest(Neo4JAppTest.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:691)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:883)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1208)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:758)
at org.testng.TestRunner.run(TestRunner.java:613)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1137)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1062)
at org.testng.TestNG.run(TestNG.java:974)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:76)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:161)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:101)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:115)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
Caused by: java.lang.ClassNotFoundException: com.soebes.tutorials.neo4jexample.RelationTypes
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
The source code of this looks like this:
public class Neo4JApp {
private String greeting;
private GraphDatabaseService graphDb;
private Node firstNode;
private Node secondNode;
private Relationship relationship;
public static void main(final String[] args) {
Neo4JApp hello = new Neo4JApp();
hello.createDb(args[0]);
hello.removeData();
hello.shutDown();
}
void createDb(String path) {
clearDb(path);
graphDb = new EmbeddedGraphDatabase(path);
registerShutdownHook(graphDb);
Transaction tx = graphDb.beginTx();
try {
firstNode = graphDb.createNode();
firstNode.setProperty("message", "Hello, ");
secondNode = graphDb.createNode();
secondNode.setProperty("message", "World!");
relationship = firstNode.createRelationshipTo(secondNode, RelationTypes.KNOWS);
relationship.setProperty("message", "brave Neo4j ");
System.out.print(firstNode.getProperty("message"));
System.out.print(relationship.getProperty("message"));
System.out.print(secondNode.getProperty("message"));
greeting = ((String) firstNode.getProperty("message"))
+ ((String) relationship.getProperty("message"))
+ ((String) secondNode.getProperty("message"));
tx.success();
} finally {
tx.finish();
}
}
private void clearDb(String path) {
try {
FileUtils.deleteRecursively(new File(path));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
void removeData() {
Transaction tx = graphDb.beginTx();
try {
firstNode.getSingleRelationship(RelationTypes.KNOWS, Direction.OUTGOING).delete();
firstNode.delete();
secondNode.delete();
tx.success();
} finally {
tx.finish();
}
}
void shutDown() {
System.out.println();
System.out.println("Shutting down database ...");
graphDb.shutdown();
}
private static void registerShutdownHook(final GraphDatabaseService graphDb) {
// Registers a shutdown hook for the Neo4j instance so that it
// shuts down nicely when the VM exits (even if you "Ctrl-C" the
// running example before it's completed)
Runtime.getRuntime().addShutdownHook(new Thread() {
#Override
public void run() {
graphDb.shutdown();
}
});
}
And the used class RelationTypes looks like this:
public enum RelationTypes implements RelationshipType {
KNOWS,
WHOKNOWS,
}
The project can be found at github.
Currently i don't see the problem?...The RelationTypes are defined in the correct location...May be someone has a hint for me?
The problem was the directory of the unit test which is not allowed to be the target folder itself. It must be a separate folder under target.

Resources