Kotlin compile java 12 and kotlin inside Eclipse or command line - eclipse

I tried to create a simple Kotlin command line app
import java.RegistroJ
class Main
fun main(){
var registro:RegistroJ? = RegistroJ()
registro?.setCognome("Baudo")
registro?.setNome("Pippo")
var registro2:RegistroJ = RegistroJ()
registro?.setNext(registro2)
registro2.setCognome("Ballo")
registro2.setNome("Pluto")
var registro3:RegistroJ? = RegistroJ()
registro2.setNext(registro3)
registro3?.setCognome("LOL")
registro3?.setNome("ABC")
while(registro != null){
println("Hello " + registro.getNome() + " " + registro.getCognome())
registro = registro.getNext()
}
}
and a really easy Java class
package java;
public class RegistroJ {
private String cognome;
private String nome;
private RegistroJ next;
public String getCognome() {
return cognome;
}
public void setCognome(String cognome) {
this.cognome = cognome;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public RegistroJ getNext() {
return next;
}
public void setNext(RegistroJ next) {
this.next = next;
}
}
But when I try to compile everything inside Eclipse I get no error but my kotlin .class are not updated.
I have a kotlin equivalent of that class and with that everything works.
But I want to be able to integrate my java class to kotlin
If I try to compile from command line I get:
Main.kt:1:13: error: unresolved reference: RegistroJ
How can I solve this problem?

Like I said in my comments:
I made some research.... I'm almost sure this is only an eclipse plugin bug. I think I will just revert to java at this point I don't like kotlin anyway (null safety is a question mark mess and I don't really like the var namevariable : Type thing) and java works so much better on eclipse (I don't really like intellij).
Yes I can confirm this. Android studio, same code, everything works as expected. So this is a problem with eclipse kotlin plugin and kotlinc compiler. On Android mix kotlin and java works.

Related

Selenium test wont launch Firefox (java with Netbeans)

I have Selenium IDE installed on Firefox, I ran a simple test on it and I exported the test cases to Netbeans under Java/JUNIT4/WebDriver. When I put the code in Netbeans and try to run it, It doesn't launch firefox. I've another simple program that will launch Firefox and go to google and search for cheese but when I try to export a test that I've ran using Selenium IDE, I can't get it to run. I'm not getting any errors and I get "successful build" when I run it, just nothing happens. Here's my code. Thanks
> Blockquotepackage firstpackage;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
//import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.support.ui.Select;
public class FirstPackage {
private WebDriver driver;
private String baseUrl;
//private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
private boolean acceptNextAlert;
public static void main(String args[]){}
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
driver.get("http://google.com");
baseUrl = "https://www.google.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// WebDriver driver = new FirefoxDriver();
System.out.println(driver.getTitle());
}
#Test
public void testGoogleSearch() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.id("gbqfq")).clear();
driver.findElement(By.id("gbqfq")).sendKeys("Google");
driver.findElement(By.id("gbqfb")).click();
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alert.getText();
} finally {
acceptNextAlert = true;
}
}
}
// TODO code application logic h
> Blockquote
This problem is likely due to incompatible versions of Firefox and Selenium Firefox WebDriver.
My guess is that your program that works (the one that goes to Google and searches for cheese) has a different version of Selenium in its path than the one that NetBeans ends up using for your imported tests from the IDE.
For more information on how to deal with the version compatibility issue, see my answer to this question.
I just ran your code on my machine and it worked as expected. Make sure you're using correct jar files and are correctly mapped in your project.

Cordova.exec function doesn't run the native function

