Apache Pivot - "Main method not found in class" - java

I followed these instructions using the Eclipse IDE:
http://blogs.locusta.gr/argy/2011/09/setup-an-apache-pivot-project-in-eclipse/
So now I've imported and attached the respective Apache Pivot libraries. I tried to run this code they have on their website, but a proper main method is missing. Eclipse has underlined the first line of the code as an error.
This is the error I get:
Error: Main method not found in class HelloJava, please define the main method
as: public static void main(String[] args)
I understand the error, but what should the main method contain? https://www.mail-archive.com/user#pivot.apache.org/msg06027.html
This guy suggests the following
public static void main(String[] args) {
DesktopApplicationContext.main(HelloJava.class, args);
}
But this returns the error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
DesktopApplicationContext cannot be resolved
Anyone got any ideas? Here is the code, I'm pretty sure only the first bits are important:
package org.apache.pivot.tutorials;
import java.awt.Color;
import java.awt.Font;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.HorizontalAlignment;
import org.apache.pivot.wtk.Label;
import org.apache.pivot.wtk.VerticalAlignment;
import org.apache.pivot.wtk.Window;
public class HelloJava implements Application {
private Window window = null;
public static void main(String[] args) {
DesktopApplicationContext.main(HelloJava.class, args);
}
#Override
public void startup(Display display, Map<String, String> properties) {
window = new Window();
Label label = new Label();
label.setText("Hello World!");
label.getStyles().put("font", new Font("Arial", Font.BOLD, 24));
label.getStyles().put("color", Color.RED);
label.getStyles().put("horizontalAlignment",
HorizontalAlignment.CENTER);
label.getStyles().put("verticalAlignment",
VerticalAlignment.CENTER);
window.setContent(label);
window.setTitle("Hello World!");
window.setMaximized(true);
window.open(display);
}
#Override
public boolean shutdown(boolean optional) {
if (window != null) {
window.close();
}
return false;
}
#Override
public void suspend() {
}
#Override
public void resume() {
}
}

Never mind, I fixed it. I just had to erase the first line of the code, and add:
import org.apache.pivot.wtk.DesktopApplicationContext;

Related

Minecraft modding Java exception in mod item class

This is my code, I have errors on line 16 and 17, i don't know where im going wrong, this is in the main ModItems class and i have been using this video as a guide If you need the rest of my class files i have uploaded the current copy of my classes here
The error on both lines is The constructor Item(Item, Item) is undefined
package TheStraying11.QuarkyPower.init;
import TheStraying11.QuarkyPower.Reference;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSoup;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;
import TheStraying11.QuarkyPower.items.QuarkUp;
import TheStraying11.QuarkyPower.items.QuarkDown;
public class ModItems {
public static Item QuarkUp;
public static Item QuarkDown;
public static void init() {
QuarkUp = new Item(QuarkUp, QuarkUp);
QuarkDown = new Item(QuarkDown, QuarkDown);
}
public static void register() {
registerItem(QuarkUp);
registerItem(QuarkDown);
}
public static void registerRenders() {
}
public static void registerItem(Item item) {
GameRegistry.register(item);
}
public static void registerRender(Item item) {
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(Reference.MODID, item.getUnlocalizedName().substring(5)), "inventory"));
}
}
friend helped, changed
QuarkUp = new Item(QuarkUp, QuarkUp);
QuarkDown = new Item(QuarkDown, QuarkDown);
to
quark_Up = new itemQuarkUp();
quark_Down = new itemQuarkDown();
EDIT:
Completely started again as that video just made a mess imo, that i didn't understand, I guess ill get better soon haha, i just wish i could use Python instead

Eclipse is running my previous .java file not the current one I want to Run

