Could not find class QWebElement - java

I'm using QtWebkit to develop a webapplication framework. Now I've begun to ude the DOM and I tryed to use the QWebElement. But when I tried to compile it brought the following error:
symbol : class QWebElement
location: class test
QWebElement elem = new QWebElement();
Here is an example that doesn't work:
import com.trolltech.qt.gui.*;
import com.trolltech.qt.webkit.*;
import com.trolltech.qt.core.*;
import com.trolltech.qt.xml.*;
public class test {
public test() {
QWebElement elem = new QWebElement();
}
public static void main(String[] args) {
QApplication.initialize(args);
new test();
QApplication.exec();
}
}
Could anyone please tell me what I'm doing wrong?
Edit:
I forgot:
When I look in the javadoc, I cant find it! everything says that it doesn't exist. But I've seen other people using it.
Does it exist or not?

Related

Issue with Py4j tutorial

Please note I do not have any previous experience with Java. I am having issues with the following tutorial for Py4j: https://www.py4j.org/getting_started.html
I installed Py4j in an Anaconda environment. I am working in Ubuntu. I set my classpath to include the .jar file for Py4j. When I try to compile the sample code on the above web-page I received an error saying the Stack symbol didn't exist. I tried to add a line of code to import it, but that did not help either (see images).
Error and Directory Structure (image)
Source code:
Stack.java
package py4j.examples;
import java.util.LinkedList;
import java.util.List;
public class Stack {
private List<String> internalList = new LinkedList<String>();
public void push(String element) {
internalList.add(0, element);
}
public String pop() {
return internalList.remove(0);
}
public List<String> getInternalList() {
return internalList;
}
public void pushAll(List<String> elements) {
for (String element : elements) {
this.push(element);
}
}
}
StackEntryPoint.java
package py4j.examples;
import py4j.GatewayServer;
import py4j.examples.Stack; // <-- I added this line but it does not solve the issue
public class StackEntryPoint {
private Stack stack;
public StackEntryPoint() {
stack = new Stack();
stack.push("Initial Item");
}
public Stack getStack() {
return stack;
}
public static void main(String[] args) {
GatewayServer gatewayServer = new GatewayServer(new StackEntryPoint());
gatewayServer.start();
System.out.println("Gateway Server Started");
}
}
I haven't used Java before, so I'm confused about how to link classes during compilation. I've tried looking extensively at Java documentation/resources online and questions related, but can't seem to solve this problem. Could someone point out what I'm doing incorrectly?
Thank you.
You are compiling class StackEntryPoint, but you have not compiled the Stack class yet. Do so first, otherwise it cannot use it to compile StackEntryPoint.
Normally your IDE would solve this for you, but you've got a special setup going here (with the Python integration) so I'm not sure how you'd integrate it.
Ideally, you'll build your Java library as a separate JAR using conventional Java tooling (e.g. Maven and IntelliJ IDEA), but it's not a bad exercise to learn to do it bare-bones first.

Google Translate from Java Application

