java 包 com.google 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7002120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Package com.google does not exist
提问by SCO
I'm using Netbeans IDE 7.0.1. I base my question on the CalculatorApp sample application available with the IDE. The sample is running fine but I wish I could use some JSON, ad so I download google-gson-stream-1.7.1.jar library, and included it in my libraries : - right click on "Library", then "Properties" then "Add JAR/Folder" and selected my JAR (located somewhere in "My Documents/Download".
我使用的是 Netbeans IDE 7.0.1。我的问题基于 IDE 提供的 CalculatorApp 示例应用程序。该示例运行良好,但我希望我可以使用一些 JSON 广告,因此我下载了 google-gson-stream-1.7.1.jar 库,并将其包含在我的库中: - 右键单击“库”,然后单击“属性”然后“添加 JAR/文件夹”并选择我的 JAR(位于“我的文档/下载”中的某处。
The problem is that when i type the following :
问题是当我输入以下内容时:
import com.google.gson;
(or even com.google), the IDE fires a "Package com.google does not exist". The JAR and its hierarchy is correctly shown on the left side pane,in the "Libraries" section. Most surprising, the IDE can autocomplete the com.google.**stuff.
(甚至 com.google),IDE 会触发“Package com.google 不存在”。JAR 及其层次结构正确显示在左侧窗格的“库”部分。最令人惊讶的是,IDE 可以自动完成 com.google。**东西。
AFAIK, I need to further to get this work, don't I ? Any ideas ?
AFAIK,我需要进一步完成这项工作,不是吗?有任何想法吗 ?
Thank you !
谢谢 !
回答by adarshr
In Java, import statements are for classes and interfaces (types) not for packages themselves. Are you sure you tried to import a class under com.google.gson
package and not the package itself?
在 Java 中,import 语句用于类和接口(类型)而不是包本身。您确定您尝试导入com.google.gson
包下的类而不是包本身吗?
import com.google.gson.Foo;
should work.
import com.google.gson.Foo;
应该管用。
So should
所以应该
import com.google.gson.*;
or
import com.google.*;
import com.google.gson.*;
或者
import com.google.*;
Note however that wildcard imports aren't particularly recommended.
但是请注意,不特别推荐通配符导入。
回答by Artis
I am using:
我在用:
import com.google.gson.Gson;