I created this ArrayLocation.java yesterday
public class ArrayLocation {
private double coords[];
public ArrayLocation (double[] coords) {
this.coords = coords;
}
public static void main (String[] args) {
double[] coords = {5.0, 0.0};
ArrayLocation accra = new ArrayLocation (coords);
coords[0] = 32.9;
coords[1] = -117.2;
System.out.println(accra.coords[0]);
}
} ---This ran well and gave me an output 32.9
Today I created a new project and added this MyDisplay.java to it
package guimodule;
import processing.core.PApplet;
public class MyDisplay extends PApplet {
public void setup(){
size(400, 600);
}
public void draw(){
}
}
But when I run MyDisplay.java eclipse is still running the old ArrayLocation.java and returning 32.9. I expected it would open a blank applet.
Please help. I am pretty new to eclipse
How should I tell eclipse to run MyDisplay.java and not ArrayLocation.java ?
Goto Projects -> Clean
Open your java file in the editor, right click Run as -> Java Application
There is no main method in your MyDisplay.java.
Check your BuildAnt
it will surely help you.
Cheers.
You may add main method to MyDisplay.java class itself as follows:
package guimodule;
import processing.core.PApplet;
public class MyDisplay extends PApplet {
public void setup(){
size(400, 600);
}
public void draw(){
}
public static void main(String args[]){
PApplet.main(new String[] {"guimodule.MyDisplay"});
}
}
OR you can also initiate your MyDisplay.java from other class having main function:
InitClass.java
public class InitClass{
public static void main(String args[]){
final MyDisplay disp = new MyDisplay();
disp.init();
}

#Test Annotiation not working with TestFX

I'm trying to implement TextFX in my project to do some UI testing. However it seems I can't get it to work properly. I've downloaded the jars from http://search.maven.org/#search%7Cga%7C1%7Ctestfx to a folder named 'TestFX-3.1.2' on my system.
Afterwards I've created a new library in Netbeans8 pointing to those jar files (jar, source and javadoc). As a matter of test I've created a simple Java FXML project with the new library added.
public class Test2 extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Next to that I have a controller for my FXML file with the following generated code:
public class FXMLDocumentController implements Initializable {
#FXML
private Label label;
#FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
label.setText("Hello World!");
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
To implement the TestFX side, I've created a new class that extends GuiTest:
package test2;
import java.io.IOException;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import org.loadui.testfx.GuiTest;
public class TestTheThing extends GuiTest {
#Override
protected Parent getRootNode() {
FXMLLoader loader = new FXMLLoader();
Parent node = null;
try {
node = loader.load(this.getClass().getResource("FXMLDocument.fxml").openStream());
} catch (IOException e) {
System.out.println(e.toString());
}
return node;
}
#Test //<-- this Annotiation does not work
public void pressTheButton(){
//TODO
}
}
As said above in the code, the #Test simply does not work and is red underlined with the warning 'cannot find symbol'. Could anyone point me in the right direction about what I'm doing wrong?
According to https://repo1.maven.org/maven2/org/loadui/testFx/3.1.2/testFx-3.1.2.pom, testFx has several dependencies (guava, junit, hamcrest-all, hamcrest-core). To work correctly, you need to add the jars corresponding to these dependencies to your project. However, using maven is the recommended approach for that.
Don't load your fxml file directly in the test class as it may not work intentionally. Instead launch main class this way:
FXTestUtils.launchApp(Test2.class);
Thread.sleep(2000);
controller = new GuiTest()
{
#Override
protected Parent getRootNode()
{
return Test2.getStage().getScene().getRoot();
}
};
Create a static method getStage() in your Test2 class that returns the Stage. The above code should reside in a method annoted with #BeforeClass in your test class. The controller is a static reference to the GuiTest.
In the end your test class should look something like this:
import java.io.IOException;
import javafx.scene.Parent;
import org.loadui.testfx.GuiTest;
import org.loadui.testfx.utils.FXTestUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TestTheThing
{
public static GuiTest controller;
#BeforeClass
public static void setUpClass() throws InterruptedException, IOException
{
FXTestUtils.launchApp(Test2.class);
Thread.sleep(2000);
controller = new GuiTest()
{
#Override
protected Parent getRootNode()
{
return Test2.getStage().getScene().getRoot();
}
};
}
#Test
public void testCase()
{
System.out.println("in a test method");
}
}
In this case you will not need to extend from GuiTest. And, don't forget to create static getStage() in Test2 class. Hope this will help. This is working fine in my case.

Netbeans template AboutBox Java

I used this code previously in netbeans 6.9.1 but it does not seem to work in 7.1.1, it underlines .getApplication() with the hint "cannot find symbol".
How can I make this work again?
JFrame mainFrame = TestProject.getApplication().getMainFrame();
AboutBox newAboutBox = new AboutBox();
newAboutBox.setLocationRelativeTo(mainFrame);
TestProject.getApplication().show(newAboutBox);
Here is a similar question, but the solution does not work.
Have you checked the static method getApplication() in TestProject.java? What does it show?
I found the solution by re-installing netbeans 6.9.1. It appears that there is a built-in library that is not in 7.1.1. I also found that the template I used was the "Desktop Application" template.
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);
}
}

Simple App Won't Compile in Eclipse (with plugin)?

my code, being practically identical to the code given in BlackBerry's tutorial, has a syntax error in Eclipse. i'm sure there is some small but i'm just not seeing, but my coworker could not find it as well. any ideas would be greatly appreciated. thanks!
Code:
pushScreen(new ABCScreen());
Error:
Cannot make a static reference to the
non-static method pushScreen(Screen)
from the type UiApplication
here is the complete source:
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class AwesomeBBCalculator extends UiApplication {
public AwesomeBBCalculator() {
AwesomeBBCalculator app = new AwesomeBBCalculator();
app.enterEventDispatcher();
}
public static void main(String[] args) {
pushScreen(new ABCScreen()); // ERROR LINE
}
}
final class ABCScreen extends MainScreen {
public ABCScreen() {
super();
// add title
LabelField title = new LabelField("Awesome BlackBerry Calculator",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
}
public boolean onClose() {
Dialog.alert("Thanks for using the Awesome BlackBerry Calculator!\nGoodbye.");
System.exit(0);
return true;
}
}
The pushScreen method can only be called within an instance of UiApplication. You are trying to call it from a static main method. That does not work. Do this instead...
public void foo()
{
pushScreen(this);
}
public static void main(String[] args)
{
(new ABCScreen()).foo();
}
public void class1()
{
pushScreen(this);
}
public static void main(String[] args)
{
(new NewScreen()).class1();
}
try making an object for the ABCScreen class and then use it or u may try this also:
UiApplication.getUiApplication().pushScreen(new ABCScreen());

Categories