Intellij Idea not showing source code files - java

I have a problem with intellij idea. Previously I used Visual Studio and now I decided to try to write code with Intellij. But it seems to me incomprehensible. I created new project (Android gradle application) and I cannot find where the source code is:
There a a bit of some files and no source code files. And when i opened folder containing my project i found source code subdirectory.
All source code files are in "Third" folder. But this folder is not shown in "project" panel. How can I fix it?

Have you tried clicking on "drop arrow" next to the text "Project"? It is on the third row from the top.
It gives you the options of selecting between "project", "Android", and "Package".
Please select "Android" and see it you can find the files.
p.s. just noticed this even though it was posted a while back. Pls kindly tick correct answer if it works out for you. Thx.

Related

Unable to find or load Main Class in Intellij 2019.4

I have been at this problem for a few days now, don't know why it is still happening. I have tried other solutions that have been posted on stackoverflow but no luck.
Below the following code is from the book crafting interpreters in java.
In IntelliJ 2019.4 this error always pop up when I am trying to run the .jar file.
Error: Could not find or load main class com.jam.Jam
Caused by: java.lang.ClassNotFoundException: com.jam.Jam
I have built the .jar file and setting the main class as com.jam.Jam and the class path for the .jar file as /home/username/Jam-Programming_Language/src/com/jam/Scanner.Scanner.
This is the layout of my project directory.
The following solutions I have tried:
Solution 1
Open Project Structure
Select Modules, then click on the module for which you want the
dependency
Choose the Dependencies tab
Click the '+' at the bottom of the page and choose the appropriate
way to connect to the library file. If the jar file is already
listed in Libraries, then select 'Library'.
and
Solution 2
Go to the Project Structure, click on Modules, and click on your
Module
Choose the "Dependencies" tab
Click the "+" button on the right-hand side and select "Jars or
directories..."
Add the directory(ies) you want (note you can multi-select) and
click OK
In the dialog that comes up, select "classes" and NOT "jar directory"
Make sure you're using that Module in your run target
It had no effect apparently. Any clue on what I should do?
Edit: Uploaded wrong screenshot, replaced screenshot.
Thanks to CrazyCoder for pointing out the errors in my project (silly mistakes). It seems that after I have resolved those mistakes.
I had to follow the solutions I have posted then rebuild the .jar file.
Afterwards I need to mark the src folder as a source root folder (right click folder -> Mark Directory as -> sources root)
Edit Configurations if pointing to wrong main class.
Set Project compiler output (File -> Project Structure -> Project) to a folder designated to hold the output (any folder basically in or outside the project).
The error says, it is trying to run: com.jam.testfile. Your class is called: com.jam.Jam.
Click the dropdown where it shows "testfile" with a little red X on it. Select "Edit Configuration." For the "Main class", select "com.jam.Jam". That's it!
BTW, the little red X means there is some problem with your configuration.

Can't open file in java-eclipse neon

I am just starting off in Java and trying to follow buckythenewboston on you tube. I have java and eclipse neon both downloaded correctly. However, when I create a new project like he showed in the video, I click finish and nothing shows up, in the video it showed on the side there should be a like java symbol with the name of the project I created. Well nothing happens it is blank on my screen. I tried opening a file from the work space in my C drive and that doesn't work either as nothing shows up so I can create a class. I know there is a couple of forum questions with similar title but that is different I think as they can at least get code in where I can't. Any explanation as what is going on would be helpful. I also tried to go to file-import-existing project... but the existing project part isn't an option.
Thanks in advance.
go into your workspace directory and delete .metadata folder, then restart eclipse
Close all perspectives and open a new one, the one you like.

Using eclipse to create a new project

I tried to create a new project "hbv8" by going to file -->new java project, and I used the default settings.
Why is my hbv8 has an red x at the corner of its icon? It also automatically imported the source code from hbv7 with me importing it. Can someone please help? Many thanks in advance!
The problems window shown as below, but I didn't import those things from hbv 7 so I can't figure out what was the problem..
Your source files are in folder hbv8/src/src/hucklebuckle - note the two /src folders.
Eclipse expects the files to be in hbv8/src/hucklebuckle (just one /src)
So move the files or recreate the project.

Eclipse - Source not found

