"找不到符号 - 方法remove(int)"对于数组列表

时间:2016-03-25 01:06:23

标签: java compilation

在一个类中,此方法是专门用于从数组列表中删除项目的。

import java.util.Scanner;
import java.util.ArrayList;
import static java.util.Arrays.*;
/************************
 * This part enables the user to add an item, remove an item, and view the list.
 * Created 17 FEB 2016
************************/
public class Menu
{

    public Scanner aryans = new Scanner(System.in);

    public String additem1 = "1";
    public String removeitem1 = "2";
    public String viewlist1 = "3";
    public String startISLA = "j";

    Item item; // From the Item class
    String itemName;
    double itemPrice;
    int quantity;

    UPC upc; // From the UPC class
    int universalproductcode;

    Location location; // From the Location class
    String locations;

    ItemList list1 = new ItemList();

    String keepShopping = "j";
    String continueISLA= "n";

    public Menu()
    {

        Drivingmethod();

    }

    public void Drivingmethod()
    {

        System.out.println("Start ISLA (j/n)? "); // input "admin" for full access to the program
        String userused = aryans.nextLine();


        if(userused.equals(startISLA))
        {

            System.out.println(" __________________________"); // Menu lines
            System.out.println("| 1: Add item              |");
            System.out.println("| 2: Remove item           |");
            System.out.println("| 3: View list             |");
            //System.out.println("| 4: Restart               |");
            System.out.println("|__________________________|");
            System.out.println("> Input selection: ");
            String ans1 = aryans.nextLine();

            if(ans1.equals(additem1))
            {

                addItem(); // add an item

            }
            else
            {

                if(ans1.equals(removeitem1))
                {

                    removeItem(); // remove an item

                }
                else
                {

                    if(ans1.equals(viewlist1))
                    {

                        viewList(); // view the list

                    }
                    else
                    {

                        if(ans1 == "4")
                        { 

                            Drivingmethod(); // returns you two the start.

                        }

                    }

                }

            }

        }

    }


    public void addItem()
    {

        do 
        {

            System.out.print("> Input item name: ");
            aryans.nextLine();
            itemName = aryans.nextLine();
            System.out.print("> Input item price: ");
            itemPrice = aryans.nextDouble();
            System.out.print("> Input item quantity: ");
            quantity = aryans.nextInt();
            System.out.print("> Input item UPC: ");
            universalproductcode = aryans.nextInt();
            System.out.print("> Input item location: ");
            aryans.nextLine();
            locations = aryans.nextLine(); // I was getting issues with this line, but this new way of setting the string fixed it. Applied this alternative to "itemName".
            list1.addToList(itemName, itemPrice, quantity, universalproductcode, locations);
            System.out.print("> Add another item (j/n)? ");
            keepShopping = aryans.nextLine();

        }

        while (keepShopping.equalsIgnoreCase("j"));

        if (keepShopping.equalsIgnoreCase("n"))
        {

            Drivingmethod();

        }

    }

    public void removeItem()
    {

        System.out.println(list1);
        System.out.println("Input the number of items you wish to remove: ");

        int Q = 1;
        int removenumberitems = aryans.nextInt();

        while(Q <= removenumberitems)
        {

            System.out.print("Input the numerical location of the item: ");
            int index1 = aryans.nextInt();
            list1.remove(index1);

            System.out.println(list1.get(index1) + " was successfully removed from the list.");

            Q++;

        }

    }

    public void viewList()
    {

        System.out.println(list1);
        System.out.println("Would you like to end ISLA (j/n)?");

        if (continueISLA.equalsIgnoreCase("n"))
        {

            Drivingmethod();

        }

    }

}

然而,在编译时,我BlueJ突出显示&#34;删除&#34;在行&#34; list1.remove(index1);&#34;作为一个错误,说明&#34;找不到符号 - 方法remove(int)&#34;。

导致此问题的原因是什么?我如何在我的代码中修复它?

0 个答案:

没有答案