Problem in OnClick, I can not pass the Array information to a text view

0

I'm having problems to inflate a list with information from the bank, I want to get the information from the user and be in a list, but only with a data type as a name, but it presents the following error:

Error message:

FATAL EXCEPTION: main
Process: com.example.matheus.privatewalletm, PID: 4149
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4780) 
at android.view.View$PerformClick.run(View.java:19866) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.matheus.privatewalletm/com.example.matheus.privatewalletm.lista2}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
at android.app.Activity.startActivityForResult(Activity.java:3745)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.app.Activity.startActivityForResult(Activity.java:3706)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:871)
at android.app.Activity.startActivity(Activity.java:4016)
at android.app.Activity.startActivity(Activity.java:3984)
at com.example.matheus.privatewalletm.Menu.abreBuscaNome(Menu.java:22)
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
at android.view.View.performClick(View.java:4780) 
at android.view.View$PerformClick.run(View.java:19866) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
  

User Class

package com.example.matheus.privatewalletm;

import android.util.Log;
import android.widget.ArrayAdapter;

import java.sql.ResultSet;
import java.util.ArrayList;

/**
 * Created by Matheus on 30/08/2016.
 */
public class Usuario extends _default {
    private int id;
    private String nome;
    private String data;
    private String rg;
    private String cpf;
    private String doenca;
    private String alergia;
    private String profissao;


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getRg() {
        return rg;
    }

    public void setRg(String rg) {
        this.rg = rg;
    }

    public String getCpf() {
        return cpf;
    }

    public void setCpf(String cpf) {
        this.cpf = cpf;
    }

    public String getDoenca() {
        return doenca;
    }

    public void setDoenca(String doenca) {
        this.doenca = doenca;
    }

    public String getAlergia() {
        return alergia;
    }

    public void setAlergia(String alergia) {
        this.alergia = alergia;
    }

    public String getProfissao() {
        return profissao;
    }

    public void setProfissao(String profissao) {
        this.profissao = profissao;
    }

    public Usuario(){
        super();
        this.id = -1;
        this.nome = "";
        this.data = "";
        this.rg = "";
        this.cpf = "";
        this.doenca = "";
        this.alergia = "";
        this.profissao = "";
    }

    public ArrayList<Usuario> getLista(){
        BD bd = new BD();
        ArrayList<Usuario> lista = new ArrayList<>();
        try {
            ResultSet resultSet = bd.select("SELECT * FROM usuario");
            if(resultSet != null ){
                while (resultSet.next()){
                    Usuario obj = new Usuario();
                    obj.setId(resultSet.getInt("id"));
                    obj.setNome(resultSet.getString("nome"));
                    obj.setData(resultSet.getString("data"));
                    obj.setRg(resultSet.getString("rg"));
                    obj.setCpf(resultSet.getString("cpf"));
                    obj.setDoenca(resultSet.getString("doenca"));
                    obj.setAlergia(resultSet.getString("alergia"));
                    obj.setProfissao(resultSet.getString("profissao"));
                    lista.add(obj);
                    obj = null;
                }
            }
        }
        catch (Exception e)
        {
            Log.d("PrivateWalletM", e.getMessage());
            this._messagem = e.getMessage();
            this._status = false;

        }
        return lista;
    }

    public void confirmar(){
        String comando = "";
        if(this.getId() == -1){
           comando = String.format("INSERT INTO usuario (nome, data, rg, cpf, doenca, alergia, profissao) values ('%s', '%s', '%s', '%s', '%s', '%s','%s' );",
                    this.getNome(), this.getData(), this.getRg(), this.getCpf(), this.getDoenca(), this.getAlergia(), this.getProfissao());
          /* try {
               comando = String.format("SELECT * FROM usuario");
           }catch(Exception e)
            {
              _messagem = "Não entrou no BD";
            }*/

        }
        else
        {
            comando = String.format("UPDATE usuario SET nome ='%s', date = '%s', rg = '%s', cpf = '%s', doenca = '%s', alergia = '%s', profissao = '%s' WHERE id = %d;",
                    this.getNome(), this.getData(), this.getRg(), this.getCpf(), this.getDoenca(), this.getAlergia(), this.getProfissao(), this.getId());
        }
        BD bd = new BD();
       bd.execute(comando);
       this._messagem = bd._messagem;
        this._status = bd._status ;
    }

    public void apagar(){
        String  comando =  String.format("DELETE FROM usuario WHERE id = %d ", this.getId());

        BD bd = new BD();
        bd.execute(comando);
        this._messagem = bd._messagem;
        this._status = bd._status ;


    }

}
  

Class NEW

