Compile error - unchecked
I created this class a couple months ago and it compiled fine, i made no changes, other that putting in a println to test the writeService method (just got to that part in my main app), now I am getting an unchecked error and I don't understand what it is complaining about.
Error message:
new-host-3:~/Desktop] mike% javac -Xlint:unchecked VIN.java
VIN.java:143: warning: [unchecked] unchecked conversion
found : java.util.ArrayList
required: java.util.ArrayList<VIN>
VINrecords = (ArrayList) oisVehicleFile.readObject();
^
1 warning
[new-host-3:~/Desktop] mike%
Code (stripped down to the essentials):
Code:
import java.io.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.Number.*;
import java.util.*;
import java.util.prefs.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import javax.swing.filechooser.FileFilter;
/**
* Maintain a vehicle history
* @author Mike Lipay
* @date 12/17/2009
* @version 1.0
*/
public class VIN implements Serializable
{
private static final long serialyearUID = 5231720162899345259L;
static ObjectOutput oosVehicleFile;
static FileInputStream fisVehicleFile;
static ObjectInputStream oisVehicleFile;
final String fileSep = System.getProperty("file.separator");
final String fieldSep = "\t";
static String vhDir = "vhDir";
static String vehicleFile;
ArrayList <VIN> VINrecords = new ArrayList <VIN> ();
String type;
String record;
/**
* Blank constructor
*/
public VIN ()
{
}
/**
* Main constructor
* @param aType Record type (Title, License, etc.)
* @param aRecord One entry from the ArrayList
*/
public VIN ( String aType, String aRecord )
{
type = aType;
record = aRecord;
}
public String getType() { return type; }
public String getRecord() { return record; }
/**
* Handle the Service Record
*/
// Read the Service record
public String readService (String aVIN)
{
if (VINrecords.size() == 0) loadVIN(aVIN);
for ( VIN VINentry : VINrecords )
if (VINentry.getType().equals("SVC"))
return (VINrecords.indexOf(VINentry) + fieldSep + VINentry.getRecord());
return (null);
}
// Read the Next Service record
public String readNextService (int aIdx, String aVIN)
{
int idx = 0;
if (VINrecords.size() == 0) loadVIN(aVIN);
for ( VIN VINentry : VINrecords )
{
if (aIdx < idx)
{
if (VINentry.getType().equals("SVC"))
return (VINrecords.indexOf(VINentry) + fieldSep + VINentry.getRecord());
}
else idx++;
}
return (null);
}
// Write the Service record
public int writeService (String aVIN, String aRecord)
{
String [] temp = aRecord.split(fieldSep, 2);
int idx = Integer.parseInt(temp[0]);
VIN tempVIN = new VIN("SVC",temp[1]);
System.out.println(temp[1]);
if (idx > -1)
VINrecords.set (idx, tempVIN);
else
{
VINrecords.add (tempVIN);
}
saveVIN(aVIN);
return (VINrecords.indexOf(tempVIN));
}
/**
* The section below handles the actual file I/O
*/
// Load the VIN file
public void loadVIN (String aVIN)
{
Preferences root = Preferences.userRoot();
Preferences node = root.node(fileSep + "com"
+ fileSep + "lipay"
+ fileSep + "vhReg");
vhDir = node.get("vhDir", "na");
if (vhDir.equals("na")) System.exit(1);
vehicleFile = vhDir + fileSep + aVIN + ".vin";
File testFile = new File (vehicleFile);
if (!testFile.exists()) return;
try
{
fisVehicleFile = new FileInputStream(vehicleFile);
oisVehicleFile = new ObjectInputStream(fisVehicleFile);
VINrecords = (ArrayList) oisVehicleFile.readObject();
oisVehicleFile.close();
fisVehicleFile.close();
}
catch (EOFException e1)
{
try
{
oosVehicleFile = new ObjectOutputStream(new FileOutputStream(vehicleFile));
oosVehicleFile.writeObject(VINrecords);
oosVehicleFile.close();
}
catch (Exception e2) { e2.printStackTrace(); }
}
catch (Exception e1) { e1.printStackTrace(); }
}
// Save the VIN file
public void saveVIN (String aVIN)
{
try {
oosVehicleFile = new ObjectOutputStream(new FileOutputStream(vehicleFile));
oosVehicleFile.writeObject(VINrecords);
oosVehicleFile.close();
}
catch (Exception e) { e.printStackTrace(); }
}
}