So I had an assignment to write a program for the game Othello/Reversi. I used NetBeans. Now the teacher sent us a "ReversiGUI.java" file that uses my own ReversiPlay.java and loads it onto a GUI so that I can test the game with my bots etc.
If I use the regular javac ReversiGUI.java and then run java ReversiGUI this works very well. However, it would be much easier for me to run the GUI from NetBeans, because I am getting some errors in the GUI, and I want to fix my code, but the info from the command line is very minimal (type of exception and line number). In NetBeans I will be able to debug and see which specific values are causing the problem.
I tried loading the GUI file into my ReversiPlay project, but every time the line ReversiPlay.someMethod is used, NetBeans says it does not recognize the symbol. So I'm guessing there's a specific way of loading the ReversiGUI.java file in NetBeans but I have no idea how to do it..
Any ideas?
Your problem is that NetBeans expects a package declaration, unlike command line. At the top of both your files put the following line:
package reversiplay;
That should fix your errors. Hope this helps!
Related
I have written a Java program that will execute an Alloy (.als) file. When I am using the commandline the program works perfectly but when I try to run it using NetBeans, this error is shown:
Exception in thread "main" Syntax error:
This module cannot be found.
It is not a built-in library module, and it cannot be found at "C:\Users\brinto dibyendu\Documents\NetBeansProjects\Alloy\util\integer.als".
What can I do?
Alloy is built & developed with Bndtools running in Eclipse. Trying to run it in Netbeans is just creating a huge amount of problems that you can avoid by taking the default route.
In Eclipse, all set up to immediately debug the main application is already done. It actually ensures resolves are handled inline instead of in another process so they are easier to debug. Then just debug it. Search for "built-in library module," and see what's happening there.
Even better, in Eclipse even the tiniest change you make to Java source code is immediately reflected in the runtime.
The quickest way I've found to fix this is to duplicate the .als files for the utilities in your file system.
Assuming your model (.als) file is in folder C:\Users\brinto dibyendu\Documents\NetBeansProjects\Alloy\, you'll need to create a util\ subdirectory in that folder and copy the source of the integer utility model (integer.als) into that subdirectory.
You can get the utility model files here.
I'm a beginner at Java and Eclipse and I will have an exam this Thursday.
I just imported those .java files on that package and project I created myself (I named the package java_10 just as it was needed, I'm mentioning this because I don't know if this is going to be useful information or not).
The problem I have is that when I click run in Eclipse, it doesn't run the current opened file but it runs another file, like in this case the KalkulimiB.java (as you can see, the result that is showing down on the console "z=15" is definitely not coming from Bank.java).
It didn't work at all in the beginning when I imported the files so I messed up a little with the run configurations so here's the picture how it looks like at the moment. Please zoom it up as it's needed, Please don't flag the question as a repost or something, I really searched for this problem but the solutions just didn't work or they just didn't really ask the same exact question as I am.
Launch configurations are a bit with a mind of their own until you know Eclipse better.
You can always explicitly run a specific class by right-clicking it in the Navigator and choose "Run" (or "Debug").
The files which can be run are those with
public static void main(Strings[] args){
//code to be run
}
other classes cannot be run but their methods can be run inside the main function of another file. Be careful though, if there are multiple main files open then the compiler will almost always run the main file that was run last.
[screen shot of project and error message in eclipse ide][1]
i have already made and tested a snake game in java.A siple GUI development using swing.It was running pretty fine
But when i went to create a runnable jar file i found that the classes were included in the java default package.So what i did was make a new project and copy the used resources and class.But this is the error message that shows up.
As you'll can see main is already defined in the Game play class(reffer to the image) ,hence i coudlnt think of a reason why this error message would show.
I tried changing the workspace as well but in vain,and furthermore now on running the application(with warnings ofcourse) the used resourses woulnot load!
Totally in a mess!!
could the community kindly help me fix it?
if the image is not visible try this link
https://i.stack.imgur.com/NF34x.jpg
Did you remember to include a package declaration? Remember, in order to run a java program that is inside of a package, you must include a package declaration.
I am hardcore Noobie in Java (and Eclipse) and this is my 1st Java code.
I am using VMware Java SDK and I am able to run the Java samples that come with the SDK. In one of the sample codes, I find this line:
import com.vmware.vcloud.sdk.Organization;
And the line in which this class is used is:
for (ReferenceType vdcLink : Organization
.getOrganizationByReference(vcloudClient, orgRef)
.getVdcRefs())
Here I understand how Organization is imported and being used.
Now, I am writing my own code in Eclipse and not able to make "Organization" work. Eclipse is not writing the import (however, Eclipse is auto-writing the import statements for few other methods that I used from the same SDK)
Here is what I did:
I did make sure that I import all the .jar files (that come from the VMware SDK) into Eclipse at Project Properties -> Java Build Path -> Libraries.
I am also running CTRL+Shift+O to arrange the imports.
I have also set Windows > Preferences > "Save Actions" and checked "Organize Imports" so that it will arrange the imports every time I save the program.
However, I am just not able to get Organization work.
So from the sample code (which is working), I copied the below line to my code:
import com.vmware.vcloud.sdk.Organization;
But still it is not working. Needless to say, If I type Organization. and then do a CTRL + Space (to show autocomplete suggestions), it does not show any methods in the pop up.
I am thinking this is somehow related to the setting of the .jar file paths but I'm not sure.
Thanks.
UPDATE:
This is the error I get when I use "Organization": This error pops up in a box when I move my mouse cursor to the Red dot on the far left of the line where I wrote Organization:
Multiple Markers At this line
-Orgnization cannot be resolved to a variable
So,
I got it working as below. Not sure whether it makes any sense to you guys. But an explanation would be really helpful:
My sample code has below things:
In Eclipse, it is located in project->src->com->vmware->vcloud->sdk->samples folder
And it has this line at the top: package com.vmware.vcloud.sdk.samples;
So I move my code from project->src to project->src->com->vmware->vcloud->sdk->samples and added that package line to my code.
Now eclipse is writing the import statement for Organization as well as eclipse shows me available methods for Organization.
Now,
I don’t want to write my code inside the samples folder.
Is this even making any sense??
Thanks for the comments. I got this idea after reading your comments.
I have developed a big program in Java and Csound that has worked smoothly until now.
In the last days I decided to add a "info" menu to display infos about the developer.
This infos were showed in another frame that i have created in Netbeans; I open it using setVisible(true).
The strange behavior is that in Netbeans everything work without problems, in command line everything works except the info Frame.
Obviusly, the class exists and works.
Any ideas?
So here is the exception:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError:
userInterface/info/InfoFrame
at userinterface.MainFrame.jMenuItem1ActionPerformed(MainFrame.java:380)
[snip]
The class exists sure, but not in the classpath when you run from the command line. Ensure that the jar exists in the classpath on the command line. Netbeans does this magic behind the scenes for you.