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

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.

Related

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]

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());
}
}

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");
}
}

I seem to be getting the error Duplicate class in a java class [duplicate]

This question already has answers here:
java - duplicate class
(6 answers)
Closed 4 years ago.
I am getting an error that says "duplicate class: (package name).(class name)"
This is the code the line that says the error is "public class Enemy"
package rpgdemo;
public class Enemy {
String name;
int weaponId;
int baseAtk;
int baseDef;
int hitRate;
int hp;
public Enemy(String name,int weaponId, int baseAtk,int baseDef,int hitRate,int hp){
this.name = name;
this.weaponId = weaponId;
this.hp = hp;
this.baseAtk = baseAtk;
this.baseDef = baseDef;
this.hitRate = hitRate;
}
}
The problem is that you have another class containing tha same class name. Maybe you have deleted the java file before but the class file still remains. So I suggest you clean and build the project.
If you do not have same class in the package, try clearing the cache of the editor otherwise change class name. Check this java - duplicate class

Java can't find symbol from .class in the same directory

I have two files: MyStringLog.java (which extends ArrayStringLog) and TestDriver.java in the same directory. Why doesn't TestDriver.java recognize the MyStringLog constructor from the MyStringLog class? In TestDriver.java I declare:
MyStringLog animals = new MyStringLog("animals");
This is supposed to construct a new MyStringLog object named animals, but I get 2 errors when I compile, both, that MyStringLog symbol is not found.
ArrayStringLog.java: http://pastebin.com/Z624DRcm
MyStringLog.java:http://pastebin.com/zaH2S3yg
TestDriver.java:
public class TestDriver {
public static void main(String[] args) {
MyStringLog animals = new MyStringLog("animals");
animals.insert("dog");
}
}
I got this to roughly work. To do so...
for the file ArrayStringLog.java, I removed the implements StringLogInterface because I simply don't have access to that interface. After doing so, I removed the package ch02.stringLogs;. When I compiled this file with the package... still there, I recieved the error: Exception in thread "main" java.lang.NoClassDefFoundError: ArrayStringLog (wrong name: ch02/stringLogs/ArrayStringLog)
Then in MyStringLog.java, I removed the import ch02.stringLogs.*;. I then saved and compiled the code, and ran the TestDriver, to which I received no compilation errors.
This leads me to believe that your error stems from the package statement in ArrayStringLog.java.
To finally get a compilation, I put all four files (ArrayStringLog, MyStringLog, StringLogInterface, TestDriver) into the same directory, removed any package... statements, added back implements StringLogInterface to ArrayStringLog.java, compiled each one, and then ran TestDriver with an added toString method from which the output was:
Log: animals
1. dog
2. cat
Here was the test driver:
public class TestDriver {
public static void main(String[] args) {
MyStringLog animals = new MyStringLog("animals");
animals.insert("dog");
animals.insert("cat");
System.out.println(animals.toString());
}
}
To make clear, ArrayStringLog begins with:
public class ArrayStringLog implements StringLogInterface
try adding import MyStringLog; to your file.
Also are you using packages? In which case it should be import <package_name>.MyStringLog;

Find all classes in a given package [duplicate]

This question already has answers here:
Can you find all classes in a package using reflection?
(30 answers)
Closed 10 years ago.
Given a package, is it possible to find all the classes in it?
For instance, how do you find out what classes are contained within java.lang?
Thanks
This should get you started (look at the console output, it will make sense):
import com.google.common.collect.Multimap;
import org.reflections.Reflections;
import java.util.Map;
public class PackageWalker {
public PackageWalker() {}
public void walk() {
Reflections reflections = new Reflections("org.reflections");
for (String mmapName : reflections.getStore().getStoreMap().keySet()) {
System.out.println("KEY["+mmapName+"]");
Multimap<String,String> mmap = reflections.getStore().getStoreMap().get(mmapName);
for (Map.Entry<String,String> entry: mmap.entries()) {
System.out.println(" PAIR[ "+entry.getKey()+"="+entry.getValue()+" ]");
}
}
}
public static void main(String[] args) {
new PackageWalker().walk();
}
}
Following jars and their dependencies are required (using Ivy format):
<dependency org="org.reflections" name="reflections" rev="0.9.8"/>
Here is my project folder:
http://www.filedropper.com/laboratorytar
You just need to make sure Ivy is installed with ant (essentially put ivy.jar into your ANT_HOME/lib (or ~/.ant/lib/ on *nix) and it will just work).

Categories