Compilando ObjectList.java [resolvido]

6 respostas
A

Pessoal estou com mais este problema.

C:\jdk1.5.0\mycart>javac ObjectList.java

ObjectList.java:7: reference to List is ambiguous, both class java.util.List in

java.util and class java.awt.List in java.awt match

public class ObjectList extends List

^

ObjectList.java:25: cannot find symbol

symbol  : variable super

location: class ObjectList

super.addItem(ob.toString());

^

ObjectList.java:34: cannot find symbol

symbol  : variable super

location: class ObjectList

super.addItem(ob.toString(), position);

^

ObjectList.java:48: cannot find symbol

symbol  : variable super

location: class ObjectList

super.addItem(label);

^

ObjectList.java:56: cannot find symbol

symbol  : variable super

location: class ObjectList

super.addItem(label, position);

^

ObjectList.java:77: cannot find symbol

symbol  : variable super

location: class ObjectList

super.delItem(index);

^

ObjectList.java:83: cannot find symbol

symbol  : method getSelectedIndex()

location: class ObjectList

int i = getSelectedIndex();

^

ObjectList.java:94: cannot find symbol

symbol  : method getSelectedIndexes()

location: class ObjectList

int[] selectedItems = getSelectedIndexes();

^

ObjectList.java:122: cannot find symbol

symbol  : method replaceItem(java.lang.String,int)

location: class ObjectList

replaceItem(ob.toString(), index);

^

ObjectList.java:131: cannot find symbol

symbol  : method replaceItem(java.lang.String,int)

location: class ObjectList

replaceItem(label, index);

^

Note: ObjectList.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

10 errors

C:\jdk1.5.0\mycart>

6 Respostas

T

Conserte o primeiro erro, e pode ser que os outros se resolvam.
(Isso é uma regra muito boa para linguagens compiladas: comece consertando o primeiro erro, porque os outros podem ser decorrências do primeiro. Alguns compiladores antigos (Turbo Pascal 3.0) levavam isso tão a sério que paravam no primeiro erro, e você tinha de corrigir para continuar.)

Dica: se você estiver usando algo como

import java.util.*;
import java.awt.*;

vai dar esse problema. Pelo que imagino, você está querendo usar java.awt.List. No seu caso seria interessante usar alguma IDE (Eclipse ou NetBeans) que transformasse esses “imports” com “*” em imports explícitos:

import java.awt.Graphics;
import java.awt.List;
// etc

No caso do Eclipse basta usar a combinação de teclas Ctrl+Shift+O (O = Organizar), que ele vai organizar tudo direitinho para você.

A

Thingol ainda ficaram estes erros…segue Codigo e erro logo abaixo…

import java.awt.Graphics;
import java.awt.List;

// This class is a special version of a scrollable list that
// associates an object with each element in the list.

public class ObjectList extends List
{
Vector objects; // the objects that correspond to list entries

public ObjectList()
{
	objects = new Vector();
}

public ObjectList(int items, boolean multiSelect)
{
	super(items, multiSelect);
	objects = new Vector();
}

public synchronized void addObject(Object ob)
{

// add a string version of the object to the list
super.addItem(ob.toString());

// add the object itself to the object vector

objects.addElement(ob);

}
public synchronized void addObject(Object ob, int position)
{

// add a string version of the object to the list
super.addItem(ob.toString(), position);

// add the object itself to the object vector

if (position >= objects.size()) {

objects.addElement(ob);

} else {

objects.insertElementAt(ob.toString(),

position);

}

}
public synchronized void addObject(String label, Object ob)
{
// Allow the object to be assigned a label independently of the object

super.addItem(label);

objects.addElement(ob);

}
public synchronized void addObject(String label, Object ob,
	int position)
{
// Allow the object to be assigned a label independently of the object

super.addItem(label, position);

if (position >= objects.size()) {

objects.addElement(ob);

} else {

objects.insertElementAt(ob.toString(),

position);

}

}
public synchronized void delObject(Object ob)
{

// See if the object is in the vector
int index = objects.indexOf(ob);

// If not, just return
if (index < 0) return;

// Remove the object from the vector
objects.removeElementAt(index);

// Remove the list entry

super.delItem(index);

}
public synchronized Object getSelectedObject()
{

// Get the index of the current selection
int i = getSelectedIndex();

if (i == -1) return null;
// Return the object currently selected

return objects.elementAt(i);

}
public synchronized Object[] getSelectedObjects()
{

// Get the indices of all the selected objects
int[] selectedItems = getSelectedIndexes();

// Create an array of all the selected objects
Object[] whichObjects = new Object[
selectedItems.length];

for (int i=0; i < selectedItems.length; i++) {
		whichObjects[i] = objects.elementAt(i);
	}

	return whichObjects;
}

public int indexOf(Object ob)
{
// Locate a particular object

return objects.indexOf(ob);

}
public Object objectAt(int index)
{
// Return the object at a particular index

return objects.elementAt(index);

}
public void replaceObject(Object ob, int index)
{

// Change a specific entry in the vector
replaceItem(ob.toString(), index);

// Change a specific entry in the list

objects.setElementAt(ob, index);

}
public void replaceObject(String label, Object ob, int index)
{

// Change a specific entry in the vector
replaceItem(label, index);

// Change a specific entry in the list

objects.setElementAt(ob, index);

}

}
C:\jdk1.5.0\mycart>javac ObjectList.java

ObjectList.java:9: cannot find symbol

symbol  : class Vector

location: class ObjectList

Vector objects; // the objects that correspond to list entries

^

ObjectList.java:13: cannot find symbol

symbol  : class Vector

location: class ObjectList

objects = new Vector();

^

ObjectList.java:19: cannot find symbol

symbol  : class Vector

location: class ObjectList

objects = new Vector();

^

Note: ObjectList.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 errors

C:\jdk1.5.0\mycart>

cv1

Andre, que parte de “cannot resolve symbol Vector” vc nao entendeu? :smiley:

A

Pessoal, foi erro meu já inclui a linha import java.util.*;
Agora ficou legar.

Brigadooooo…

T

Você copiou o código de algum lugar que ensinava Java 1.1, não é verdade? Nesse tempo não existia java.util.List, e não dava problemas com

import java.awt.;
import java.util.
;

No seu caso, para compilar com Java 5.0, basta pôr:

import java.awt.List;
import java.util.Vector;

A

Pô, o cara sabe tudo…copiei sim vou procurar um mais atualizado. Obrigado.

Criado 9 de junho de 2005
Ultima resposta 9 de jun. de 2005
Respostas 6
Participantes 3