我在启动ccObj线程时收到IllegalThreadStateException,因为此线程已启动两次。但是,只要我的输入与CC文本匹配,我就需要启动线程。我尝试在If循环内创建线程对象,但是需要在if条件之前使用此对象。如果每当付款类型为“ CC”时有任何方式启动此线程,请帮助我
CreditCardPayment ccObj = new CreditCardPayment();
System.out.println("Enter the number of payments:");
int numberOfPayments = Integer.parseInt(reader.readLine());
System.out.println("Enter the payment details (Invoice ID, ACC Number, Payment Amount, Payment Type)");
List<String> input = new ArrayList<String>();
for(int i=0;i<numberOfPayments;i++) {
input.add(reader.readLine());
}
for(String list : input)
{
String[] inputarr = list.split(",");
String paytype = inputarr[3];
ccObj.setCardNumber(inputarr[1]);
}
else if(paytype.equalsIgnoreCase("CC"))
{
ccObj.start();
ccObj.join();
}