在NetBeans 7.2中,我很难找到如何使用-Xlint进行编译:在Maven项目中未选中.在Ant项目下,您可以通过转到项目属性 - >编译来更改编译器标志,但Maven项目似乎没有任何此类选项.
有没有办法配置IDE使用Maven编译这些标志?
当我在Android Studio中构建我的Android项目时,我收到消息:
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Run Code Online (Sandbox Code Playgroud)
和
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Run Code Online (Sandbox Code Playgroud)
我想做消息建议的内容,但是如何做?-Xlint如上所述,如何配置我的Android工作室重新编译我的项目?(我使用的是Android Studio 3.0.1)
为什么每次编译时都会出现"使用未经检查或不安全的操作"错误?代码有什么问题?我复制了本教程中完全相同的代码http://www.mkyong.com/java/json-simple-example-read-and-write-json/
import java.io.FileWriter;
import java.io.IOException;
import org.json.JSONArray;
import org.json.JSONObject;
public class JsonSimpleExample {
public static void main(String[] args) {
JSONObject obj = new JSONObject();
obj.put("name", "mkyong.com");
obj.put("age", new Integer(100));
JSONArray list = new JSONArray();
list.add("msg 1");
list.add("msg 2");
list.add("msg 3");
obj.put("messages", list);
try {
FileWriter file = new FileWriter("c:\\test.json");
file.write(obj.toJSONString());
file.flush();
file.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.print(obj);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在完成学校的实验室作业,并在编译时收到此错误.程序运行正常,有点想修复导致错误的原因.程序代码和完整错误如下.一如既往地谢谢!
错误:注意:F:\ Java\Lab 8\Lab8.java使用未经检查或不安全的操作.注意:使用-Xlint重新编译:取消选中以获取详细信息.
码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
public class Lab8 extends JFrame {
public Lab8()
{
// Create an array of Strings for age ranges
String[] ageRanges = {"Under 20", "20-29", "30-39", "40-49", "50-59", "60 and Above"};
JComboBox jcbo = new JComboBox(ageRanges);
// Create an array of String destinations
String[] destination = {"Mercury", "Venus", "Moon", "Mars", "Jupiter / Europa", "Saturn / Triton", "Pluto + Sharon"};
JList jlst = new JList();
// Declare …Run Code Online (Sandbox Code Playgroud) 我想使用gson删除具有空集合或空值的属性.
Aiperiodo periodo = periodoService();
//periodo comes from a service method with a lot of values
Gson gson = new Gson();
String json = gson.toJson(periodo);
Run Code Online (Sandbox Code Playgroud)
我打印json,我有这个:
{"idPeriodo":121,"codigo":"2014II",
"activo":false,"tipoPeriodo":1,
"fechaInicioPreMatricula":"may 1, 2014",
"fechaFinPreMatricula":"jul 1, 2014",
"fechaInicioMatricula":"jul 15, 2014",
"fechaFinMatricula":"ago 3, 2014",
"fechaInicioClase":"ago 9, 2014",
"fechaFinClase":"dic 14, 2014",
"fechaActa":"ene 15, 2015",
"fechaUltModificacion":"May 28, 2014 12:28:26 PM",
"usuarioModificacion":1,"aiAvisos":[],
"aiAlumnoCarreraConvalidacionCursos":[],
"aiAlumnoMatriculas":[],"aiMallaCurriculars":[],
"aiAlumnoCarreraEstados":[],"aiAdmisionGrupos":[],
"aiMatriculaCronogramaCabeceras":[],
"aiAlumnoCarreraConvalidacions":[],
"aiHorarioHorases":[],"aiAsistencias":[],
"aiAlumnoPreMatriculas":[],
"aiAlumnoMatriculaCursoNotaDetalles":[],
"aiOfertaAcademicas":[],"aiTarifarios":[]}
Run Code Online (Sandbox Code Playgroud)
例如,对于那个json,我不想拥有集合aiAvisos,有一种方法可以从json中删除它.我正在使用很多集合,我在这里展示了一个,我真的需要从json中删除它们.
我需要这样的东西:
{"idPeriodo":121,"codigo":"2014II",
"activo":false,"tipoPeriodo":1,
"fechaInicioPreMatricula":"may 1, 2014",
"fechaFinPreMatricula":"jul 1, 2014",
"fechaInicioMatricula":"jul 15, 2014",
"fechaFinMatricula":"ago 3, 2014", …Run Code Online (Sandbox Code Playgroud) 我写了以下java代码:
public static void main(String[] args) {
Vector vector = new Vector();
for(int i=1; i<=10; i++)
vector.addElement(i);
Enumeration vEnum = vector.elements();
while(vEnum.hasMoreElements())
System.out.println(vEnum.nextElement());
}
Run Code Online (Sandbox Code Playgroud)
在编译它时会收到以下警告消息:
Note: TestJavaApplication.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Run Code Online (Sandbox Code Playgroud)
Netbeans抱怨"过时收藏"的消息.
在这种情况下,你推荐我什么?
注意,我需要在J2ME应用程序中使用Vector作为存储元素顺序的动态数组.我很乐意使用Hashtable但不幸的是它不存储其元素的顺序.
编辑1
审查后,这个答案我从改变报关Vector vector = new Vector();进入Vector<String> vector = new Vector<String>();.现在又收到另一条警告信息:
TestJavaApplication.java:2: warning: com.sun.org.apache.xerces.internal.parsers.IntegratedParserConfiguration is Sun proprietary API and may be removed in a future release
import com.sun.org.apache.xerces.internal.parsers.IntegratedParserConfiguration;
^
Run Code Online (Sandbox Code Playgroud)
谢谢.
我的老师给了我们一些示例代码,以帮助显示Java中的反射是如何工作的,但是我收到了一些错误:
Note: DynamicMethodInvocation.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Run Code Online (Sandbox Code Playgroud)
这是代码:
import java.lang.reflect.*;
import java.lang.Class;
import static java.lang.System.out;
import static java.lang.System.err;
public class DynamicMethodInvocation {
public void work(int i, String s) {
out.printf("Called: i=%d, s=%s%n\n", i, s);
}
public static void main(String[] args) {
DynamicMethodInvocation x = new DynamicMethodInvocation();
Class clX = x.getClass();
out.println("class of x: " + clX + '\n');
// To find a method, need array of matching Class types.
Class[] argTypes = { …Run Code Online (Sandbox Code Playgroud) 所以我想在这里运行这个简单的程序:
import java.util.*;
class StackDemo
{
public static void main(String[] args) {
Stack s = new Stack();
s.push(5);
s.push("dog");
System.out.print(s);
}
}
Run Code Online (Sandbox Code Playgroud)
StackDemo.java使用未经检查或不安全的操作.注意:重新编译以-Xlint:unchecked获取详细信息.流程已完成.
它显示了预期的结果,"[5, dog]"但我不明白Build Output窗口中的那条消息.这可能有什么问题?
我知道有很多类似的帖子.据我所知,错误意味着我应该对类型更具体.我的代码:
import java.util.*;
public class Storefront {
private LinkedList<Item> catalog = new LinkedList<Item>();
public void addItem(String id, String name, String price, String quant) {
Item it = new Item(id, name, price, quant);
catalog.add(it);
}
public Item getItem(int i) {
return (Item)catalog.get(i);
}
public int getSize() {
return catalog.size();
}
//@SuppressWarnings("unchecked")
public void sort() {
Collections.sort(catalog);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我确实指定LinkedList由类型的对象组成Item.当我用-xlint编译它时,我得到了
warning: unchecked method invocation: method sort in class
Collections is applied to given types
Collections.sort(catalog);
required: List'<'T'>'
found: …Run Code Online (Sandbox Code Playgroud) 在一个应用程序中,我正在使用SharedPrefernces保存/加载(序列化/反序列化)某些对象。
这是反序列化代码:
private void loadData() {
String str = sharedPreferences.getString(PREF_TAG, null);
byte[] bytes = Base64.decode(str, Base64.DEFAULT);
try {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream input = new ObjectInputStream(bais);
arrayOfObjects = (ArrayList<MyObject>) input.readObject();
} catch (Exception e) {
Log.i("BUG", "error decoding serialized objects: " + e.toString());
}
if (arrayOfObjects == null) {
Log.i("BUG", "serious problem!");
}
}
Run Code Online (Sandbox Code Playgroud)
但是每当我编译该项目时,该行:
arrayOfObjects = (ArrayList<MyObject>) input.readObject();
Run Code Online (Sandbox Code Playgroud)
引起警告,包含此方法的类“使用未经检查或不安全的操作”。
如何摆脱此警告或更改代码以更安全?
java ×9
android ×2
collections ×1
gson ×1
java-me ×1
javascript ×1
json ×1
maven ×1
netbeans ×1
reflection ×1
stack ×1
vector ×1