找不到符号Java错误? [英] Cannot find symbol Java error?

查看:346
本文介绍了找不到符号Java错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用code工作 java.util.Arrays.sort(数字);
难道我做错了什么?这似乎怪我。

 进口java.util.Arrays中的*。Test类{
   公共静态无效的主要(字串[] args){
    双[]号= {6.0,4.4,1.9,2.9,3.4,3.5};
    的char []字符= {'A​​','A','4','F','D','P'};    排序(数字);    的System.out.println(的binarySearch(数字,3));   }
}

(终端显示错误)

  Test.java:8:错误:无法找到符号
    排序(数字);
    ^
符号:方法排序(双[])
位置:类测试
 Test.java:10:错误:无法找到符号
    的System.out.println(的binarySearch(数字,3));
                       ^
 符号:方法的binarySearch(双[],INT)
 位置:类测试
  2个错误


解决方案

这是类的静态方法的阵列的。

您应该调用它是这样的:

  Arrays.sort(的someArray);

请注意你仍然要导入Arrays类是这样的:

 进口java.util.Arrays中;

或者像其他人所说的,如果你做一个静态导入可以省略类名。

我认为 Arrays.sort()是可读性更好。

The code works when I used java.util.Arrays.sort(numbers); Am I doing something wrong? This seems weird to me.

import java.util.Arrays.*;

class Test {
   public static void main(String[] args) {
    double[] numbers = {6.0, 4.4, 1.9, 2.9, 3.4, 3.5};
    char[] chars = {'a', 'A', '4', 'F', 'D', 'P'};

    sort(numbers);

    System.out.println(binarySearch(numbers, 3));

   }
}

(Error displayed in terminal)

Test.java:8: error: cannot find symbol
    sort(numbers);
    ^
symbol:   method sort(double[])
location: class Test
 Test.java:10: error: cannot find symbol
    System.out.println(binarySearch(numbers, 3));
                       ^
 symbol:   method binarySearch(double[],int)
 location: class Test
  2 errors

解决方案

It's a static method of the class Arrays.

You should invoke it like this:

Arrays.sort(someArray);

Note you still have to import the Arrays class like this:

import java.util.Arrays;

Or as others have mentioned, if you do a static import you can omit the class name.

I would argue that Arrays.sort() is better for readability.

这篇关于找不到符号Java错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