I try to make a cordova plugin in IBM worklight.
Javascript:
HelloWorld = {
sayHello: function (success, fail, resultType) {
Cordova.exec(
success,
fail,
"HelloWorld",
"HelloWorld",
[resultType]
);
}
};
function callFunction() {
HelloWorld.sayHello(basarili, basarisiz, "sinan");
}
Java:
package com.Cordova1;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;
import android.util.Log;
public class HelloWorld extends CordovaPlugin {
public boolean execute(String arg0, JSONArray arg1, String arg2) {
Log.d("HelloPlugin", "Hello, this is a native function called from PhoneGap/Cordova!");
return true;
}
}
When I call callFunction I see that fail function worked. Also, I can't see any HelloPlugin message in log window.
What can I do ?
module 09_3 ApacheCordovaPlugin in the samples is indeed using the deprecated Plugin class instead of CordovaPlugin. I have rewritten the HelloWorldPlugin class in module 09_3 to eliminate the deprecated Cordova Plugin API usage. The sample is working fine.
package com.AndroidApacheCordovaPlugin;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
public class HelloWorldPlugin extends CordovaPlugin {
#Override
public boolean execute(String action, JSONArray arguments,
CallbackContext callbackContext) throws JSONException {
if (action.equals("sayHello")) {
String responseText = "Hello world";
try {
responseText += ", " + arguments.getString(0);
callbackContext.success(responseText);
return true;
} catch (JSONException e) {
callbackContext.error(e.getMessage());
}
} else {
callbackContext.error("Invalid action: " + action);
return false;
}
return false;
}
}
A couple of things, 1) did you add a line for your plugin into the config.xml file? and 2) you seem to be overriding the wrong method in CordovaPlugin. It should be:
public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
I was having the same problem. Have a look at module 09_3 ApacheCordovaPlugin in the samples. That example does work for me, but they are using the deprecated Plugin class instead of CordovaPlugin.
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
...
public class HelloWorldPlugin extends Plugin {
public PluginResult execute(String action, JSONArray arguments, String callbackId) {
The deprecated class returns PluginResult, not a boolean. I've tried the same code using the CordovaPlugin signature and that results in a fail every time. Apparently whatever WL code is invoking the plugin is apparently expecting the signature of the deprecated class.
I solved the problem.
I use the version 2.4 of cordova. I can't understand why it didn't work. when I use "cordova.exec" it doesn't work, however when I use PhoneGap.exec it works.
Also I looked for the definition;
In the last line of cordova-2.4.0.js, it says
var PhoneGap = cordova;
Ok, Phonegap was defined, but I don't know why cordova doesn't work.
Thank you for your answers.

error when i run my RMI project

what do i have to do when I have this error:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException
I added the path of the bin in JDK in the properties of "MY computer": this one "C:\Program Files\Java\jdk1.6.0_19\bin"
and I entered to run-cmd-
cd C:\Users\user\Documents\NetBeansProjects\CountRMI\src\countrmi
start rmiregistry
and i run the server, so this error appear
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException
Thank u
Consider looking at the Cajo project. It wraps RMI so you don't have to worry about starting rmi registries and the such.
See the example below from one of the Cajo wiki pages
Duck.java
public interface Duck {
boolean looks();
boolean walks();
boolean talks();
}
DuckServer.java
import gnu.cajo.invoke.Remote;
import gnu.cajo.utils.ItemServer;
public class DuckServer implements Duck {
public boolean looks() {
System.out.println("hi there!");
return true;
}
public boolean walks() {
System.out.println("waddle waddle");
return true;
}
public boolean talks() {
System.out.println("quack quack!");
return true;
}
public static void main(String args[]) throws Exception { // simple unit test
Remote.config(null, 1198, null, 0); // use cajo port 1198
ItemServer.bind(new DuckServer(), "Donald");
System.out.println("duck server running");
}
}
DuckClient.java
import gnu.cajo.utils.extra.TransparentItemProxy;
public class DuckClient { // try out DuckServer
public static void main(String args[]) throws Exception {
Duck duck = (Duck)TransparentItemProxy.getItem(
"//serverHost:1198/Donald",
new Class[] { Duck.class }
);
System.out.println("looks like = " + duck.looks());
System.out.println("walks like = " + duck.walks());
System.out.println("talks like = " + duck.talks());
}
}
The time has passed, but maybe this helps someone. When you put
cd C:\Users\user\Documents\NetBeansProjects\CountRMI\src\countrmi
you are setting de path to sources files, but yo have to set this to the classes files, in this way
cd C:\Users\user\Documents\NetBeansProjects\CountRMI\build\classes
and start rmiregistry, of course
at least, it worked fine for me.

Problem on aboutBox() in java

I'm developing a javadesktop application in Netbeans 6.9 and everything is perfect but...it gives me an error on this :
#Action
public void showAboutBox()
{
if (aboutBox == null) {
JFrame mainFrame = Mp4App.getApplication().getMainFrame();
aboutBox = new mp4AboutBox(mainFrame);
aboutBox.setLocationRelativeTo(mainFrame);
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
#SuppressWarnings("unchecked")
and this is the error :
Compiling 1 source file to Q:\Mp3 App\mp4-beta\mp4\build\classes
Q:\Mp3 App\mp4-beta\mp4\src\mp4\Mp4View.java:223: cannot find symbol
symbol : class mp4AboutBox
location: class mp4.Mp4View
aboutBox = new mp4AboutBox(mainFrame);
1 error
Q:\Mp3 App\mp4-beta\mp4\nbproject\build-impl.xml:603:
The following error occurred while executing this line:
Q:\Mp3 App\mp4-beta\mp4\nbproject\build-impl.xml:284: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 8 seconds)
the real problem is that this is the code generated from netbeans...also if you create a new Project->java->Destop Application and you leave it there without adding nothing,it gives always me the same problem... what to do ????????????
netbeans version: 6.9.1
jdk version: 7
O.S : Windows 7 32 bit
You shouldn't create your GUI using Netbeans because it generates unreadable code. The Swing-Package is pretty straight forward, so you should use it.
To the Error: Do you have a mp4AboutBox-class and what is in it?
You might be missing an import. Provide your imports in that file.
I had a similar question that I got the solution to by re-installing netbeans 6.9.1.
This is the solution I came up with from that:
TestProject class:
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
public class TestProject extends SingleFrameApplication {
#Override protected void startup() {
show(new AppView(this));
}
#Override protected void configureWindow(java.awt.Window root) { }
public static TestProject getApplication() {
return Application.getInstance(TestProject.class);
}
public static void main(String[] args) {
launch(TestProject.class, args);
}
}
AppView JFrame:
import org.jdesktop.application.FrameView;
import org.jdesktop.application.SingleFrameApplication;
public class AppView extends FrameView {
public AppView(SingleFrameApplication app) {
super(app);
JFrame mainFrame = TestProject.getApplication().getMainFrame();
AboutBox newAboutBox = new AboutBox();
newAboutBox.setLocationRelativeTo(mainFrame);
TestProject.getApplication().show(newAboutBox);
}
}

GWT problem with calling Java methods from JSNI

I tried the example from google at this page:
http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=DevGuideJavaFromJavaScript
I want to be able to call a Java method from JSNI, but nothing happens. No errors but the methods are not called. However, I can modify the fields from my class.
Here is the code I tried:
package com.jsni.client;
import com.google.gwt.core.client.EntryPoint;
public class Testjsnii implements EntryPoint {
String myInstanceField;
static int myStaticField;
void instanceFoo(String s) {
System.out.println(s);
}
static void staticFoo(String s) {
System.out.println(s);
}
public native void bar(Testjsnii x, String s) /*-{
this.#com.jsni.client.Testjsnii::instanceFoo(Ljava/lang/String;)(s);
x.#com.jsni.client.Testjsnii::instanceFoo(Ljava/lang/String;)(s);
#com.jsni.client.Testjsnii::staticFoo(Ljava/lang/String;)(s);
var val = this.#com.jsni.client.Testjsnii::myInstanceField;
}-*/;
public void onModuleLoad() {
bar(this,"Hello");
}
}
It prints nothing on the console but only a waring that says:
[WARN] [testjsnii] - JSNI method
'#com.jsni.client.Testjsnii::bar(Lcom/jsni/client/Testjsnii;Ljava/lang/String;)' returned > a value of type JavaScript object(1) but was declared void; it should not have returned a > value at all
I wonder what is the problem.
Thanks for the help.
You're actually running into a Chrome (10-dev) issue with the GWT DevMode plugin: http://code.google.com/p/google-web-toolkit/issues/detail?id=5778