简体   繁体   English

在 java.util.Arrays 类中找不到静态方法 asList( java.lang.String )

[英]Static method asList( java.lang.String ) not found in the java.util.Arrays class

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Apache BSF: 2.4.0

I'm trying to use the following code inside a BeanShell:我正在尝试在 BeanShell 中使用以下代码:

import java.util.Arrays;
import java.util.List;

// Set the mongodb query (must be a pipeline)
List query = Arrays.asList("");

And I'm getting the following error:我收到以下错误:

15:01:46,351 ERROR [BSFManager] Exception: 
java.security.PrivilegedActionException: org.apache.bsf.BSFException: BeanShell script error: Sourced file: inline evaluation of: ``import org.pentaho.reporting.engine.classic.core.util.TypedTableModel;  import j . . . '' : Typed variable declaration : Error in method invocation: Static method asList( java.lang.String ) not found in class'java.util.Arrays' : at Line: 20 : in file: inline evaluation of: ``import org.pentaho.reporting.engine.classic.core.util.TypedTableModel;  import j . . . '' : Arrays .asList ( "" ) 
 BSF info: expression at line: 1 column: columnNo
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.bsf.BSFManager.eval(BSFManager.java:442)

Any idea?任何的想法?

You have to give it an array to convert to a List.你必须给它一个数组来转换成一个列表。 Here is an example of how to use the command from https://www.geeksforgeeks.org/arrays-aslist-method-in-java-with-examples/ :以下是如何使用来自https://www.geeksforgeeks.org/arrays-aslist-method-in-java-with-examples/的命令的示例:

    // Java program to demonstrate 
// asList() method for String value 

import java.util.*; 

public class GFG1 { 
    public static void main(String[] argv) 
        throws Exception 
    { 

        try { 

            // creating Arrays of String type 
            String a[] = new String[] { "A", "B", "C", "D" }; 

            // getting the list view of Array 
            List<String> list = Arrays.asList(a); 

            // printing the list 
            System.out.println("The list is: " + list); 
        } 

        catch (NullPointerException e) { 
            System.out.println("Exception thrown : " + e); 
        } 
    } 
}

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

相关问题 受休眠限制,无法将java.util.Arrays $ ArrayList强制转换为java.lang.String - java.util.Arrays$ArrayList cannot be cast to java.lang.String on hibernate restriction Model.addAttribute:无法将类型&#39;java.util.Arrays $ ArrayList&#39;的值转换为必需类型&#39;java.lang.String&#39; - Model.addAttribute : Failed to convert value of type 'java.util.Arrays$ArrayList' to required type 'java.lang.String' java.util.Arrays中的私有静态类ArrayList - 为什么? - private static class ArrayList in java.util.Arrays - Why? 获取 java.util.Arrays$ArrayList 的类 - Get the class of java.util.Arrays$ArrayList Android Java.util.Arrays类 - Android Java.util.Arrays class JMeter - 在类&#39;java.nio.file.Paths&#39;中找不到静态方法get(java.lang.String) - JMeter - Static method get( java.lang.String ) not found in class'java.nio.file.Paths' Java:找不到适合解析的方法(java.util.List <java.lang.String> ) - java: no suitable method found for parse(java.util.List<java.lang.String>) java: 没有找到适合 addAll(java.util.List 的方法<java.lang.String> ) - java: no suitable method found for addAll(java.util.List<java.lang.String>) 找不到JSP方法:类java.lang.String - JSP Method not found: class java.lang.String 预期的数组类型; 找到:'java.util.map<java.lang.string,java.lang.string> '</java.lang.string,java.lang.string> - Array type expected; found: 'java.util.map<java.lang.String,java.lang.String>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM