Error in JavaFX FXML tutorial - eclipse

I have followed every step in this (https://blogs.oracle.com/jmxetc/entry/connecting_scenebuilder_edited_fxml_to) tutorial, and yet keep getting an error about this section in the controller class:
myButton.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("That was easy, wasn't it?");
}
});
The only difference I can think of is that it was written for FX 2.0 and not 8.0?
Exception in Application start method
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: 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(Thread.java:745)
Caused by: java.lang.Error: Unresolved compilation problems:
The method setOnAction(EventHandler<ActionEvent>) in the type ButtonBase is not applicable for the arguments (new EventHandler<ActionEvent>(){})
EventHandler cannot be resolved to a type
The method handle(ActionEvent) of type new EventHandler<ActionEvent>(){} must override or implement a supertype method
at simple.SimpleController.initialize(SimpleController.java:24)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
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 simple.Main.start(Main.java:26)
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)
Exception running application simple.Main
Let me know if you need to see the classes and FXML files (dw, they're very short)
Thank you!
PS- Please bear with me if I need clarification about your answer because as a Java newbie I often get confused!
EDIT 1:
package simple;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SimpleController
implements Initializable {
#FXML // fx:id="myButton"
private Button myButton; // Value injected by FXMLLoader
#Override // This method is called by the FXMLLoader when initialization is complete
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
assert myButton != null : "fx:id=\"myButton\" was not injected: check your FXML file 'simple.fxml'.";
// initialize your logic here: all #FXML variables will have been injected
myButton.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("That was easy, wasn't it?");
}
});
}
}

You are missing the import for EventHandler, and you have the wrong import for ActionEvent. (Also you have imported ActionListener for some reason, though you never use it.)
Your imports should be
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;

Related

Create a Movie Player in javafx using eclipse

I want to create a Movie Player in javafx using eclipse.My code is compile successfully but it gives run time error.I tried using different file path also.
But it not resolved the error.
My code is
package Player3;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MediaPlayer3 extends Application{
public static void main(String args[])
{
launch(args);
}
public void start(Stage stage) throws Exception {
Group root = new Group();
Media media =new Media("file:////‪C://Kaise.MP4");
MediaPlayer player4=new MediaPlayer(media);
MediaView view = new MediaView(player4);
root.getChildren().add(view);
Scene scene =new Scene(root,400,400,Color.BLACK);
stage.setScene(scene);
stage.show();
player4.play();
}
}
The error is
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 sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
java.lang.RuntimeException: Exception in Application start method
java.lang.RuntimeException: Exception in Application start method
As #Sergei Sirik mentioned this is JavaFX and not 'pure' java. Anyway reading the documentation of Media class for the constructor(String source) you will see :
The source must represent a valid URI and is immutable. Only HTTP, FILE, and JAR URLs are supported. If the provided URL is invalid then an exception will be thrown
So I will suggest first to create a File object ( to be able to check file permissions for read write etc ) and after that just pass the mediaFile.toURI().toString() to the Media class constructor and it will open.
Edit :
I guess you will use a FileChooser in future in order to load your video so it will make the file creation and handling much easier.
I had test the code below and it loads successfully my videos on my computer.
import java.io.File;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String args[]) {
launch(args);
}
public void start(Stage stage) throws Exception {
Group root = new Group();
FileChooser fc = new FileChooser();
File x = fc.showOpenDialog(null);
Media media = new Media(x.toURI().toString());
MediaPlayer player4 = new MediaPlayer(media);
MediaView view = new MediaView(player4);
root.getChildren().add(view);
Scene scene = new Scene(root, 400, 400, Color.BLACK);
stage.setScene(scene);
stage.show();
player4.play();
}
}
If you have any error like :
MediaException: MEDIA_UNSUPPORTED : Unrecognized file signature!
It's probably cause you alter the file signature by hand or try to play an unsupported file format like mkv.

TypeNotPresentException with JUnitParamsRunner

