I am new to coding and watching a tutorial. These lines work in the tutorial, but Eclipse keeps telling me there is an error [duplicate] - java

This question already has answers here:
InvalidModuleDescriptorException when running my first java app
(8 answers)
Closed 2 years ago.
public class LearnJava {
public static void main(String[] args) {
name = "Susan";
System.out.println(name.toUpperCase());
}
}
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: D:\java\JavaTutorial\bin
Caused by: java.lang.module.InvalidModuleDescriptorException: LearnJava.class found in top-level directory (unnamed package not allowed in module)

public class LearnJava {
public static void main(String[] args) {
String name = "Susan";
System.out.println(name.toUpperCase());
}
}

Related

The type java.io.FilterOutputStream cannot be resolved. It is indirectly referenced from required .class files [duplicate]

This question already has answers here:
the type java.io.FilterOutputstream cannot be resolved. error
(2 answers)
Closed 21 hours ago.
File Structure
MathNumber.java file
package com.code_for_numbers.number;
import java.util.ArrayList;
public class MathNumber {
public ArrayList<Integer> primeNums(){
ArrayList<Integer> arrList =new ArrayList<Integer>();
arrList.add(1);
arrList.add(2);
arrList.add(3);
arrList.add(5);
arrList.add(7);
arrList.add(11);
return arrList;
}
}
PerformTask.java file
package com.code_for_numbers.number;
public class PerformTask {
public static void main(String[] args) {
MathNumber n=new MathNumber();
System.out.println(n.primeNums());
}
}
While running my code I get error in PerformTask.java file The type java.io.FilterOutputStream cannot be resolved. It is indirectly referenced from required .class files
The outcome of result I am expecting [1,2,3,5,7,11]
I think this is the same: the type java.io.FilterOutputstream cannot be resolved. error
It looks like there is no JVM configured for your project in your IDE.

Eclipse is not find vlcj class [duplicate]

This question already has answers here:
Why am I getting a NoClassDefFoundError in Java?
(31 answers)
Closed last year.
My code run, compiler is printing this error
Exception in thread "main" java.lang.NoClassDefFoundError: uk/co/caprica/vlcj/player/component/EmbeddedMediaPlayerComponent
at main.test.main(test.java:10)
Caused by: java.lang.ClassNotFoundException: uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 1 more
My Code is very simple
package main;
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent;
public class test
{
public static void main(String[] args)
{
System.out.print("Test run\n");
EmbeddedMediaPlayerComponent player = new EmbeddedMediaPlayerComponent();
}
}
Project Lib is
JNA-5.2.0.jar
JNA-Platform-5.2.0.jar
vlcj-4.7.1.jar
vlcj-natives-4.1.0.jar
I don't know why occur this problem.
It's saying that the class EmbeddedMediaPlayerComponent is not found. Did you define the class?

I get bugs in whatever i write on my editor using inteliJ in Java.(maybe an IDE problem?) [duplicate]

This question already has answers here:
Does Java support inner / local / sub methods?
(5 answers)
Closed 3 years ago.
After some time I tested this simple code and still I had errors.
The errors that I got on this example was the following:
line 4 cannot resolve method a.
Line 6:first: ';' expected,second: Expression expected,third: Variable 'a' is never used.
So I don't get it. Whatever I try I get errors. I even downloaded some code in java from an IntelliJ developer and when I pasted on my editor I still got errors with methods and even the System.out.println. I tried to write in Eclipse but even there I got errors. Please help. I want so much to study but I am getting frustrated with these things.
public class asdf {
public static void main(String[] args) {
a();
static void a() {
System.out.println("asdfff");
}
}
}
Just get your a() method declaration out of the main :
public class asdf {
public static void main(String[] args) {
a();
}
static void a() {
System.out.println("asdfff");
}
}

Exception in thread "main" java.lang.NoClassDefFoundError: net/arnx/jsonic/JSONException [duplicate]

This question already has answers here:
Why am I getting a NoClassDefFoundError in Java?
(31 answers)
Closed 6 years ago.
I am trying to build a program that will take a sentence from user and return the language of the text to the user.
When I run my application, I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: net/arnx/jsonic/JSONException
Does this mean I have to download jsonic and add it as a jar file to my application?
import java.util.ArrayList;
import com.cybozu.labs.langdetect.Detector;
import com.cybozu.labs.langdetect.DetectorFactory;
import com.cybozu.labs.langdetect.Language;
import java.util.Scanner;
import com.cybozu.labs.langdetect.LangDetectException;
public class LangDetectSample {
public void init(String profileDirectory) throws LangDetectException {
DetectorFactory.loadProfile(profileDirectory);
}
public String detect(String text) throws LangDetectException {
Detector detector = DetectorFactory.create();
detector.append(text);
return detector.detect();
}
public ArrayList detectLangs(String text) throws LangDetectException {
Detector detector = DetectorFactory.create();
detector.append(text);
return detector.getProbabilities();
}
public static void main(String[] args) throws LangDetectException {
LangDetectSample detector = new LangDetectSample();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter text: ");
String input = scanner.nextLine();
String language = detector.detect(input);
System.out.print(language);
}
}
NoClassDefFoundError happens if your class definition is present at compile time but is missing at runtime. You need to provide your program with a library that contains the definition.
To do that you usually need to place your library right next to your program because that's where your program will search for it.

Why does the following code compile but not run? [duplicate]

This question already has answers here:
Case sensitivity of Java class names
(4 answers)
Closed 9 years ago.
class Demo
{
Demo()
{
System.out.println("Hello From Demo");
}
}
class demo
{
demo()
{
System.out.println("Hello From Small Demo");
}
}
class Test
{
public static void main(String arg[])
{
Demo d1=new Demo();
demo d2=new demo();
}
}
This code compiles but not doesn't run; When I try to run this program, it gives a classNotFoundException. What am I doing wrong?
Under Unix, and/or compiled into a .jar application, file names are case case-sensitive. And all would work: demo.class, Demo.class.
Under Windows the compilation of demo and Demo will overwrite one file.

Categories