Eclipse error com.avaje.ebean.EbeanServer not resolved - eclipse

In Eclipse I have an error on my top blank line and I cant get rid of it. Here's my code (I am making a bukkit plugin):
//this is where I get the error
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
#Override
public void onEnable() {
new EventHandler(this);
}
#Override
public void onDisable() {
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("BLANK") && sender instanceof Player) {
Player player = (Player) sender;
return true;
}
return false;
}
}
I can't find anyway around it. Please help.

You appear to be missing your package name. Try this instead:
package my.package.name;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
#Override
public void onEnable() {
new EventHandler(this);
}
#Override
public void onDisable() {
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("BLANK") && sender instanceof Player) {
Player player = (Player) sender;
return true;
}
return false;
}
}
Remember to replace my.package.name with your package name.

Related

manipulate string to substring on java

after long googling days, no success.
i just want to get the first number from "result=0.23 562"
here is my code, i will appreciate any help!
by the way this is an android app
the function ServerTransfer() just getting data from phone's USB.
package com.WiMiapplication.wimi;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class trackingActivity extends Activity{
TextView Fields;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.trackingsub);
}
#Override
protected void onResume() {
super.onResume();
new ServerTransfer(){
int indexend=0;
int indexstart=0;
private String Dude ="3";
#Override
public void onPostExecute(String result){
for(int i=0;i<=result.length();i++){
String Spectate=Character.toString(result.charAt(i));
if(!Spectate.equals(" ")){
indexend++;
} else{
Dude =result.substring(result.indexOf(" ") + 3);
}
}
Fields = (TextView)findViewById(R.id.X_location);
Fields.setText(result);
}
}.execute();
}
}
try this:
Dude =result.split(" ")[0];

Launch JavaFX application from another class

I need to start a javafx Application from another "container" class and call functions on the Application, but there doesn't seem to be any way of getting hold of a reference to the Application started using the Application.launch() method. Is this possible?
Thanks
Suppose this is our JavaFX class:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class OKButton extends Application {
#Override
public void start(Stage stage) {
Button btn = new Button("OK");
Scene scene = new Scene(btn, 200, 250);
stage.setTitle("OK");
stage.setScene(scene);
stage.show();
}
}
Then we may launch it from another class like this:
import javafx.application.Application;
public class Main {
public static void main(String[] args) {
Application.launch(OKButton.class, args);
}
}
I had the same problem as this and got round it using this hack:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.util.concurrent.CountDownLatch;
public class StartUpTest extends Application {
public static final CountDownLatch latch = new CountDownLatch(1);
public static StartUpTest startUpTest = null;
public static StartUpTest waitForStartUpTest() {
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return startUpTest;
}
public static void setStartUpTest(StartUpTest startUpTest0) {
startUpTest = startUpTest0;
latch.countDown();
}
public StartUpTest() {
setStartUpTest(this);
}
public void printSomething() {
System.out.println("You called a method on the application");
}
#Override
public void start(Stage stage) throws Exception {
BorderPane pane = new BorderPane();
Scene scene = new Scene(pane, 500, 500);
stage.setScene(scene);
Label label = new Label("Hello");
pane.setCenter(label);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
and then the class you are launching the application from:
public class StartUpStartUpTest {
public static void main(String[] args) {
new Thread() {
#Override
public void run() {
javafx.application.Application.launch(StartUpTest.class);
}
}.start();
StartUpTest startUpTest = StartUpTest.waitForStartUpTest();
startUpTest.printSomething();
}
}
Hope that helps you.
Launch JavaFX in other Class using Button:
class Main extends Application{
public void start(Stage s)throws Exception{
event();
s.show();
}
public void event(){
btn.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent ae){
Stage s = new Stage();
new SubClassName().start(s);
}
});
}
public static void main(String[] args) {
launch(args);
}
}
class SubClassName{
public void start(Stage s){
Pane pane = new Pane();
Scene addFrame = new Scene(pane,280,450);
s.setScene(addFrame);
s.show();
}
}
I'm not sure what you're trying to achieve, but note that you can e.g call from another class Application.launch to start the JavaFX Application thread and Platform.exit to stop it.
The above ways of invoking other javafx class from another sometimes work. Struggling to find an ultimate way to do this brought me to the following walk around:
Suppose this is the javafx class that exteds Application we wish to show from a different class, then we should add the following lines
class ClassToCall extends Application{
//Create a class field of type Shape preferably static...
static Stage classStage = new Stage();
#Override
public void start(Stage primaryStage){
// Assign the class's stage object to
// the method's local Stage object:
classStage = primaryStage ;
// Here comes some more code that creates a nice GUI.....
// ......
}
}
And now from the other place in the project, in order to open the window
that the above class creates do the following:
// Suppose we want to do it with a button clicked:
btn1.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
//create an object of the class you wish to invoke its
//start() method:
ClassToCall ctc = new ClassToCall();
// Then call its start() method in the following way:
ctc.start(ClassToCall.classStage);
}// End handle(ActionEvent event)
});// End anonymous class