I am trying to do a simple translator by NetBeans. Firstly, I tried to implement the code below from a forum page:(https://www.java-forums.org/java-applets/38563-language-translation.html)
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
public class Main {
public static void main(String[] args) throws Exception {
// Set the HTTP referrer to your website address.
Translate.setHttpReferrer("http://code.google.com/p/google-api-translate-java");
String translatedText = Translate.execute("Bonjour monde le",
Language.FRENCH, Language.ENGLISH);
System.out.println(translatedText);
}
}
I cannot compile the code. I got cannot resolve symbol for setHttpReferrer() although I added related jar.
Secondly, I tried to implement another solution from the page (https://www.java-forums.org/java-applets/61655-language-translation-using-google-api.html). I got my API key and set it.
import com.google.api.GoogleAPI;
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
public class Translation
{
public static void main(String[] args) throws Exception {
GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java");
GoogleAPI.setKey("i have set my Api key");
String translatedText = Translate.DEFAULT.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);
System.out.println(translatedText);
}
}
When I try to run this I got 403 error as null. Is there a simple way to call Google Translator from Java application?
403 error is documented on the faq as "exceeding your quota". https://cloud.google.com/translate/faq
I suspect however, you get the error because you haven't initialised the API properly, i.e authenticated, ...
Have a look at the setup in this code. Also search for hello welt.
https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-translate/src/test/java/com/google/cloud/translate/TranslateImplTest.java
Hope this helps.

Error "BeanShell 2.0b4 - by Pat Niemeyer (pat#pat.net) bsh%" while running code via eclipse

on running the below selenium code, i am getting an error in a popup:
Eclipse version:3.4.2, Selenium stand alone server used:2.51.0
I had the selenium server added to my project. Not sure why this error is popping up
package upointPckg;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Upoint {
public static void main(String[] args){
String url = "www.google.com";
WebDriver Driver = new FirefoxDriver();
Driver.manage().window().maximize();
Driver.get(url);
}
}
Also tried running it without importing the drivers, it shows the same error:
package uPointPackage;
public class UPointClass {
public static void main(String[] args) {
String url = "www.google.com";
System.out.println(url);
}
}
BeanShell 2.0b4 - by Pat Niemeyer (pat#pat.net)
Hi Guys, I was also getting same error because i had mentioned main() method within multiple classes under same package. So while executing current class from run icon at header in eclipse, compiler was getting confused to which main() method need to be executed.
So solution is to write main() method only in single class within a package or execute only single class by right click on that particular class and run as Java Application,

About Adding import package in Groovy by customizing compilation process

I am writing a java file in which i am parsing the given groovy file using GroovyClassLoader to find the class in it. To do this, i have to import some class (like org.junit.Test) and add package and add static import also. Since i am using old groovy version 1.6, i can not use compilation customizers as these classes not available in this version. So to import custom classes, i had to write custom groovy class loader by extending groovy class loader class like below,
...
public static class DefaultImportClassLoader extends GroovyClassLoader {
public DefaultImportClassLoader(ClassLoader cl){
super(cl);
}
public CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource codeSource) {
CompilationUnit cu = super.createCompilationUnit(config, codeSource);
cu.addPhaseOperation(new SourceUnitOperation() {
public void call(SourceUnit source) throws CompilationFailedException {
//source.getAST().addImport("Test",ClassHelper.make("org.junit.Test")); //working
source.getAST().addImportPackage("org.junit.");
}}, Phases.CONVERSION);
return cu;
}
}
here add import package is not working. Would any one give right suggestion way of using addImportPackage().
I've tested your code and works perfectly for me. (with groovy-all-1.6.9.jar) (edit: groovy-all-1.6.0.jar works fine too)
How do you use your class DefaultImportClassLoader?
I've done:
public static void main(String[] args) throws InstantiationException, IllegalAccessException{
GroovyClassLoader loader = new DefaultImportClassLoader(new GroovyClassLoader());
Class groovyClass = loader.parseClass(DefaultImportClassLoader.class.getClassLoader().getResourceAsStream("so_22729226/test.groovy"));
GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
groovyObject.invokeMethod("run", null);
}
With this Groovy class:
class so_22729226_Test {
def run(){
print Test.class
}
}
And I get the expected output: interface org.junit.Test
If I use the standard loader I get:
Caused by: groovy.lang.MissingPropertyException: No such property: Test for class: so_22729226_Test
Which is the expected behaviour too.

My Scala methods do not return values to Java code

This is a Scala module:
package xpf
import java.io.File
import org.jdom.Element
import org.jdom.input.SAXBuilder
object xmlpf {
def load_file(filename: String): Element = {
val builder = new SAXBuilder
builder.build(new File(filename)).getRootElement
}
}
And here is Java code, calling the method from Scala above:
package textxpf;
import org.jdom.Element;
public class Main {
public static void main(String[] args) {
Element root = xpf.xmlpf.load_file("/home/capkidd/proj/XmlPathFinder/Staff.xml");
System.out.println(root.getName());
}
}
Running java main procedure I see
run:
Exception in thread "main" java.lang.NullPointerException
at textxpf.Main.main(Main.java:8)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Exploring the problem I found that I cannot return any value of any type from any Scala method to the Java code that called it.
I use NetBeans 6.9.1 with Scala 2.8.1 plugin.
scala-library.jar and jdom.jar are properly plugged to the project.
What am I doing wrong?
Has anybody any idea?
Try this and then debug accordingly:
package xpf
import java.io.File
import org.jdom.Element
import org.jdom.input.SAXBuilder
object xmlpf {
def load_file(filename: String): Element = {
val builder = new SAXBuilder
val re = builder.build(new File(filename)).getRootElement
if (re == null) throw new NullPointerException("the root element is null!")
re
}
}
I tried a similar program with no problems:
// ms/MyObject.scala
package ms
object myObject {
def foo(s: String) = s
}
// mj/MyObject2.java
package mj;
public class MyObject2 {
public static void main(String[] args) {
System.out.println(ms.myObject.foo("hello"));
}
}
I compiled both files, then "scala -cp . mj.MyObject2". Works fine with scala 2.8.1.final. Does this example work in your setup?
So, I wonder if it's some sort of environment issue, such as picking up a stale build of the Scala class? Have you tried a clean build from scratch? Is your runtime class path correct?

Categories