java - 调用构造函数时收到错误

标签 java constructor

在扫描代码后到达此部分时,我收到此错误:

Project2_JoshuaLucas[,0,0,0x0,invalid,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=350,height=200]]

Project2_JoshuaLucas selection = new Project2_JoshuaLucas("", "", "", "", "", "", "", 0.00);

Object source = event.getSource();
if (source == cabin1)
{
  cabin1.setBackground(Color.darkGray);
  cabin2.setBackground(Color.gray);
  cabin3.setBackground(Color.gray);
  cabin4.setBackground(Color.gray);
  cabin5.setBackground(Color.gray);
  cabin6.setBackground(Color.gray);
  cabin7.setBackground(Color.gray);
  cabin8.setBackground(Color.gray);
  cabin9.setBackground(Color.gray);
  cabin10.setBackground(Color.gray);
  suite1.setBackground(Color.red);
  suite2.setBackground(Color.red);

  System.out.println("Your choice is Cabin 11-1, would you like to designate this as your room?");
  info1 = scan_in.nextLine();
  info1 = info1.toLowerCase();

 if ( info1.equals ("yes") || info1.equals ("y"))
{
   continues=true;   
   System.out.println("Please enter the number of people in your cabin (*Maximum number of people is 2*)");
   cabin_people = scan_in.nextInt();
   scan_in.nextLine();


   while(continues)
   {
     switch (cabin_people)
     {
     case 1:
       System.out.println("There is one passenger within the cabin. (You will pay an EXTRA 45% because of the empty passenger slot)");
       continues=false;
       onepassenger=true;
       break;
     case 2:
       System.out.println("There are two passenger within this cabin.");
       continues=false;
       twopassenger=true;
       break;
     default:
       System.out.println("Please try again. Remember, the maximum amount of passengers allowed is 2.");
       System.out.println("How many passengers are staying within this cabin?");
       cabin_people=scan_in.nextInt();
       scan_in.nextLine();
       continues=true;

 }//Closes the Switch
 }//Closes the while(continues) loop

 while(onepassenger)
 {
   System.out.println("Please state your FIRST name: ");
   fname1=scan_in.nextLine();
   System.out.println();
   System.out.println("Please state your LAST name: ");
   lname1=scan_in.nextLine();

   onepassenger=false;
   Project2_JoshuaLucas passenger1 = new Project2_JoshuaLucas (fname1, lname1, "", "", "", "", "", 0.00);
   System.out.println(passenger1);
 } //Closes while(1passenger)

我该如何解决这个问题?

最佳答案

您的 toString() 方法正在打印对象数据中的所有内容。

关于java - 调用构造函数时收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33357962/

相关文章:

java - 如何使用 JavaFX 图表 API 生成图表图像以进行导出而无需先显示

java - 具有继承问题的响应式(Reactive) WebTestClient json 反序列化

java - 在 JFrame 类中调用 File 方法是一个好习惯吗?

java - ArrayList 到不同的类

java - mongo java驱动程序中的getConnectionsPerHost()和getMaxSize()方法有什么区别

Javascript 对象编程和对象表示

java - 当没有构造函数的类的默认构造函数是 'automatically' 时,为什么编译器会提示父类(super class)没有构造函数?

c++ - 无法将变量 't' 声明为抽象类型 'AddSalariedEmployee'

java - 哪种编写代码的方式更好?特定构造函数或导入

C++ 链表 - 构造函数和运算符重载