How To Get Tab Text in GWT?

how do I get the text of a selected tab in GWT? I see there is a method com.google.gwt.user.client.ui.TabBar.setTabText(String text) but how do I get the text?
I ended up extending TabPanel like so:
package com.benhowden.gwttemplate;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.Widget;
import java.util.ArrayList;
import java.util.List;
public class DFSTabPanel extends TabPanel {
List<String> tabsTexts;
public DFSTabPanel() {
super();
tabsTexts = new ArrayList<String>();
}
#Override
public void add(Widget w, String tabText) {
super.add(w, tabText);
tabsTexts.add(tabText);
}
#Override
public boolean remove(int index) {
boolean removed = super.remove(index);
if(removed) {
tabsTexts.remove(index);
return removed;
}
return removed;
}
#Override
public void clear() {
super.clear();
tabsTexts.clear();
}
public String getTabText(int index) {
return tabsTexts.get(index);
}
}

Make a draggable popup background transparent in javafx?

I'm doing a little excersice i JavaFX with netbeans, I'm trying to make a popup when I clic a button, but the popup have a white background, how can I do it transparent?
Thanks.
Here is the code:
Main:
package test;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.image.Image;
public class Test extends Application {
#Override
public void start(Stage stage) throws Exception {
stage.initStyle(StageStyle.TRANSPARENT);
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root, Color.TRANSPARENT);
stage.setScene(scene);
stage.show();
stage.setTitle("integrIX");
stage.getIcons().add(new Image("test/integrix_icon.png"));
}
public static void main(String[] args) {
launch(args);
}
}
FXMLController:
package test;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class FXMLDocumentController implements Initializable {
#FXML
private Button menu1;
#FXML
private Button menu2;
#FXML
private Button menu3;
#FXML
private Button menu4;
#FXML
private Button closeButton;
#FXML
private Button minimizeButton;
#FXML
private Pane paneMain;
private double xOffset;
private double yOffset;
private Stage popup;
#Override
public void initialize(URL url, ResourceBundle rb) {
Platform.runLater(new Runnable(){
private StageStyle Color;
#Override
public void run(){
Stage stage = Stage.class.cast(paneMain.getScene().getWindow());
makeDraggable(stage, paneMain);
Parent popupLoaded = null;
try {
popupLoaded = FXMLLoader.load(getClass().getResource("popup.fxml"));
} catch (IOException ex) {
Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
}
Scene popupScene = new Scene(popupLoaded);
popup = new Stage();
popup.initStyle(StageStyle.TRANSPARENT);
popup.initModality(Modality.WINDOW_MODAL);
popup.initOwner(stage);
popup.setScene(popupScene);
}
});
}
#FXML
public void diagnosticButton(){
assert popup != null;
popup.show();
}
#FXML
public void handleClick(MouseEvent event) {
//System.err.println("BOUND OFFSET");
//xOffset = event.getSceneX();
//yOffset = event.getSceneY();
//xOffset = event.getSceneX();
//yOffset = event.getSceneY();
}
#FXML
public void handleDrag(MouseEvent event) {
//System.err.println("DRAGGING");
Stage stage = Stage.class.cast(paneMain.getScene().getWindow());
stage.setX(event.getScreenX() - xOffset);
stage.setY(event.getScreenY() - yOffset);
}
public void makeDraggable( final Stage stage, final Node byNode) {
byNode.setOnMousePressed(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
// record a delta distance for the drag and drop operation.
xOffset = stage.getX() - mouseEvent.getScreenX();
yOffset = stage.getY() - mouseEvent.getScreenY();
byNode.setCursor(Cursor.MOVE);
}
});
byNode.setOnMouseReleased(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
byNode.setCursor(Cursor.DEFAULT);
}
});
byNode.setOnMouseDragged(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
stage.setX(mouseEvent.getScreenX() + xOffset);
stage.setY(mouseEvent.getScreenY() + yOffset);
} });
byNode.setOnMouseEntered(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
if (!mouseEvent.isPrimaryButtonDown()) {
byNode.setCursor(Cursor.DEFAULT);
} } });
byNode.setOnMouseExited(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
if (!mouseEvent.isPrimaryButtonDown()) {
byNode.setCursor(Cursor.DEFAULT);
} } });
}
#FXML
public void changeButtonOnOver(Event e){
menu1.getStyleClass().add("boton_over");
}
#FXML
public void changeButtonOnExited(){
menu1.getStyleClass().remove("boton_over");
}
#FXML
public void changeButtonOnOver2(Event e){
menu2.getStyleClass().add("boton_over");
}
#FXML
public void changeButtonOnExited2(){
menu2.getStyleClass().remove("boton_over");
}
#FXML
public void changeButtonOnOver3(Event e){
menu3.getStyleClass().add("boton_over");
}
#FXML
public void changeButtonOnExited3(){
menu3.getStyleClass().remove("boton_over");
}
#FXML
public void changeButtonOnOver4(Event e){
menu4.getStyleClass().add("boton_over");
}
#FXML
public void changeButtonOnExited4(){
menu4.getStyleClass().remove("boton_over");
}
#FXML
public void changeButtonOnOverClose(){
closeButton.getStyleClass().add("btn_cerrar_over");
}
#FXML
public void changeButtonOnExitedClose(){
closeButton.getStyleClass().remove("btn_cerrar_over");
}
#FXML
public void changeButtonOnOverMinimize(){
minimizeButton.getStyleClass().add("btn_cerrar_over");
}
#FXML
public void changeButtonOnExitedMinimize(){
minimizeButton.getStyleClass().remove("btn_cerrar_over");
}
#FXML
public void exit(){
Stage stage = Stage.class.cast(closeButton.getScene().getWindow());
stage.close();
}
#FXML
public void minimize(){
Stage stage = Stage.class.cast(minimizeButton.getScene().getWindow());
stage.setIconified(true);
}
}
Popup Controller:
package test;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class PopupController implements Initializable {
#FXML
private Pane rect;
private double xOffset;
private double yOffset;
#Override
public void initialize(URL url, ResourceBundle rb) {
Platform.runLater(new Runnable(){
private Parent root;
#Override
public void run(){
Stage stage = Stage.class.cast(rect.getScene().getWindow());
makeDraggable(stage, rect);
}});
}
#FXML
public void initialize(){
System.err.println("init popup called");
assert rect != null;
Stage stage = Stage.class.cast(rect.getScene().getWindow());
makeDraggable(stage, rect);
}
public void makeDraggable( final Stage stage, final Node byNode) {
byNode.setOnMousePressed(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
// record a delta distance for the drag and drop operation.
xOffset = stage.getX() - mouseEvent.getScreenX();
yOffset = stage.getY() - mouseEvent.getScreenY();
byNode.setCursor(Cursor.MOVE);
}
});
byNode.setOnMouseReleased(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
byNode.setCursor(Cursor.DEFAULT);
}
});
byNode.setOnMouseDragged(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
stage.setX(mouseEvent.getScreenX() + xOffset);
stage.setY(mouseEvent.getScreenY() + yOffset);
} });
byNode.setOnMouseEntered(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
if (!mouseEvent.isPrimaryButtonDown()) {
byNode.setCursor(Cursor.DEFAULT);
} } });
byNode.setOnMouseExited(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
if (!mouseEvent.isPrimaryButtonDown()) {
byNode.setCursor(Cursor.DEFAULT);
} } });
}
#FXML
private Button closeButton;
#FXML
public void changeButtonOnOverClose(){
closeButton.getStyleClass().add("btn_cerrar_over");
}
#FXML
public void changeButtonOnExitedClose(){
closeButton.getStyleClass().remove("btn_cerrar_over");
}
#FXML
public void exit(){
Stage stage = Stage.class.cast(closeButton.getScene().getWindow());
stage.close();
}
}
In Popup Controller initialize try:
rect.setStyle("-fx-background-color: transparent;");

