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.
Related
I'm using Eclipse Eclipse IDE for Java Developers [Version: 2018-12 (4.10.0)
Build id: 20181214-0600] to develop a JavaFX project but I got some problems.
After a Java update, I've found several errors in my CSS files. Eclipse seems to think the CSS files are Java source code, as figured in the image below.
When I drag the mouse on a error, the description is "Syntax error on token 'Invalid character', interface expected" (because of # symbol)
I'm sure the code is correct because there are no errors before the latest java update to version 1.8.2.
Anyone can help me?
Most likely what happened here is what #Gianpio Benincasa said: You've created a new class, then in the file explorer you renamed it.
However, it's worth checking this one: Go to window/preferences, type 'associations' in the filter box to quickly nav to setting General>Editors>File Associations, and scroll through the file types list for *.css. Click on it, and check which editors are associated with it.
An eclipse with no particularly relevant plugins should only list 'Text Editor', and it should be marked as default. If you added plugins specifically for editing CSS, those will also be listed (and one of those is now probably default instead). Perhaps you or someone else went out of their way to add the java editor to this list somehow. If that is the case, simply make 'text editor' the default again (click it, click 'default'), then click on the java editor, and click 'remove'.
for eclipse that is a java class, in fact the icon has the "J". Probably when you created it you have created a new class and then have renamed it.
Create a new generic file instead a java class and copy the contents to the new file.
For create a generic file, rightclick and follow new-> other-> General-> files
Have a nice day
Having strange problem for couple of days.
I have written 2 main files, so to test based on need.
I have been facing following strange problems,
The main fail stops executing after some statement. doesnt hang! after cleaning the build, and compiling again it got executing!
I updated few System.out.println statements, but i am cant see new statements.
I excluded the unwanted main files and tried. even commented the whole unwanted main files and tried.
I even tried changing the main file name that i am using.
I observe the eclipse is not compiling the main file i wanted or it is taking old class file some where residing?
I cant see the unwanted class anywhere in the workspace!!
anyone experienced similar problem?
Please try right-mouse click on the class in "Package Explorer", then
form the menu choose "Run As" -> "Java Application".
This will run (and compile if needed) the selected source code.
I copied a main file from other project, and that package got retained in that file. when i modify the code in copied main file, forgot to modify a constructor name which was pointing to earlier package. I missed to trace import statements and it was not expanded. when i try to copy the file to post in stackflow, i found earlier package was included and found that was the culprit!!
In IntelliJ with the ASM Bytecode plugin installed you can select "Show Bytecode outline" in the popup menu when viewing a class file. Recently my IntelliJ (Community Version 12.1.6) started displaying:
// couldn't generate bytecode view, no .class file found
in the ASM window.
This occurs on various class files across different modules in my project. The strange thing is that I will get this message for one class; but another class in the same module and package works fine.
The entire project compiles fine and all my tests run. I cannot figure out why I get this message for one class and not another.
I have had the same problems after moving to IDEA 12 but my "positive hit rate" for being actually able to view the byte code outline became more stable again after upgrading to version 13. However, the result is still rather dissatisfying. From the logs, I learned that the plugin seems to not being able to find the referred class files even though they exist. It helps to make the project before trying to view the files, but this is not a perfect solution either. I guess, the problems will stay until someone sufficiently annoyed (maybe you?) upgrades the plugin.
What I use for now is simply javap from IntelliJ IDEA. You can add external tools by doing the following:
Settings > External Tools > Add...
Set the javap location for the called program: For example C:\Program Files\Java\jdk7\bin\javap.exe on Windows, depending of your installation path.
Add -v -c $FileClass$ as the parameters (here you can of course set the parameters you actually require).
Set $OutputPath$ as the working directory.
Now you can use javap from the right click menu on the source code view and you can also define a shortcut for the command.
Per Andrey Breslav's comment, the correct resolution to this issue is to use the "Show Bytecode" command in the "View" menu. You must have the source file open for this command to be displayed. You must have compiled the source since the last change for the command to complete successfully.
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!
I am trying to refactor my package using Eclipse
org.sheehan.activity
to
org.sheehan.stocks.activity
For some reason my project just blows up when I do this and R doesn't get regenerated. How can I refactor properly?
UPDATE:
I updated my Android Manifest to reflect the change. R still doesn't get regenerated. Even after a clean. The compiler is complaining about org.sheehan.activity.R
I resolved by:
Android Tools > Rename Package Application
If you renamed properly, all your references across your project should have gotten updated. After doing this, clean your project by going to Project > Clean. This should fix it.
Fixing missing reference to R in eclipse:
Refactor -> Rename`
Build -> Clean
Android Tools -> Fix Project Properties
select the base package of your project in the eclipse package explorer, press F2 (Rename), in the rename dialog: SELECT ALL the checkboxes.:
That should do it
The package name doesn't update in the XML files. Specifically your manifest which needs to know the base package.
For more advanced imports and refactors, literally closing the Eclipse IDE can refresh a cache that causes random errors like "End position lies outside document range" or the "what once worked now doesn't hair puller outter errors."
Signs you should close Eclipse when trying to rename things are:
When you import a project, do some refactoring (like trying to change the package name), then delete the project and try again, you will see immediate R.java errors when you didn't before
When you are importing projects that have manually generated R.java files that have custom imports like "com.ns.proj.R" and don't see the name update in Preview
The box that asks if you want to "Rename subpackages" is checked unexpectedly
the code in the "Preview>>" looks as if it's been complied before instead of black and white code with the proper names replaced
you get XML errors in the manifest activity name like this
android:name="com.ns.proj.CustomCocom.ns.proj.CustomControlse="#android:style/Theme.Light.NoTitleBar"
when it should be
android:name="com.ns.proj.CustomControls"
android:style="Theme.Light.NoTitleBar"
There are too many to name obviously, however this is as important as "keep your eye on the ball" in sports. Something that is so easy to forget, yet things like these apply to other software programs like Dreamweaver (e.g. when you use the Dreamweaver "Put" option instead of FTP dragging with FileZilla and you notice your domain isn't updating your changes online). I called Adobe when I first started as a developer 8 years ago because I knew I wasn't doing anything wrong. They said sometimes the generated files to perform the action get corrupted...in other words, IDE's have bugs too!
In general, close the IDE before you off yourself...it could save your life!
Right click in your Project, go to
Android Tools > Rename Package Application
Sometimes if Project > Clean doesn´t work, so Delete /gen and /bin folders of your project.