Error of java code when moving between Ubuntu and windows - java

Well, I am using IntelliJ to develop a project. I put some of my .java files in the folder src/model/. I have to begin with package src.model;, in Ubuntu , in order to avoid error. While in windows I have to begin with package model;.
Does anyone know why this happens and how can I avoid changing my code when I switch between the two platforms ?

Most probably your content root is set to [something]/src in Ubuntu, See here to fix it.

Related

Can't get Atom editor ide-java package to work on new Mac installation

I have recently been using the Atom editor with its ide-java package to do some Java development. It has worked well enough for me and I'd like to continue to use it.
I have just refreshed my Mac from scratch after having some repairs done on it that required erasing the disk. Since installing on this refreshed Mac, I am getting red error highlights on pretty much every line of code, including the first line of files which start with a comment. Most of the errors have a message something like this:
The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
A Google search shows this error and some fixes within Eclipse projects, but I am not (directly) using Eclipse and I've had a hard time figuring out how to fix the problem in ide-java.
I've tried deleting the .project file and the .settings folder and allowed them to be auto-regenerated. I've tried uninstalling and re-installing the ide-java package. I've tried setting the package's Java Home to both a Java 8 and a Java 10 home folder. None of these have made a difference.
Can anyone offer any advice on how to troubleshoot and make this work as it has for me in the past?
To fix this - you can try to reset atom settings.
For linux:
mv ~/.atom ~/.atom.bak
You will have to install packages again, but this helped me to fix the issue

Opening a .jar in Ubuntu

While making a game, i moved from programming in windows to ubuntu for better usability. that aside, when in windows, using Desktop d = Desktop.getDesktop(); and using d.open(new File("file dir.jar"); and it worked in windows. but, when using ubuntu, it opens the jar in an archive manager. so my question is, how would i open the .jar to be executed? Any help would be great! thanks in advance!
Edit: it may be possible i installed java wrong... but i did it the way i found on google. if that is the case, any correction would be great :D
I see two ways:
1) add the jar you want to run to the program classpath and run it's main method.
2) using Runtime.exec() you can run anything you want, but you may lose platform independence
The archive manager is set as the default program to open .jar files. You will have to change it in Ubuntu's settings for default programs. You can right-click on the file you want to open and select to open it with your installed Java runtime environment, in the meantime.

Can't read AppletViewer properties file - Applet

