Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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程序在eclipse中编译,而不是在netbeans中编译?_Java_Eclipse_Netbeans - Fatal编程技术网

Java程序在eclipse中编译,而不是在netbeans中编译?

Java程序在eclipse中编译,而不是在netbeans中编译?,java,eclipse,netbeans,Java,Eclipse,Netbeans,在eclipse中,这行代码经过编译,程序运行良好 SimpleAdapter adapter = new SimpleAdapter(getApplicationContext(), (List<? extends Map<String, ?>>) data, R.layout.message_list_item, from, to); simpledapter adapter=newsimpledapter(getApplicationContext(),(List

在eclipse中,这行代码经过编译,程序运行良好

SimpleAdapter adapter = new SimpleAdapter(getApplicationContext(), (List<? extends Map<String, ?>>) data, R.layout.message_list_item, from, to);
simpledapter adapter=newsimpledapter(getApplicationContext(),(List>)数据,R.layout.message_List_项,from,to);
它发出警告:

unchecked cast from ArrayList<Map> to List<? extends Map<String, ?>>
未选中从ArrayList到List的强制转换>
但是,在netbeans中:

Incompatible types: ArrayList<Map> cannot be converted to List<? extends Map<String, ?>>
不兼容类型:无法将ArrayList转换为List>
然后是运行时错误:

error: inconvertible types
            SimpleAdapter adapter = new SimpleAdapter(getApplicationContext(), (List<? extends Map<String, ?>>) data, R.layout.message_list_item, from, to);
required: List<? extends Map<String,?>>
found:    ArrayList<Map>
错误:不可转换类型
SimpleAdapter=新的SimpleAdapter(getApplicationContext(),(List>)数据,R.layout.message\u List\u项,from,to);
必填项:列表>
发现:ArrayList

有人能给我解释一下这种行为上的差异吗?谢谢。

检查两个平台,确保两个IDE中运行的JDK版本相同,这很可能是问题所在。

Eclipse有自己的Java编译器,而Netbeans使用JDK中的编译器。它们是兼容的,并且都能生成有效的代码,但是对于一些模糊的特性(特别是在泛型领域),它们不是100%兼容的。大多数情况下,Eclipse编译器将能够处理更复杂的情况

尝试安装Java7并将其用于Netbeans。Oracle修复了编译器中的一些错误

编辑再次查看问题后,我发现一个问题:您混合了泛型和原始类型:您尝试将
Map
转换为
Map

在声明
数据
时,尝试使用泛型类型,而不是
数组列表
。如果这不起作用,那么您可以使用以下解决方法:

    @SuppressWarnings( { "unchecked", "rawtypes" } )
    java.util.List<? extends Map<String, ?>> tmp = (java.util.List<? extends Map<String, ?>>)((List) data);
@SuppressWarnings({“unchecked”,“rawtypes”})
java.util.List>tmp=(java.util.List>)((List)数据);

在编译器有机会对您使用泛型信息之前,这个小技巧会从右侧删除所有泛型信息。

您很可能在两个IDE上运行两个不同版本的Java。检查它。检查netbeans的编译器设置。默认情况下,在eclipse中,未经检查的泛型类型操作会发出警告,但可以设置为Error或Ignore(在Preferences->Java->Compiler->Errors/Warnings中),我设法运行了它,但它抛出了运行时错误。如果你有一个简单的测试用例,你可能想报告它。我在哪里报告它?OpenJDK将是一个好地方:如果你与Oracle有支持合同,请寻求支持。这将使bug得到更多的关注。您可能还想尝试使用Java8的预发行版。如果bug在那里被修复了,你很有可能会要求他们将修复向后移植。谢谢,但我在这里用我自己的问题找到了解决方案: