I compiled the Java files:
source code
folder1
a.java
b.java
folder2
c.java
d.java
Main.java
And I want to run them in this folder:
bin
folder1
a.class
b.class
folder2
c.class
d.class
Main.class
I tried java Main
and the program runs. But when I press a key, it says:
java.lang.ClassNotFoundException: CFactory
where CFactory is a Java file called by Main.java like this: (Class.forName("CFactory").newInstance())
How to fix the problem, and run it as normal?
run.bat
mkdir abstractfactorypattern\abstractcommandfactory
mkdir abstractfactorypattern\abstractfoodfactory
mkdir commandpattern
mkdir mementopattern
mkdir stock
cd ..\source code
javac abstractfactorypattern\abstractcommandfactory\*.java
javac abstractfactorypattern\abstractfoodfactory\*.java
javac commandpattern\*.java
javac mementopattern\*.java
javac stock\*.java
move abstractfactorypattern\abstractcommandfactory\*.class ..\bin\abstractfactorypattern\abstractcommandfactory
move abstractfactorypattern\abstractfoodfactory\*.class ..\bin\abstractfactorypattern\abstractfoodfactory
move commandpattern\*.class ..\bin\commandpattern
move mementopattern\*.class ..\bin\mementopattern
move stock\*.class ..\bin\stock`enter code here`
move *.class ..\bin
cd ..\bin
java AIMS
pause
That error means Java cannot find a file called CFactory.class
. Do you have it somewhere?
Once you find where it is, execute your Java program like this (assuming your file is at C:/path/CFactory.class
):
java -classpath .;C:/path/ Main
解决方案核心命令c = Class.forName(“ package1.package2。” + x).newInstance();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.