package com.example.matheus.privatewalletm;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class Novo extends AppCompatActivity {

    private Usuario usuario;
    private EditText editTextNome;
    private EditText editTextData;
    private EditText editTextRg;
    private EditText editTextCpf;
    private EditText editTextDoenca;
    private EditText editTextAlergia;
    private EditText editTextProfissao;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_novo);

        this.usuario = new Usuario();
        this.editTextNome = (EditText) findViewById(R.id.editTextNome);
        this.editTextData = (EditText) findViewById(R.id.editTextData);
        this.editTextRg = (EditText) findViewById(R.id.editTextRg);
        this.editTextCpf = (EditText) findViewById(R.id.editTextCpf);
        this.editTextDoenca = (EditText) findViewById(R.id.editTextDoenca);
        this.editTextAlergia = (EditText) findViewById(R.id.editTextAlergia);
        this.editTextProfissao = (EditText) findViewById(R.id.editTextProfissao);

        Intent intent = getIntent();
            if(intent != null){
                Bundle bundle = intent.getExtras();
                if(bundle != null){
                    this.usuario.setId(bundle.getInt("id"));
                    this.editTextNome.setText(bundle.getString("nome"));
                    this.editTextData.setText(bundle.getInt("data"));
                    this.editTextRg.setText(bundle.getString("rg"));
                    this.editTextCpf.setText(bundle.getString("cpf"));
                    this.editTextDoenca.setText(bundle.getString("doenca"));
                    this.editTextAlergia.setText(bundle.getString("alergia"));
                    this.editTextProfissao.setText(bundle.getString("profissao"));

                }
            }
    }

    public void confirmar (View view){
        this.usuario.setNome(this.editTextNome.getText().toString());
        this.usuario.setData(this.editTextData.getText().toString());
        this.usuario.setRg(this.editTextRg.getText().toString());
        this.usuario.setCpf(this.editTextCpf.getText().toString());
        this.usuario.setDoenca(this.editTextDoenca.getText().toString());
        this.usuario.setAlergia(this.editTextAlergia.getText().toString());
        this.usuario.setProfissao(this.editTextProfissao.getText().toString());
        this.usuario.confirmar();

        Toast.makeText(this,this.usuario.get_messagem(),Toast.LENGTH_LONG).show();
        if(usuario._status)
            finish();
    }

    public void cancelar (View view)
    {

        finish();
    }
}
  

User Class Adapter

package com.example.matheus.privatewalletm;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by Matheus on 30/08/2016.
 */
public class UsuarioAdapter extends ArrayAdapter<Usuario> {
    private Context context;
    private ArrayList<Usuario> lista;

public UsuarioAdapter(Context context, ArrayList<Usuario> lista)
    {
        super(context,0,lista);
        this.context = context;
        this.lista = lista;
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        final Usuario itemPosicao = this.lista.get(position);
        convertView = LayoutInflater.from(this.context).inflate(R.layout.item_lista,null);
        final View layout = convertView;

        TextView textViewNome = (TextView) convertView.findViewById(R.id.textViewNome);
        textViewNome.setText(itemPosicao.getNome());

        TextView textViewData = (TextView) convertView.findViewById(R.id.textViewData);
        textViewData.setText(itemPosicao.getData());

        TextView textViewRg = (TextView) convertView.findViewById(R.id.textViewRg);
        textViewRg.setText(itemPosicao.getRg());

        TextView textViewCpf = (TextView) convertView.findViewById(R.id.textViewCpf);
        textViewCpf.setText(itemPosicao.getCpf());

        TextView textViewDoenca = (TextView) convertView.findViewById(R.id.textViewDoenca);
        textViewDoenca.setText(itemPosicao.getDoenca());

        TextView textViewAlergia = (TextView) convertView.findViewById(R.id.textViewAlergia);
        textViewAlergia.setText(itemPosicao.getAlergia());

        TextView textViewProfissao = (TextView) convertView.findViewById(R.id.textViewProfissao);
        textViewProfissao.setText(itemPosicao.getProfissao());

       /* Button button = (Button) convertView.findViewById(R.id.buttonEditar);
        button.setOnClickListener(new View.OnClickListener(){

        public void onClick(View v){
            Intent intent = new Intent(context,Novo.class);
            intent.putExtra("nome", itemPosicao.getNome());
            intent.putExtra("data", itemPosicao.getData());
            intent.putExtra("rg", itemPosicao.getRg());
            intent.putExtra("cpf", itemPosicao.getCpf());
            intent.putExtra("doenca", itemPosicao.getDoenca());
            intent.putExtra("alergia", itemPosicao.getAlergia());
            intent.putExtra("profissao", itemPosicao.getProfissao());
            context.startActivity(intent);
           }
        });
    Button buttonDeletar = (Button) convertView.findViewById(R.id.buttonApagar);
        buttonDeletar.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                itemPosicao.apagar();
                if (itemPosicao._status)
                    layout.setVisibility(View.GONE);
                else
                    Toast.makeText(context, itemPosicao.get_messagem(), Toast.LENGTH_LONG).show();
            }
        });*/

        return convertView;

    }

}
  

Class Name Adapter

package com.example.matheus.privatewalletm;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by Matheus on 30/08/2016.
 */
public class NomeAdapter extends ArrayAdapter<Usuario> {
    private Context context;
    private ArrayList<Usuario> lista;

    public NomeAdapter(Context context, ArrayList<Usuario> lista)
    {
        super(context,0,lista);
        this.context = context;
        this.lista = lista;
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        final Usuario itemPosicao = this.lista.get(position);
        convertView = LayoutInflater.from(this.context).inflate(R.layout.item_lista2,null);
        final View layout = convertView;

        TextView textView16 = (TextView) convertView.findViewById(R.id.textView16);
        textView16.setText(itemPosicao.getNome());

        return convertView;

    }

}
  

LIST 1 Class

package com.example.matheus.privatewalletm;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class Lista extends AppCompatActivity {
    private ListView listViewUsuario;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lista);

        this.listViewUsuario = (ListView) findViewById(R.id.listViewUsuario);
        this.listViewUsuario.setAdapter(new UsuarioAdapter(this, new Usuario().getLista()));
    }
    public void voltar(View view){
        finish();
    }


}
  

Class List2

package com.example.matheus.privatewalletm;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class lista2 extends AppCompatActivity {
    private ListView listView2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nome);

        this.listView2 = (ListView) findViewById(R.id.listView2);
        this.listView2.setAdapter(new NomeAdapter(this, new Usuario().getLista()));
    }
    public void voltar(View view)
    {
        finish();
    }


}
    
asked by anonymous 13.09.2016 / 02:43

1 answer

3

I do not think you declared the acitivity in manifest.xml

"Have you declared this activity in your AndroidManifest.xml?"

    
13.09.2016 / 03:13