How to import stuff in java with Visual Studio Code - java

Im new with Java and i'm struggling with packages and classes when it comes to imports.
So i want to do something simple :
I want to include my class that takes inputs from the user, but somehow it keeps giving me all sorts of errors.

In Java, to be part of a package, you both need to be inside the correct folder, and start the file with package myclass;. You didn't show us the source code for Clavier.java but my educated guess is that you didn't start it with package myclass;.
As a side note, myclass is a really bad and confusing name for a package (which isn't a class).

Related

File not in same subdirectory or sourcepath?

I am new to Java and this is my essay to pass java. I found a template that I want to test, but the error is too strange for me to understand.
I must work in Netbeans ID 13 and the picture shows it all. But to me... I have the idea that I have everything on the same place. See here
I hope someone can help me to get on the right track.
Make sure the package and the directory names are both in lowercase. So 'com.mycompany.test1' not 'com.mycompany.Test1'. If the java source files are in the same package, then an import is not needed.
There might be something wrong within Options.java too. If so, please share the source code of it.

How to set up jaudiotagger on windows 10

I am rather new to programming and have never used a secondary source as I am using right now and need help. I am trying to use jaudiotagger (http://www.jthink.net/jaudiotagger/index.jsp) in a java program that I am writing but am not having any luck in accessing the classes that the service provides. I feel as though I am going about this entirely wrong; I've gone to https://bitbucket.org/ijabz/jaudiotagger/downloads/ and downloaded the "jaudiotagger-2.2.6-SNAPSHOT.jar" file, inserted this into the folder with my code and then tried importing as follows:
package jaudiotagger.src.org.jaudiotagger.audio;
import jaudiotagger.src.org.jaudiotagger.audio.AudioFile;
as an example for trying to import the AudioFile class, however that returns the error
audiotagger.java:7: error: cannot find symbol
import jaudihotagger.src.org.jaudiotagger.audio.AudioFile;
I have gone through the file directory on the link that I have provided and that is the location of the AudioFile script, however it still does not work.
I have never done anything like this before so I'm sorry if I'm missing some key conceptual stuff. I have also visited the previously asked question Add JAudiotagger Library to Java on Windows 7 however I don't know how to do the process that the user provided.

Java noob, wondering if I made a mistake regarding packages

So to give context, I am new to Java and have no other programming experience. The IDE I am using is NetBeans. I picked up a book called "Sams Teach Yourself Java" and the tutorials in this book are having me put all the different classes I write in the same package. The problem with this is that when I want to run a class with attached arguments I can't just run the file from the "Run" tab. The book tells me to run it as a main project. But if I select run as main, one of my other classes runs. I figured out a work-around buy setting a main class, but I haven't found anything online about this and want to make sure I am not doing something stupid. This is my first question and any tips on how to ask effective questions on this site are appreciated.
While learning, there is nothing wrong with putting many classes in the same package. The reasons for separating classes into different packages can wait until later lessons and learning.
You can run a particular class as a Java application in Netbeans, assuming it has the correct main() method, by pressing ctrl-shift-f5 while that class is the one currently selected (i.e., currently displayed in the editor pane). You can run the most recently run java application by pressing ctrl-f5, even if that class is not the one currently selected.
This question is clear enough. If you get to a programming problem, go far enough to have tried something that doesn't work as expected. To ask about it, try to show the smallest program that illustrates your problem; tell WHAT is happening that you do not expect (or not happening that you do). If there is an error message, include all of it, don't just describe it.
Is each class a new project/example from the book?
You could have multiple classes within the same package that each have a main method. Only the main method within the class that is selected to run/passed on will be called.
In NetBeans, there is a little drop down arrow that you can press and it should allow you to specify which one to call.
The application is running properly. That I can assure you. Since all the classes you created contains main method the compiler is confused because it does not know which class's main method should be executed successfully. Hence, it builds all the methods but does not execute them. If you observe the output tab, after clicking on the run button, it will always show build successful. This means it it building the classes but not executing them. To execute each class separately, either right-click on the class and then select the run option, or use the keyboard shortcut 'Shift+F6'. This shortcut executes the class you are currently working in.

How do you add external codebase to eclipse?

OK I give up. I've been trying to do this for the past two hours I googled how to add external source to eclipse, how to import, how to add to build path etc. and I must say there is absolutely nothing that clearly states how do you do this.
I want to add a directory with some Java classes. I downloaded it from github. It has a package some.package.name in its header.
I tried drag and dropping it to my project, adding it via build paths, using the import button. I tried changing the package names.
I always get this "RED X" icon next to the folder names ( these folder names are called like the package string in the headers ). This isn't even annotated so I do not know what am I even doing wrong. Why doesn't eclipse accept these sources? They are already in the project tree I do not understand this.
Can somebody actually tell me how you are supposed to do this? And why is this so complicated? Why would people create a IDE with I suppose a million lines of code and then make it be so hard to do the simplest thing?
Sorry for the rant but I am seriously starting to hate Java.

Run main method of a class in the test folder

Tried to google but got hundreds of unrelated issues regarding testing. I guess I'm missing a crucial keyword to reduce the number of hits to something that is relevant for me.
I have a class in src/test-integration/java which i need to run, since it is a tool for extracting test data from an database. It's basically just a little script in the main method.
However when I try to "run as java application" in Eclipse it says: Error: Could not find or load main class x.y.z.MyClass
I know it has worked before, but not sure how I got it to work.
Sorry for any missing information, please feel free to ask for more.
Any ideas of what I'm missing?
Added the whole full path to the java class in the Java Build Path properties in Eclipse and deselected "allow output for source folders" and selected it once again (don't know if that did something, but I include it anyway).

Categories