I know this question has been asked many times before, but none of the proposed solutions resolve my issue (or I'm not implementing them correctly).
I'm developing a plugin for OpenFire, and when I set a breakpoint in my plugin source Eclipse reports "Source not found". The JAR is built separate from the build of the OpenFire server. I've tried adding the JAR and specifying the source code directory, but no dice.
Here's the process I'm following: When I hit my breakpoint I'm clicking "Edit Source Lookup Path", clicking "Add", Java Library, User Library, click User Libraries, adding my library (tried both "Add JARs" and "Add External JARs"), and then specifying the folder that contains the source code. I've also tried:
Adding the source by selecting "File System Directory" instead of "Java Library"
Adding it by selecting "Workspace Folder"
In the Project Explorer, adding the source for my plugin to the Java Build Path
In the Project Explorer, adding my JAR as a Library and specifying the Source attachment
Thanks in advance for any suggestions.
Personally, I have no good experience in Eclipse JDT, when adding a source folder at the time it hits a break point. What I always prefer to do, is adding the source folder before debugging:
Select Project/Properties/Libraries
Select your library and "edit..." the source attachment
Select either the corresponding source folder or the zip/jar containing the package
After that, you should be able to open the source files in the virtual "Referenced Libraries" folder (directly below the "JRE System Library" folder inside the project), or when opening a reference to a linked class file from within the JDT editor. If you are able to access the source, then you should also be able to at least stop at the break point and see the corresponding source.
Else, you will have to check again, if the source folder is really valid: The source folder or source archive must contain the folder with the name of the root package of the library (e.g. the default Java "src.zip" inside the JDK folder also includes a corresponding "java" folder at its root). When in doubt, extract the archive and select the parent folder of the package you are interested in - sometimes source archives might be a mess or incompatible to JDT.
If this has been assured and it still doesn't work, chances are, that your linked source folder does not correspond to the compiled version of the library. Usually JDT will handle such inconsistencies fine, but if you try to open a source file, that is entirely different than the corresponding class file, you will encounter problems. In this case I would suggest either downloading the correct source version of the library, or recompiling the library from the source, if all else fails.
If opening a referenced source file from withing the JDT editor does work fine, and you are still unable to open the source files when a break point is entered during debugging, then most likely the class files are missing the line numbers of the corresponding source file. Again, you will have to recompile the library from the source in this case.
Finally, it is also possible to overwrite the default source lookup by specifying source folders or archives in the source tab of the launch configuration. But you should normally not need to do this, when your build path is configured correctly. From the Eclipse Help:
The Source tab defines the location of source files used to display source when debugging a Java application. By default, these settings are derived from the associated project's build path. You may override these settings here.
I had this very annoying problem for a long time but was finally able to solve it. In my case, a null pointer exception was being thrown somewhere in Java's Transformer.IsRuntimeCode(ProtectionDomain) function.
I didn't really need to know about this since the exception was being caught and handled, but eclipse would pause debugging every time this happened and tell me that the source wasn't available. As a result, I constantly had to keep pressing the button to continue code execution.
In order to prevent this from happening, I:
1. Clicked on the "Breakpoints" window at the bottom of the debugging
screen
2. Right clicked "NullPointerException"
3. Unchecked "Caught"
This prevented the debugger from pausing program flow during a caught NullPointerException.alt text
(source: SharpDetail.com)
And this another one as:
Eclipse doesn't crash. You're trying to step into a method, where eclipse doesn't know where to find the source (*.java) files and informs you about this. Here is how to tell eclipse where to look. Go to
Window->Preferences->Java->Installed JREs,select the JRE you are using and click Edit.
There, select all of the jar files in the list you see and and click Source Attachment....
In the window that shows up, select the fille src.zip, which is in your JDK folder (if you didn't uncheck it while installing the JDK). On the machine I'm on right now, that is
C:\Program Files\Java\jdk1.7.0_07\src.zip.
Save all your changes (possibly restart eclipse) and you won't see that error again.
Well it turns out the solution was anticlimactic. When Balder's recommendations did not work I tried debugging one of the stock OpenFire plugins and it worked just fine. I then created a new plugin from scratch, and by doing nothing other than adding the source to the project (Right-click on the project -> New -> Source Folder) it also worked just fine. I have no idea why Eclipse refuses to see the source for my original plugin, but I moved all my code and libraries over to the new plugin and debugging is working as expected.
Many times you put jar files in eclipse IDE as referenced libraries when binary version of application was downloaded. Usually done so by configuring the build path. But the binary does not have the source files. You have Binary version and source version of application.
One simple way is to download the source libraries that you also use maven to build the project.
Keep somehwere, may be inside your project workspace.
Now while seeing the class file (from eclipse, jar exploded) you may see the source not found, fine.... there is a button below and click on that, a new window opens and there select add external folder.
Reference it to the src folder of the source you downloaded(not the binary one) and kept somewhere as said above and it will show the class details from that.
I fixed this issue with doing the following:
Click at the menu Window - Preferences - Debug - Step Filtering And check all the packages like the following image.
(Step Filtering)
Then, debug again your project and thats it.
Best regards,
In my case, I had a breakpoint in the class declaration. I mean in the next line.
public class GenerateInterface implements JavaCall {
So, the debugger stopped in that line and showed the following message:
Source not found
I think unconsciously activate the breakpoint in that line.

No Package Hierarchy Importing Project in Eclipse

I've been trying to import a project that works on a friend's computer, however no matter what I try, the package hierarchy is completely lost and the result is this
Has anyone seen this issue before? I've been struggling with it for a while. Occasionally creating a new project and copying in the src folder works, but I've been unsuccesfful in my recent attempts.
The presentation of packages is a user option. Click the little down-arrow at the top of the package panel, then select "Package Presentation" from flat to hierarchical.
Turns out we weren't including the .classpath file in the source control. Facepalm. Good answers, though.
It could also be that the folders are not listed in the project as Source Folders. Go to the project properties and check that the root folders (looks like "data" and "src" here) are listed as source folders in the Build Path.

Categories