I have a project in intellij and when I created my packages I made a mistake because they all start in capital letter, for example my previous package name was "Main" then I changed it to "main" and I did it to all of my packages.
error: package com.myproject.thesis.main does not exist import
com.myproject.thesis.main.Main;
but the "main" package and "Main" class does exist and already imported on the class that needs it. Also what should I name the package where I put my main class?
While it may not help in this case, a general thing to try when "My code compiles and runs, but IDEA is really confused about the symbols in my project" is to go into the "File" menu and choose "Invalidate Caches / Restart". I've rarely used it, and it doesn't always help, but every once in a while it fixes IDEA's confusion.
See also the IntelliJ IDEA help on Cleaning System Cache.
You need to edit configuration. From IntelliJ Run menu choose Edit Configurations. On the configuration window change the package name of Main class.
I hope this helps.
Try changing the packages to something else first. e.g. coma.myprojecta.thesisa.maina and get that to work. Then change it back to com.myproject.thesis.main. I think IntelliJ might be having problems with the change in case. If you change it something totally different and then back it IntelliJ should realise that things have changed.
As for what to call the class with main method, it is up to you. There is some good advice here. https://softwareengineering.stackexchange.com/questions/208062/naming-conventions-for-java-classes-that-have-a-static-main-method
You could also try a complete reset of the project. Create a whole new project, with the packages named (and cased) the way you want. Then, move the code files from your old project into the folders for your new project. IDEA should be able to see the files you put in there and parse them correctly.
Just clean the contents in /target (or "mvn clean"), and Intellij can find your new package correctly.
Related
I have a big project and i decided to change some of the packages inside and also rename and delete some classes.
After I did it I am getting an error of:
java.lang.ClassNotFoundException: Main.Ser_Network.
That class does not exist anymore and i have replaced it with a different class and changed all the references to it inside the project.
I have also tried Project --> Clean.
Nothing works and i don't know what else i can do.
EDIT
I created a brand new project, created new packages and new class file (same names) and i am still getting this error.
How can i solve this issue? This is very important, any help would be appreciated.
Thank you.
Make sure that all references to the class are not in your code. You can do this by searching for it with a Ctrl+H.
Also try right-clicking your project folder and clicking "Close Project." Then try re-opening your project and rebuilding.
I am new to Java and I found something super weird. I imported a project into my eclipse and tried to made some changes to it.
However, no matter what I did the output of the project remained the same even after I commented out the entire Main class.
Anyone has a clue why this is happening ?
It's likely that your project cannot built due to some critical problem (missing required library, unable to write to the output directory, etc.). Please check "Errors/Warnings" view, there should be some hint.
Looks like you had compiled classes in the target directory. Do a Project > Clean before you run.
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!!
I am building an application and I added a new activity to generate a view. I compiled it. My application can not find anything that is on the format R.id.xxx or R.layout.xxx, I've tried also cleaning my project, closing Eclipse and opening Eclipse again, but nothing. The most strange thing is that before everything was working well. But now it can not recognize even the R.layout.main that is default of my principal activity. Anyone have an idea?
Also I have tried almost everything here: R cannot be resolved - Android error
but no result!
Solved
Thanks to woopsy, also I found the reference to this kind of problem
http://source.android.com/source/using-eclipse.html
it happens because Eclipse sometimes imports R when you press the combination ctrl+shift+O
Remove all your imports for the Activity and then have eclipse fix imports. I have had problems where eclipse wants to import a different R than the one I need.
First of All Check You have R.java File then check
import android.R;
Enter Yourpackages like import com.mypackages.prj;
If you are using eclipse, take a backup of your layout main.xml file and then from the eclipse new file interface create a new "Android XML File" and call it main.xml. copy back from the backup the contents into this new file.
try this.
check your xml files. there might be something wrong in it which is causing R not to build up automatically. To observe such errors, switch your view to Console tab
this is a common error. You need to just search your R.java file in generated section of your project directory in Eclipse. Need to import if the R.java file into the package then import . R;
I hope it will work for you. It was absolutely worked for me...enjoy programming
friends take care that u haven't imported R class, if you have delete "import android.R". The reason is there are two R things one R.java and R.class and we need the java, where we dont need to import rather than referring it. It worked for me and may be to you too.
I found the solution...For me works it
Poject->Properties->Android->Project Build Target (here choose android4.4 or 5.1.1 Android Open Source Project)->Ok
Project->Build All
This function ...
This problem can fix with this process: -
File---->Invalidate cache/restart.
it will restart your android studio and fix that problem
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.