简体   繁体   English

arraylist给出“无法解析”和“无法解析为类型”错误(日食)

[英]arraylist giving “cannot be resolved” and “cannot be resolved to a type” errors (eclipse)

I'm writing a Selection Sort program, and it's still unfinished, so there are a lot of errors, but the one I'm looking to fix first is the error that eclipse keeps giving me: 我正在编写一个Selection Sort程序,但它仍未完成,所以有很多错误,但是我要首先解决的是eclipse不断给我的错误:

thelist cannot be resolved to a type

and again, in the rest of the program: 再次,在程序的其余部分中:

thelist cannot be resolved

my program looks like this: 我的程序如下所示:

import java.util.ArrayList;
public class SelectionSort {

public static void main(String[] args) {
    final int N = Integer.parseInt(args[0]);
    //populate list with number from 1 to N

    // Create an ArrayList containing Integer type elements
    ArrayList<Integer> thelist = new ArrayList();

    //while loop to accept a new value from random generator

    //call sort method
}

public static void sort(final thelist<Integer> list) {

    // declare an int variable to hold value of index at which the element
    // has the smallest value
        int smaller = 0;
        int b=0;

     // declare an int variable to hold the smallest value for each iteration
     // of the outer loop
        int smallerindex = 0;      

        for(int a=1;a<thelist.size();a++){
            /* find the index at which the element has smallest value */
            // initialize variables
            smaller = thelist.get(a-1);
            smallerindex = a-1;

            for(b=a;b<thelist.size();b++){
                if(thelist.get(b)<smaller){
                    // update smallest
                    smaller = thelist.get(b);
                    smallerindex = b;
                }
            }
         // do nothing if the curIndex has the smallest value
            //Swap the smallest element with the first element of unsorted subarray
            int temp = thelist.get(destIndex);
            thelist.set(destIndex, thelist.get(sourceIndex));
            thelist.set(sourceIndex, temp);

        }
    }

} }

In your sort method your are giving thelist as the type of the parameter list: 在您的排序方法中,您将列表作为参数列表的类型:

public static void sort(final thelist<Integer> list) {

change it for: 更改为:

public static void sort(final ArrayList<Integer> list) {

Then in the main method when you need to call the sort method, you call it like this: 然后在main方法中需要调用sort方法时,您可以这样调用它:

//call sort method
sort(thelist);

and that's the way you will have your list "thelist" and use it in your method. 这就是您拥有列表“ thelist”并在方法中使用它的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM