i have following code
package org.david.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.logical.shared.BeforeSelectionEvent;
import com.google.gwt.event.logical.shared.BeforeSelectionHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.TabBar;
public class TabBar1 implements EntryPoint{
#Override
public void onModuleLoad(){
TabBar bar=new TabBar();
bar.addTab("foo");
bar.addTab("bar");
bar.addTab("baz");
bar.addSelectionHandler(new SelectionHandler(){
public void onSelection(SelectionEvent event){
//let user know what you just did
Window.alert("you clicked tab"+event.getSelectedItem());
}
});
// Just for fun, let's disallow selection of 'bar'.
bar.addBeforeSelectionHandler(new BeforeSelectionHandler() {
public void onBeforeSelection(BeforeSelectionEvent event) {
if (event.getItem().intValue() == 1) {
event.cancel();
}
}
});
}
}
but i have following errors
ompiling 1 source file to C:\XAMPP\xampp\htdocs\TabBar1\build\web\WEB-INF\classes
C:\XAMPP\xampp\htdocs\TabBar1\src\java\org\david\client\TabBar1.java:28: cannot find symbol
symbol : method intValue()
location: class java.lang.Object
if (event.getItem().intValue() == 1) {
Note: C:\XAMPP\xampp\htdocs\TabBar1\src\java\org\david\client\TabBar1.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
C:\XAMPP\xampp\htdocs\TabBar1\nbproject\build-impl.xml:518: The following error occurred while executing this line:
C:\XAMPP\xampp\htdocs\TabBar1\nbproject\build-impl.xml:248: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)
please help
BeforeSelectionEvent should be BeforeSelectionEvent<Integer> so that getItem() returns an Integer instead of an Object.
Object doesn't have an intValue() method, and Integer does.
You should have also seen an unchecked conversion warning in your compile saying something to that effect.
Related
I am trying to have proper assertion (with implicit null checks) for a property of a list element.
The first assertion is working as expected, except that it will generate no proper error message if actual is null.
The second is supposed to provide proper null check for actual, but it's not compiling.
Is there an option tweak the second assertion to make it work?
import java.util.List;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class ExampleTest {
private static class Sub {
private String value;
public String getValue() {
return value;
}
}
private static class Example {
private List<Sub> subs;
public List<Sub> getSubs() {
return subs;
}
}
#Test
void test() {
Example actual = null;
assertThat(actual.getSubs())//not null safe
.extracting(Sub::getValue)
.contains("something");
// assertThat(actual)
// .extracting(Example::getSubs)
// .extracting(Sub::getValue)//not compiling
// .contains("something");
}
}
For type-specific assertions, extracting(Function, InstanceOfAssertFactory) should be used:
assertThat(actual)
.extracting(Example::getSubs, as(list(Sub.class)))
.extracting(Sub::getValue) // compiles
.contains("something");
Assertions.as(InstanceOfAssertFactory) is an optional syntax sugar to improve readability
InstanceOfAssertFactories.list(Class) provides the list-specific assertions after the extracting call
I'm writing my first lines for jbehave.. and already bumping with this error:
import org.jbehave.core.annotations.Given;
import org.jbehave.core.steps.Steps;
public class UserDetailsInputSteps extends Steps
{
#Given("UI for user profile")
public void launchUI(){
}
}
Error: '#Given' not applicable to method
Cannot get what I'm doing wrong. Thanks for any help.
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.
I have Eclipse Java EE IDE Helios Service Release 2 Build id: 20110218-0911; I am trying use them with SeleniumRC and when I compile the code appears the next error message:
Type mismatch: cannot convert from DataProviderSites to annotation
The attribute DataProviderSites is undefined for the annotation type Test
However, when I validate the code, is visualized "the validation completed with no errors or warnings"
The Code in DataProviderSites.java is:
package script;
import org.junit.Test;
import junit.framework.TestCase;
import com.thoughtworks.selenium.SeleneseTestBase;
import org.junit.AfterClass;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.*;
import java.io.File;
import jxl.*;
public class DataProviderSites extends SeleneseTestBase {
#BeforeClass
public void setUp() throws Exception {
SeleniumServer seleniumserver=new SeleniumServer();
seleniumserver.boot();
seleniumserver.start();
setUp("http://www.examinator.ws/", "*firefox");
selenium.open("/");
selenium.windowMaximize();
selenium.windowFocus();
}
#DataProviderSites
(name = "DPS1")
public Object[][] createData1() throws Exception{
Object[][] retObjArr=getTableArray("test\\Resources\\Data\\sitios.xls",
"DataPool", "TestData");
return(retObjArr);
}
#Test(DataProviderSites = "DPS1")
public void testDataProviderSites(String nombre) throws Exception {
selenium.type("sitio", nombre);
if (selenium.isTextPresent("examinator"))
selenium.click("xpath=/descendant::button[#type='submit']");
else
selenium.waitForPageToLoad("30000");
selenium.click("xpath=/descendant::a[text()='"+nombre+"']");
}
#AfterClass
public void tearDown(){
selenium.close();
selenium.stop();
}
public String[][] getTableArray(String xlFilePath, String sheetName, String tableName) throws Exception{
String[][] tabArray=null;
Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
Sheet sheet = workbook.getSheet(sheetName);
int startRow,startCol, endRow, endCol,ci,cj;
Cell tableStart=sheet.findCell(tableName);
startRow=tableStart.getRow();
startCol=tableStart.getColumn();
Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow+1, 100, 64000, false);
endRow=tableEnd.getRow();
endCol=tableEnd.getColumn();
System.out.println("startRow="+startRow+", endRow="+endRow+", " +
"startCol="+startCol+", endCol="+endCol);
tabArray=new String[endRow-startRow-1][endCol-startCol-1];
ci=0;
for (int i=startRow+1;i<endRow;i++,ci++){
cj=0;
for (int j=startCol+1;j<endCol;j++,cj++){
tabArray[ci][cj]=sheet.getCell(j,i).getContents();
}
}
return(tabArray);
}
}
Anybody have a idea to resolve this?
Just click the error and click "Convert to TestNG(Annotations)".
Validation does not check the logic like it does not check for syntax of code.
But when we compile the program it will check for syntax so you got type cast exception.
Validation success does not mean program is correct.
I think annotations(#Test(DataProviderSites = "DPS1"), #DataProviderSites
(name = "DPS1")) causes the exception.
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