Pessoa cannot be converted to String

The following error appears in my class Vetor: “Incompatible types: Pessoa cannot be converted to String”.

Class Vetor

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!");
    public void locPlace(Pessoa n) throws Exception {
        if (size==0)
            for (int i=0;i<size;i++)
    public void add(int i, String n) {
        if (size==A.length){
            for (int j=size=i;j>i;j--)

Class Pessoa

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;

Here’s a picture enter image description here

I trying some solutions, but didn’t worked. This error is showing on lines 34 and 38, as you can see in the image. How can I do fix this?


Look at the parameters of add. N is a String not a Pessoa.

Leave a Reply

Your email address will not be published. Required fields are marked *