這是主要的類:public class TestAbstractFactory{ public static void main(String []args){ String [] creatros = {"ConcreteCreatorA", "ConcreteCreatorB"}; try{ int choice = Integer.parseInt("0"); //---------- //Creator c = Creator)Class.forName(creatros[choice]).newInstance(); //Creator c = new ConcreteCreatorA(); //---------- c.anOperation(); } catch(Exception e){ System.out.println("Problem Encoutered"); System.out.println(e); } }}結(jié)果 1 (Creator c = (Creator)Class.forName(creators[choice]).newInstance();):遇到的問題java.lang.ClassNotFoundException:ConcreteCreatorA結(jié)果 2(Creator c = new ConcreteCreatorA();):創(chuàng)建的產(chǎn)品:ConcreteProductA*這個(gè)結(jié)果是預(yù)期的。所以問題是,為什么我在第一個(gè)程序中運(yùn)行失敗,但在第二個(gè)程序中運(yùn)行以獲得我的預(yù)期結(jié)果?
java:無(wú)法找出無(wú)法找到或加載主類的問題
慕標(biāo)5832272
2023-09-27 10:32:27