GWT.setUncaughtExceptionHandler()

Has anyone successfully used the above statement to catch the exception before it goes to the browser as an alert?.
I registered a custom Exception Handler in the first line of my application entry point. But it does not catch the exception as expected.
public void onModuleLoad(){
GWT.setUncaughtExceptionHandler(new MyExceptionHandler());
...
....
}
EDIT
Here are my two classes:
I expect my system.out will print the details of the exception
and exception will be swallowed and should not be sent to browser.
Or Am I wrong?
package mypackage;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
public class MyEntryPoint implements EntryPoint {
public void onModuleLoad() {
GWT.setUncaughtExceptionHandler(new ClientExceptionHandler());
startApplication();
}
private void startApplication() {
Integer.parseInt("I_AM_NOT_NUMBER");
}
}
package mypackage;
import com.google.gwt.core.client.GWT;
public class ClientExceptionHandler implements GWT.UncaughtExceptionHandler {
#Override
public void onUncaughtException(Throwable cause) {
System.out.println(cause.getMessage());
}
}
I believe what's happening here is that the current JS event cycle is using the DefaultUncaughtExceptionHandler because that was the handler set at the start of the cycle. You'll need to defer further initialization to the next event cycle, like this:
public void onModuleLoad() {
GWT.setUncaughtExceptionHandler(new ClientExceptionHandler());
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
#Override
public void execute() {
startApplication();
Window.alert("You won't see this");
}
});
}
private void startApplication() {
Integer.parseInt("I_AM_NOT_A_NUMBER");
// or any exception that results from server call
}
Update: And here's the issue that describes why this works, and why it isn't planned to be fixed.
Setting up a default handler can be a tricky proposition some times. I can tell you exactly what is going on. If you get an exception in the onModuleLoad(), the handler will not be called. It is only after the load method is completed that it will ACTUALLY get put into place.
You should try the following:
public void onModuleLoad(){
GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
onUncaughtException(Throwable t) {
// Do stuff here
}
});
}
and see if that helps.
Silly solution, but it works fine!
before anything add your EntryPoint in your app.gwt.xml
<entry-point class='myPackage.client.MyEntryPoint' />
then;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
public class MyEntryPoint implements EntryPoint {
private EventBus eventBus;
#Inject
public MyEntryPoint(final EventBus eventBus){
this.eventBus = eventBus;
}
#Override
public void onModuleLoad() {
CustomUncaughtExceptionHandler customUncaughtExceptionHandler = new CustomUncaughtExceptionHandler();
GWT.setUncaughtExceptionHandler(customUncaughtExceptionHandler);
try {
onModuleLoad2();
} catch (RuntimeException ex) {
eventBus.fireEvent(new BusyEvent(false));
customUncaughtExceptionHandler.onUncaughtException(ex);
}
}
private void onModuleLoad2() {
throw new RuntimeException("test");
}
}
and your CustomUncaughtExceptionHandler would be something like:
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
import com.google.gwt.event.shared.UmbrellaException;
import com.google.gwt.user.client.Window;
public class CustomUncaughtExceptionHandler implements UncaughtExceptionHandler {
#Override
public void onUncaughtException(Throwable e) {
Throwable exceptionToDisplay = getExceptionToDisplay( e );
Window.alert( exceptionToDisplay.getCause() .getMessage()+" "+ exceptionToDisplay.getStackTrace());
}
private static Throwable getExceptionToDisplay( Throwable throwable ) {
Throwable result = throwable;
if (throwable instanceof UmbrellaException && ((UmbrellaException) throwable).getCauses().size() >= 1) {
result = ((UmbrellaException) throwable).getCauses().iterator().next();
}
return result;
}
}