I created a Java applet program and compiled it. As a result of the compilation, it generated a class file. But, it showed the following warning message while running the applet with the command prompt using the appletviewer command.
D:\Applets\Applets>appletviewer FirstApplet.java
Warning: Can't read AppletViewer properties file: C:eswaran_s.VMSPL\.hotjava\properties Using defaults.
When I run this command once again, it does not show the warning message, but the applet is not running.
How can I solve this issue?
My solution to this problem was to simply (in Eclipse) go to Run-> Run configurations... and open the JRE card where I set Java SE to a newer installed version. (in my case from SE 6 to SE 7)
The file .appletviewer should be in your home folder. If it's not exist then default file is created. You can also place it in the %USERPROFILE%\.hotjava\properties.
If you run appletviewer it runs because you got any message from it. Suppose your instance is created on the %PATH%. But to run properly you should supply the argument text file that contains deprecated <APPLET> tag. It doesn't matter what extension it has.
Your extension is wrong. You should pass HTML file path like this:
D:\Applets\Applets>appletviewer htmlfile_name.html
Instead of this:
D:\Applets\Applets>appletviewer FirstApplet.java
It is often very difficult to write, compile and run applets in the applet viewer from the command prompt. A better way would be to download the program Eclipse from the Internet. I often got lots of errors when trying to run programs from the command prompt, and Eclipse automaticly compiles, emphasises special words (like new, break, byte, short etc.) and even error checks your code (it underlines errors with a squiggly red line like Microsoft word's spellcheck). All my problems have been solved! I seriously recommend downloading it.
i think your jdk miss some package or loss path so re-installed jdk latest version and run your program. and check your htm program is correct or not may be some time occurred due to wrong htm program.
I had the same problem following the instructions for a similar tutorial from Oracle's Java: A Beginner's Guide - Sixth Edition (pg 515). The directions tell you to immediately run the .java file with the applet viewer. However, you must first compile it. So, C:>javac FirstApplet.java. This will compile the program and create your FirstApplet class file, which is what is currently missing from your execution. Then, C:>appletviewer FirstApplet.java. Your applet should run fine. Seems odd that the tutorial would leave out this instruction.
Shoutout to RAB teaching broken code (Applets have been deprecated in most browsers)
First, make sure you have the javadoc folder (simply labelled "doc" once extracted) inside your jdk folder as advised here:
http://www.jcreator.com/installation.htm
You can download the doc file from here for Java SE 8:
http://www.oracle.com/technetwork/java/javase/documentation/jdk8-doc-downloads-2133158.html
Make sure you build the project first before running it (Menu/Build/Build Project).
Now run your project.
if you are using command line to run the file, use this particular line after importing packages.
/*<applet code = "Class_name.class" width=300 height=250></applet>*/
I have change this line in the prompt and ready:
D:\Applets\Applets>appletviewer FirstApplet.java

Eclipse Can't find default Java Classes on Mac OS X

I have done Android and C development in my copy of Eclipse, but have never actually done Java strictly. When I add code that compiles using "javac codename.java" to an eclipse project, eclipse gives me errors and can't recognize statements like import java.io.* . I believe this is due to a problem with my class path and I have tried adding some paths like library/system/java but have not had any success. Any ideas for a solution?
If Eclipse is having troubles with classes delivered by JDK, I would suggest checking out if it (thus - JDK) is properly installed. You may do that by going to menu Window > Preferences and started typing "jdk" in search input. It should point You to Java > Installed JREs. Check if there is proper JDK installed (if not - You may add it there).
After that try to clean Your project - menu Project > Clean....
Hope this helps, regards.
If you go into the preferences dialog and go to Java/Installed JREs, make sure those paths are correct.
In order for Eclipse to recognize source files as Java and compile them, your project has to be a Java project. Putting a .java file in a project that wasn't created via New / Java Project won't work.
Please try creating a Java project and put your .java file in it.
On os x the default location (right now anyway) is /System/Library/Java/JavaVirtualMachines/[VERSION].jdk/Contents/Home
The default location is available from /usr/libexec/java_home.
That said, I've never had any problems with eclipse not finding the jdk, usually it's all
automatic.

JVM: could not open

Error - JVM - BlackBerry 9800
Simulator
--------------------------------------- JVM: could not open
C:\Users\Bayron.Tellez\Downloads\eclipse-java-helios-win32\eclipse\plugins\net.rim.ejde.componentpack6.0.0_6.0.0.29\components\simulator\Java\net_rim_bis_lib.cod
My friend installed Eclipse with the Blackberry simulator. I'm assuming it was a portable installation because at no point we were prompted to install.
Now, he zipped it up and copied it to my machine when running I receive that error above. Obviously it's because it's trying to look for something on my friends directory. How can I change it to my path?
My path is:
C:\Eclipse\eclipse\plugins\net.rim.ejde.componentpack6.0.0_6.0.0.29\components\simulator\Java\net_rim_bis_lib.cod
Where do I change this?
I would suggest not running eclipse from a copy of someone else's installation. This will probably contain lots of installation-specific files which are unlikely to match your machine.
Why not install it yourself, then install the Blackberry Java Developer plugin? It's available at http://na.blackberry.com/eng/developers/javaappdev/devtools.jsp
You can change the early installed paths of all .cod files from xml.manifest
[Eclipse Installed Path]\plugins\net.rim.ejde.componentpack7.1.0\components\simulator\[BlackBerry simulator version].xml.manifest
Eg:
C:\Program Files\Eclipse\plugins\net.rim.ejde.componentpack6.0.0_6.0.0.30\components\simulator\9800.xml.manifest
Then remove the [BlackBerry simulator version].xml.manifest.bin file.
Now it should be work.
You may also want to check file Settings.rc,
found in the folder
PATH\plugins\net.rim.ejde.componentpack4.6.1_4.6.1.49\components\bin
first you have a path to your eclipse installation, and then corresponding Simulator you are trying to run.
hope this helps,
Use notepad++ to replace all occurrances of old directory into new directory in the eclipse directory.
Start the eclipse, and click clean simulator button.
That should be all.
Though it is not advisable to run a copy of eclipse, there is a very simple way for one to solve such a problem: it is by running the clean.bat file that is in the simulator folder of the specific component pack version folder. The path to that file would look like this: PATH\plugins\net.rim.ejde.componentpack[BlackBerry version]\components\simulator\clean.bat
I think that would do.
Still, installing a new version is the best option.
It will be better you install it yourself frsh rather than copying it from friends machine.
But you can give it a try.
Goto your eclipse\plugins\net.rim.ejde.componentpack6.0.0_6.0.0.29 directory and check do on of these files contain this path:
plugin.properties
plugin.xml
META-INF/eclipse.inf
.options
Or else you could grep for problem path in your plugin directory and replace same with updated path.
This error occurse cause your simulator have previously loadded application. Removing them solve your problem.
How to remove installed Java programs on the simulator?
Quote from Reset and clean the blackberry simulator:
Are you sick of having a million icons on your BlackBerry simulator for every HelloWorld and demo project you have every tested? Try this to remove old programs from the simulator and start with a clean ribbon. From the command line browser to your rim jde directory, switch to the simulator sub directory and run clean.bat. This program takes longer than you would expect (about 30 seconds or so on my 3 ghz machine).
UPDATE
Also delete all [app name].cod|cso|debug|jar files from simulator folder Also make sure projects you don't want on simulator are not active and are not in build configuration.

Categories

Resources