Pessoa 无法转换为字符串
Pessoa cannot be converted to String
我的 class Vetor 中出现以下错误:“不兼容的类型:Pessoa 无法转换为字符串”。
Class维托[=25=]
package Pratique;
public class Vetor {
private Pessoa[ ] A;
private int capacity;
private int size;
public Vetor(int capacity) {
A = new Pessoa[capacity];
this.size = 0;
this.capacity = capacity;
}
public boolean isEmpty() {
if (size==0) {
return true;
} else {
return false;
}
}
public int size() {
return size;
}
public Pessoa get(int i) throws Exception {
if (isEmpty()) throw new Exception ("Lista vazia");
if (i>=size()) throw new Exception ("Posição não existe");
return A[i];
}
public void set(int i, Pessoa n) throws Exception {
if (isEmpty()) throw new Exception ("A lista está vazia!");
if (i>=size()) throw new Exception ("Esta posição não existe!");
A[i]=n;
}
public void locPlace(Pessoa n) throws Exception {
if (size==0)
add(0,n);
else
for (int i=0;i<size;i++)
if(n.getID()>=A[i].getID()){
add(i,n);
break;
}
}
public void add(int i, String n) {
if (size==A.length){
size--;
for (int j=size=i;j>i;j--)
A[j+1]=A[j];
A[i]=n;
size++;
}
}
}
Class佩索阿
package Pratique;
public class Pessoa {
protected String nome;
protected int ID;
public Pessoa (String nome, int ID) {
this.nome = nome;
this.ID = ID;
}
public String getNome() {
return nome;
}
public int getID() {
return ID;
}
}
这是一张照片
我尝试了一些解决方案,但没有奏效。此错误显示在第 34 和 38 行,
正如你在图片中看到的那样。我该如何解决这个问题?
查看add的参数。 N 是字符串而不是 Pessoa。
我的 class Vetor 中出现以下错误:“不兼容的类型:Pessoa 无法转换为字符串”。
Class维托[=25=]
package Pratique;
public class Vetor {
private Pessoa[ ] A;
private int capacity;
private int size;
public Vetor(int capacity) {
A = new Pessoa[capacity];
this.size = 0;
this.capacity = capacity;
}
public boolean isEmpty() {
if (size==0) {
return true;
} else {
return false;
}
}
public int size() {
return size;
}
public Pessoa get(int i) throws Exception {
if (isEmpty()) throw new Exception ("Lista vazia");
if (i>=size()) throw new Exception ("Posição não existe");
return A[i];
}
public void set(int i, Pessoa n) throws Exception {
if (isEmpty()) throw new Exception ("A lista está vazia!");
if (i>=size()) throw new Exception ("Esta posição não existe!");
A[i]=n;
}
public void locPlace(Pessoa n) throws Exception {
if (size==0)
add(0,n);
else
for (int i=0;i<size;i++)
if(n.getID()>=A[i].getID()){
add(i,n);
break;
}
}
public void add(int i, String n) {
if (size==A.length){
size--;
for (int j=size=i;j>i;j--)
A[j+1]=A[j];
A[i]=n;
size++;
}
}
}
Class佩索阿
package Pratique;
public class Pessoa {
protected String nome;
protected int ID;
public Pessoa (String nome, int ID) {
this.nome = nome;
this.ID = ID;
}
public String getNome() {
return nome;
}
public int getID() {
return ID;
}
}
这是一张照片
我尝试了一些解决方案,但没有奏效。此错误显示在第 34 和 38 行, 正如你在图片中看到的那样。我该如何解决这个问题?
查看add的参数。 N 是字符串而不是 Pessoa。