Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java InnerList类型中的不适用于参数(整数)_Java_Linked List - Fatal编程技术网

Java InnerList类型中的不适用于参数(整数)

Java InnerList类型中的不适用于参数(整数),java,linked-list,Java,Linked List,我的setInner方法一直遇到这个问题,如果我一直告诉我“类型InnerList中的setInner(GList)方法不适用于参数(Integer)”。这对我来说似乎很奇怪,因为一个整数似乎适用于一个GList。有人能帮我找出我做错了什么吗 我的内部类,其中将存储整数列表'Inner' public class InnerList { private String name; private GList<Integer> inner = new GList<Integer&g

我的setInner方法一直遇到这个问题,如果我一直告诉我“类型InnerList中的setInner(GList)方法不适用于参数(Integer)”。这对我来说似乎很奇怪,因为一个整数似乎适用于一个GList。有人能帮我找出我做错了什么吗

我的内部类,其中将存储整数列表'Inner'

public class InnerList {
private String name;
private GList<Integer> inner = new GList<Integer>();
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public GList<Integer> getInner() {
    return inner;
}
public void setInner(GList<Integer> inner) {
    this.inner = inner;
}
}
公共类内部列表{
私有字符串名称;
private GList inner=新GList();
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公共英语{
返回内部;
}
公共空间设置内部(GList内部){
this.inner=内部;
}
}
在我的主方法中,导致我出现问题的公共类部分:

GList<InnerList> list = new GList<InnerList>(); 
    InnerList iList = new InnerList ();
    Scanner sc = new Scanner(System.in);
    String answer;
while (true) {
            System.out.println("Do you want to enter a number (y/n)?");
            answer = sc.nextLine();
            if (answer.equals("y")) {
                System.out.println("Enter Number: ");
                answer = sc.nextLine();
                try {
                    Integer num1 = Integer.valueOf(answer);                            
                    if (list.isEmpty() == true) {                           
                        iList.setInner(num1);  //ERROR IS HERE
                        list.insertFirstItem(iList);
                    } else {
                        iList = new InnerList();
                        iList.setInner(num1); //AND HERE
                        list.insertNext(iList);
                    }
                } catch (NumberFormatException e) {
                    System.out.println("You must enter an number! " + e);
                }
                continue;
            } else {
                break first;
            }
        }
GList list=new GList();
InnerList iList=新的InnerList();
扫描仪sc=新的扫描仪(System.in);
字符串回答;
while(true){
System.out.println(“是否要输入数字(y/n)?”;
答案=sc.nextLine();
如果(答案等于(“y”)){
System.out.println(“输入编号:”);
答案=sc.nextLine();
试一试{
整数num1=整数.valueOf(答案);
如果(list.isEmpty()==true){
iList.setInner(num1);//此处有错误
列表.插入第一项(iList);
}否则{
iList=新的内部列表();
iList.setInner(num1);//这里
list.insertNext(iList);
}
}捕获(数字格式){
System.out.println(“您必须输入一个数字!”+e);
}
继续;
}否则{
先突破;
}
}

错误信息非常清楚。您正在使用

iList.setInner(num1);
你应该在什么时候做

iList.setInner(myIntegerGlist);

匹配方法的预期参数类型。

您还不了解类型。整数不是闪光。如果它扩展了课堂上的闪光,那将是一种闪光。但事实并非如此。即使在概念上,我也不明白任何人怎么能想象一个整数是一个列表。我不确定你想做什么,但你的
setInner
方法需要一个*整数对象列表,而你正在传递它一个整数。所以本质上我需要另一个列表GList nList=new GList()?列表是存储值的位置;但是我对SNG做了更改,错误是一样的。是的,您需要创建一个新的
GList
。在上面的代码中看不到一个。我断断续续地使用它;当我解决其他问题时。我不知道这是这次事故的原因。ThanksI将提取
GList()
一个单独的变量。我假设您希望用值填充它……不可能说它是否符合您的期望,因为您在问题中没有这样说,也没有为您的类和方法编写任何文档。