My Java-Code looks like this:
Person.java
public class Person {
private int age;
public Person(int age) {
this.age = age;
}
public boolean isAdult() {
return age >= 18;
}
#Override
public String toString() {
return "Person of age: " + age;
}
}
PersonTest.java
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
#RunWith(JUnitParamsRunner.class)
public class PersonTest {
#Test
#Parameters({
"17, false",
"22, true" })
public void personIsAdult(int age, boolean valid) throws Exception {
assertThat(new Person(age).isAdult(), is(valid));
}
}
And if I press "Run As" => "JUnit Test Case" I get the "java.lang.TypeNotPresentException: Type [unknown] not present".
Here the full Stack Trace:
java.lang.TypeNotPresentException: Type [unknown] not present
at sun.reflect.annotation.TypeNotPresentExceptionProxy.generateException(TypeNotPresentExceptionProxy.java:46)
at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:84)
at com.sun.proxy.$Proxy2.value(Unknown Source)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.NoClassDefFoundError: org/junit/runners/BlockJUnit4ClassRunner
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1015)
at java.lang.ClassLoader.loadClass(ClassLoader.java:413)
at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:439)
at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:420)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:349)
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
at java.lang.Class.createAnnotationData(Class.java:3521)
at java.lang.Class.annotationData(Class.java:3510)
at java.lang.Class.getAnnotation(Class.java:3415)
at org.junit.internal.builders.IgnoredBuilder.runnerForClass(IgnoredBuilder.java:10)
... 11 more
JUnit-Version is 4.12
Hamcrest-all Version is 1.3
Hamcrest-core Version is 1.3
Does anyone has an advice how to fix this Problem? Thanks in advance.
I now was able to solve my own problem using this forum here: https://jira.spring.io/browse/SPR-9450
I used the libraries as User Libraries, but obviously this was the mistake. When I use it as external jars in my classpath everything works.

hadoop mapreduce wordcount program

I tried to run a word count program in eclipse. in the browser the output directories are being created but i am not getting any out put. I am getting the following error. plz help me out. please. I am struct at the last point.
I gave the following command to execute the program.
hduser#niki-B85M-D3H:/home/niki/workspace$ hadoop jar wordcount.jar WordCount /user/hadoop/dir1/file.txt wordcountoutput
The output file named wordcountoutput is created but the error is displayed as follows.
I tried to run a word count program in eclipse. in the browser the output directories are being created but i am not getting any out put. I am getting the following error. plz help me out. please. I am struck at the last point.
I gave the following command to execute the program.
hduser#niki-B85M-D3H:/home/niki/workspace$ hadoop jar wrd.jar WordCount /user/hduser/outputwc /user/hduser/outputwc/
The output file named wordcountoutput is created but the error is displayed as follows.
5/12/24 15:15:46 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at WordCount.run(WordCount.java:29)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:84)
at WordCount.main(WordCount.java:48)
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.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
this is the exception i am getting now at the final step
WordCount.java
import java.io.IOException;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider.Text;
public class WordCount extends Configured implements Tool{
#Override
public int run(String[] args) throws Exception {
if(args.length<2){
System.out.println("plz give input and output directories");
return -1;
}
JobConf conf = new JobConf();
//conf.setJarByClass(WordCount.class);
conf.setJar("wrd.jar");
FileInputFormat.setInputPaths(conf,new Path(args[1]));
FileOutputFormat.setOutputPath(conf,new Path(args[2]));
conf.setMapperClass(WordMapper.class);
conf.setReducerClass(WordReducer.class);
conf.setMapOutputKeyClass(Text.class);
conf.setMapOutputValueClass(IntWritable.class);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
JobClient.runJob(conf);
return 0;
}
public static void main(String args[]) throws Exception{
int exitCode =ToolRunner.run(new WordCount(), args);
System.exit(exitCode);
}
}
Word Reducer.java
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
public class WordReducer extends MapReduceBase implements Reducer<Text,IntWritable,Text,IntWritable>{
#Override
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter r)
throws IOException {
int count=0;
while(values.hasNext()){
IntWritable i= values.next();
count+=i.get();
}
output.collect(key,new IntWritable(count));
}
}
WordMapper.java
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
public class WordMapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
#Override
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter r)
throws IOException {
String s = value.toString();
for(String word:s.split(" ")){
if(word.length()>0){
output.collect(new Text(word), new IntWritable(1));
}
}
}
}
Try this out:
public static void main(String args[]) throws Exception{
int exitCode =ToolRunner.run(new Configuration(), new WordCount(), args);
System.exit(exitCode);}
according to this

