Anyone knows how build a Google toolbar to search on web with java?
I have this code but something is wrong.
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt)
{
try {
String searchText = URLEncoder.encode(jTextField1.getText(),"UTF-8");
URLDisplayer.getDefault().showURL
(
new URL
(
"http://www.google.com/search?hl=en&q="+searchText+"&btnG=Google+Search"
)
);
} catch (Exception eee) {
return;
}
What I did:
called www.google.com and used the key words "java URLDisplayer". One of the result was: http://www.labath.org/docs/java/jdk1.2.2/netbeans/OpenAPIs/org/openide/awt/HtmlBrowser.URLDisplayer.html
I called www.google.com and used the key words "download org.openide.awt" (The package of the above class). One of the result was:
http://bits.netbeans.org/download/trunk/jnlp/org-openide-awt/ .
What you can do is following:
Download this jar file and add it to your class path from your Java project. Refresh and rebuild your project.
I tried it with my Eclipse installation, used your code and all compiler errors and warnings disappeared.
Related
Ok, I'm sure this should be pretty easy, but I'm fairly new to Java (I'm more a .NET boy :P) and after following every single recommendation I found here to no success, I think it's time to step back and ask.
I'm trying to start a simple rmi project with a client, a server and a common project where common interfaces are defined. I've just implemented my server code, and when I try to run it to check if everything is fine, I get struck on a java.lang.ClassNotFoundException.
After following several answers on similar issues, I'm fair sure that my problem comes from rmiregistry running on a different location than my project.
I use following code to set registry codebase:
public class Utils {
public static final String CODEBASE = "java.rmi.server.codebase";
public static void setCodeBase(Class<?> c) {
String ruta = c.getProtectionDomain().getCodeSource().getLocation().toString();
String path = System.getProperty(CODEBASE);
if (path != null && !path.isEmpty()) {
ruta = path + " " + ruta;
}
System.setProperty(CODEBASE, ruta);
}
}
Then, I try to start my server code with this main class:
public class MainRegulador {
public static void main(String[] args) throws AccessException, RemoteException, NotBoundException {
Utils.setCodeBase(IRegulador.class);
Registry registro = null;
Remote proxy = null;
try {
Regulador myReg = new Regulador();
proxy = UnicastRemoteObject.exportObject(myReg, 36510);
registro = LocateRegistry.getRegistry();
registro.rebind("Distribuidor", proxy); //this is the line where exception is thrown
System.out.println("El Regulador está corriendo. Pulse ENTER para finalizar el proceso.");
System.in.read();
} catch(Exception ex) {
System.out.println("No se ha logrado inicializar el Registrador");
System.out.println(ex.getMessage());
} finally {
if (registro != null && proxy != null) {
registro.unbind("Distribuidor");
UnicastRemoteObject.unexportObject(proxy, true);
}
}
}
}
But when I run it, always get a java.lang.ClassNotFoundException at IRegulador interface.
Now the fun part:
I've printed to console java.rmi.server.codebase value, and it's pointing to bin folder of project where IRegulador interface is defined. (file:/F:/Practicas%20y%20dem%c3%a1s/Sistemas%20Distribuidos/common/bin/)
Obviously, that project is also set in the classpath of server project
(Regulador)
Workspace and rmiregistry are on different disks
Despite all, it doesn't seem a global classpath problem, as Utils class is on the same project as IRegulador interface, and it runs before the exception is thrown (as java.rmi.server.codebase is correctly set).
I've tried to set the classpath of rmiregistry before calling it (although it is directly discouraged on some answers), but nothing changed.
I've also tried to start rmiregistry.exe from Regulador project bin folder, but also seemed to don't change anything.
Coming from a .NET background, I've always found these classpath issues confusing, and this one is starting to consume much more time than I suspect it deserves. I'm in desperate need of help.
UPDATE: I'm starting to think that the problem is within the url it's passed to the codebase from IRegulador.class. If I paste it into windows explorer, the SO is unable to locate it, so I supose that it's being built with some structure problem that prevents the registry to reach the route:
file:/F:/Practicas%20y%20dem%c3%a1s/Sistemas%20Distribuidos/common/bin/
UPDATE2: I thought path route could be too complex, so I decided to simplify it and strip it from any non-straight character. Now codebase value is
file:/F:/Practicas/SD/common/bin/
However the problem persists, I don't know why rmiregistry is unable to reach that folder.
Then I decided to move the whole project to the same disk where rmiregistry is executed, and see if it changes anything. But nothing changed, same problem.
Ok, finally I got it working...
I've just copied rmiregistry.exe into the common/bin folder and launch it directly from there (previously just had called from there).
This seems to fix the problem with the routes (actually it makes the route available to the registry as it's on the same folder, probably all my codebase writting code is superflous now).
I have a small Unity3d project to integrate JAR with it. My (simplified) java class in Android Studio library project is like below code:
package com.playsqreen.library.api;
... imports ...
public class PlaysreenAPI {
private static PlayscreenAPI _api;
private PlayscreenAPI(Activity activity) {
this.activity = activity;
}
// static method to create singleton
public static PlayscreenAPI build(Activity activity, String key) {
if (_api == null) {
// post processing something
// before returning instance of this class
_api = new PlayscreenAPI(activity);
}
return _api;
}
public String doEchoThis(String msg) {
return "ECHO: " + msg;
}
}
So from Android Studio, I generate my JAR and dump it into ../MyProject/Assets/Plugins/Android and from Unity IDE I can see something like below:
Then I create a C# script like below to load my java class:
void Start () {
_builder = new StringBuilder();
try
{
_builder.Append(">>> Step 1\n");
AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
if (activityClass != null)
{
_builder.Append(">>> Step 2\n");
AndroidJavaObject activity = activityClass.GetStatic<AndroidJavaObject>("currentActivity");
if (activity != null)
{
_builder.Append(">>> Step 3\n");
AndroidJavaClass apiClass = new AndroidJavaClass("com.playsqreen.library.api.PlayscreenAPI");
if (apiClass != null)
{
_builder.Append(">>> Step 4\n");
object[] args = { activity, secretKey };
api = apiClass.CallStatic<AndroidJavaObject>("build", args);
}
}
}
}
catch (System.Exception e)
{
_builder.Append(e.StackTrace.ToString());
}
}
I print my StringBuilder in Text UI object in order for me to capture on which Step my code brakes, and it turns out after step 3. and my Text UI object prints:
java.lang.ClassNotFoundException:com.playsqreen.library.api.PlayscreenAPI and etc...
A thread I found here suggest me to use Java Decompiler to check if the java class really included in the Jar, from this site. And so I did, and the Java Decompiler shows my java class does exists (see below)
So I really stuck now. How can I load my java class from Unity? Please help.
Thanks.
After following lysergic-acid advice below, I includes the rest of jars that required by my custom jar, see below pic. And everything fine :)
You did not post the full error message you are getting at runtime. Also you did not mention which of your debug prints get printed, so i'll try to come up with a few different issues that you can check. Hopefully, one of these can assist in fixing the issue:
JAR name contains '.' (period character). Not sure how Unity interprets this (i've never used such a naming convention myself). Select the .JAR file in Unity and make sure that Unity marks it up as an Android plugin (should have "Android" selected in the plugin importer. I would also try to rename that to a name without any periods just to be on the safe side.
Wrong invocation of the Java method: in your example, the static method build in Java receives a single argument (Activity), but when you're calling it from Unity, you're passing an array of 2 arguments.
Missing dependencies: When your native Java code relies on other classes (e.g: from other libraries), in case you do not include these libraries with your .JAR file, your class will not be loaded at runtime and it will fail with cryptic errors such as NoClassDefFoundException. Make sure to include all dependencies as well.
**Shameless Promotion: ** I offer services to fix Android related issues in Unity. Check it out here, in case you're interested :)
Install newest JDK version and try again.
I create project in Intellij Idea, add tess4j 2.0 from maven, write test application. When I start debug all works fine. When I click "build artifacts" and launch jar file I haven't any result, no errors, nothing.
public class MainApp {
static String fileName = "C:\\Users\\Alex\\Google Drive\\TW\\LIB\\Tess4J\\eurotext.png";
public static void main(String[] args) {
try {
System.setOut(new PrintStream(new File("output-file.txt")));
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Start");
ITesseract instance = new Tesseract1(); // JNA Direct Mapping
try {
String result = instance.doOCR(new File(fileName));
System.out.println(result);
} catch (TesseractException e) {
System.out.println("Error");
System.out.println(e.getMessage());
e.printStackTrace();
}
System.out.println("End");
}
}
Output when debug
Start
The (quick) [brown] {fox} jumps!
Over the $43,456.78 #90 dog
& duck/goose, as 12.5% of E-mail.........
End
Output when launch jar
Start
No "Error", no "End". How it's possible?
I had the same issue. Sometimes it doesn't load classes correctly for some reason. here's how i was able to get it fixed for some far.
Build your artifact and then Remote debug your jar with intellij.
Find out in which line your application breaks.
Then wrap it with try{... line where application breaks..} catch(Error e){e.getMessage(); }
You can see the error message in variable "e" in debug output. So you can determine the issue.
May be this is not an appropriate way to do it. But this is how i was able to track down the errors in my jar file.
How ever it is best to use this as a temporary way to track the errors in your jar and to find out why it breaks and then find out correct way (Which is i'm not currently aware about.. but however got to heard about some library called One-Jar) to build jar without getting any errors on deployment.
I'm creating a small app to send messages to phone numbers using google voice. I made a simple test case that works in Eclipse and can send out messages as expected. However, when I try to run it on a terminal, I keep running into issues. Here is the main class I've written:
import java.io.IOException;
import com.techventus.server.voice.Voice;
public class main_WUB {
public static void main(String[] args) {
// TODO Auto-generated method stub
String username = "wake.up.bot.acc";
String password = "wakeupbotacc";
String originNumber = #;
String pavlePhone = #;
String wakeupMessage = "txt from main_WUB";
try {
Voice voice = new Voice(username, password);
voice.sendSMS(pavlePhone, wakeupMessage);
System.out.println("IT WORKED?");
//voice.call(originNumber, pavlePhone, "1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I've transferred the class into a remote server to test on a linux machine, however, these are the issues I've come up against. When I try to run the main class using
java main_WUB
it returns an exception, stating
Exception in thread "main" java.lang.NoClassDefFoundError: com/techventus/server/voice/Voice at main_WUB.main<main_WUB.java:18> ...
What confuses me is that I ran into this error beforehand in eclipse, and fixed it by importing the reference library in which com.techventus.server.voice.Voice is contained. Now I'm running into the same issue when trying to compile directly. Is there a way to fix this? What am I missing in my command? Any help would be appreciated.
create a jar file for your entire project in eclipse. Procedure for making jar file in eclipse -> right click on your project -> export -> java -> runnable jar file -> select main_WUB in launch configuration drop down list box -> select radio button "extract required libraries into generated jar" -> finish.
now open cmd promt -> goto the path where jar is there -> then give the command "java -jar main_WUB"
It should work.
You need build the JAR with all Libs (dependences) includes.
When you build your project in Eclipse, use the option 'Build with dependences'
In the following code:
public void connect()
{
/*
String selectedPort = "COM1";
String selectedPort = (String)window.cboxPorts.getSelectedItem();
selectedPortIdentifier = (CommPortIdentifier)portMap.get(selectedPort);
*/
}
Eclipse complains that selectedPort cannot be resolved. Why is it even looking inside of a comment?
First, you need to refresh the project.
Second, clean and rebuild. This must be happening as the new class file is not generated for you java file and eclipse is still looking at the previous compiled form.