AspectJ and Java8 - bad type on operand stack

Looking at This Eclipse Bug it seems the Java Verifier (since 1.6) has had issues with ApsectJ.
The bug says AspectJ 1.8.1 will fix the problem. But using that with Java8u11 I still get the verify error.
I'm running JUnit4 under STS 3.6.0 (Eclipse 4.4). I believe this configuration is the very latest available of all packages.
Completely replaced the remainder of text with requested example. This seems to be limited to #Around advice. #Before works fine.
JUnit:
package com.test.aspectjdemo.junit;
import static org.junit.Assert.*;
import org.junit.Test;
import com.test.aspectjdemo.domain.AspectTarget;
public class AspectTargetTest {
#Test
public void testFirstMethod() throws Throwable {
AspectTarget aspectTarget = new AspectTarget();
aspectTarget.firstMethod();
}
}
Vmarg: -javaagent:C:....m2\repository\org\aspectj\aspectjweaver\1.8.1\aspectjweaver-1.8.1.jar
Class under test (I had some problems because proceed apparently declares it throws Throwable, which makes sense, but this simple test didn't throw anything. So I added a faux exception make it compile :
package com.test.aspectjdemo.domain;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class AspectTarget {
final Logger logger = LogManager.getLogger();
int x = 1;
public void firstMethod() throws Throwable {
logger.info("Start First Method");
x = secondMethod(x);
logger.info("Exit X is {}", x);
}
private int secondMethod(int x) throws Throwable {
logger.info("input is {}", x++);
if (x==100)
throw new RuntimeException();
return new Integer(x);
}
}
The Aspect:
package com.test.aspectjdemo.aspects;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
public aspect LoggingAspect {
static final Logger logger = LogManager.getLogger();
/**
* Exclude JUnit methods
*/
#Pointcut("!within(com.test.aspectjdemo.junit..*Test)")
public void noJunit() {}
#Pointcut("execution(* com.test.aspectjdemo.domain.*.*(..)) && noJunit()")
public void allMethods() { }
#Around("allMethods()")
public Object allmethods(ProceedingJoinPoint joinPoint) throws Throwable {
return joinPoint.proceed();
}
Finally once again the Error, which is actually thrown when the JUnit attempts to instantiate the AspectTarget (first line of testFirstMethod method).
java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
com/test/aspectjdemo/domain/AspectTarget.secondMethod(I)I #23: invokestatic
Reason:
Type 'org/aspectj/lang/JoinPoint' (current frame, stack[2]) is not assignable to integer
Current Frame:
bci: #23
flags: { }
locals: { 'com/test/aspectjdemo/domain/AspectTarget', integer, integer, 'org/aspectj/lang/JoinPoint' }
stack: { 'com/test/aspectjdemo/domain/AspectTarget', integer, 'org/aspectj/lang/JoinPoint', 'com/test/aspectjdemo/aspects/LoggingAspect', null, 'org/aspectj/lang/JoinPoint' }
Bytecode:
0000000: 1b3d b200 4b2a 2a1c b800 51b8 0057 4e2a
0000010: 1c2d b800 6601 2db8 006a b800 6dac
at com.test.aspectjdemo.junit.AspectTargetTest.testFirstMethod(AspectTargetTest.java:13)
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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
The problem is that you mix native AspectJ syntax (public aspect LoggingAspect) with annotation-style #AspectJ syntax. I can reproduce the problem this way.
Correct #AspectJ syntax:
package com.test.aspectjdemo.aspects;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
#Aspect
public class LoggingAspect {
#Pointcut("!within(com.test.aspectjdemo.junit..*Test)")
public void excludeJUnit() {}
#Pointcut("execution(* com.test.aspectjdemo.domain.*.*(..)) && excludeJUnit()")
public void allMethods() {}
#Around("allMethods()")
public Object allmethods(ProceedingJoinPoint thisJoinPoint) throws Throwable {
System.out.println(thisJoinPoint);
return thisJoinPoint.proceed();
}
}
Correct native AspectJ syntax:
package com.test.aspectjdemo.aspects;
public aspect LoggingAspect {
pointcut excludeJUnit() :
!within(com.test.aspectjdemo.junit..*Test);
pointcut allMethods() :
execution(* com.test.aspectjdemo.domain.*.*(..)) && excludeJUnit();
Object around() : allMethods() {
System.out.println(thisJoinPoint);
return proceed();
}
}

error when I use GWT RPC

I have a problem with Eclipse when I use an RPC..
If I use a single method call it's all in the right direction but if I add a new method to handle the server I get the following error:
com.google.gwt.core.client.JavaScriptException: (null): null
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeBoolean(ModuleSpace.java:184)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeBoolean(JavaScriptHost.java:35)
at com.google.gwt.user.client.rpc.impl.RpcStatsContext.isStatsAvailable(RpcStatsContext.java)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:221)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
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 com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
at java.lang.Thread.run(Thread.java:619)
Can I have more services in an asynchronous call right? Where am I wrong?
This is my implementation MyService:
package de.vogella.gwt.helloworld.client;
import com.google.gwt.user.client.rpc.RemoteService;
public interface MyService extends RemoteService {
//chiamo i metodi presenti sul server
public void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann);
public void setWeb(String userCorrect,String query, String titolo,String snippet,String url);
}
MyServiceAsync
package de.vogella.gwt.helloworld.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface MyServiceAsync {
void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann,AsyncCallback<Void> callback);
void setWeb(String userCorrect,String query, String titolo,String snippet,String url, AsyncCallback<Void> callback);
}
RPCService:
package de.vogella.gwt.helloworld.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.FlexTable;
public class RPCService implements MyServiceAsync {
MyServiceAsync service = (MyServiceAsync) GWT.create(MyService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) service;
public RPCService()
{
endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "rpc");
}
public void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann,AsyncCallback callback)
{
service.creaXML(nickname, pass, email2, gio, mes, ann, callback);
}
public void setWeb(String userCorrect,String query, String titolo,String snippet,String url,AsyncCallback callback) {
service.setWeb(userCorrect,query, titolo,snippet,url,callback);
}
}
MyServiceImpl
package de.vogella.gwt.helloworld.server;
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import de.vogella.gwt.helloworld.client.MyService;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.NodeList;
public class MyServiceImpl extends RemoteServiceServlet implements MyService {
//metodo che inserisce il nuovo iscritto
public void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann){
.......
}
public void setWeb(String userCorrect,String query, String titolo,String snippet,String url) {
.....
}
In the app in client-side I do
RPCService rpc2 = New RPCService()
rpc2.setWeb(..,...,...,...,callback);
and
RPCService rpc = New RPCService()
rpc.creaXML(..,...,...,...,callback); (in other posizions in the code...)
and..
AsyncCallback callback = new AsyncCallback()
{
public void onFailure(Throwable caught)
{
Window.alert("Failure!");
}
public void onSuccess(Object result)
{
Window.alert("Successoooooo");
}
};
Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Servlets -->
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>De_vogella_gwt_helloworld.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>rPCImpl</servlet-name>
<servlet-class>de.vogella.gwt.helloworld.server.MyServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>rPCImpl</servlet-name>
<url-pattern>/de_vogella_gwt_helloworld/rpc</url-pattern>
</servlet-mapping>
</web-app>
Thank you all for your attention
Sebe
You seem to be invoking your RPC services in a strange way.
There is a tutorial in GWT web page showing how this should be done.
EDIT:
This bug reported in GWT bugs database may be related to your problem (the stack trace is very similar). Some information about the bug can be also found here.
I lost my pass and I recreate the account... I see your board..it's a problem with my browser web... If I use Internet Explorer it work fine, but If I use Firefox (my predefinite browser) throw the exception (but It compile fine). I have not found anything that I can fix it...