Executando o projeto, este apresenta os problemas descritos abaixo na FormularioActivity em relação a AlunoDAO:
C:\VLC\Projeto\Android\Agenda\app\src\main\java\vlc\com\br\agenda\modelo\FormularioActivity.java Error:(51, 32) error: constructor AlunoDAO in class AlunoDAO cannot be applied to given types; required: Context,int found: FormularioActivity reason: actual and formal argument lists differ in length Incremental compilation of 4 classes completed in 2.785 secs. :app:compileDebugJavaWithJavac FAILED Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
package vlc.com.br.agenda.dao;
import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper;
import vlc.com.br.agenda.modelo.Aluno; import vlc.com.br.agenda.modelo.FormularioActivity;
/* Created by Valeria on 01/09/2016. */ public class AlunoDAO extends SQLiteOpenHelper{
public AlunoDAO(Context context, int version) { super(context, "Agenda", null, 1); }
@Override public void onCreate(SQLiteDatabase db) {
String sql = "create table Alunos (id integer primary key, nome text not null," + "endereco text, telefone text, site text, nota real)"; db.execSQL(sql); }
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String sql = "drop table if exists Alunos"; db.execSQL(sql); onCreate(db);
}
public void insere(Aluno aluno) {
SQLiteDatabase db = getWritableDatabase(); ContentValues dados = new ContentValues(); dados.put("nome",aluno.getNome()); dados.put("endereco",aluno.getEndereco()); dados.put("telefone",aluno.getTelefone()); dados.put("site",aluno.getSite()); dados.put("nota",aluno.getNota());
db.insert("Alunos",null,dados);
} }
package vlc.com.br.agenda.modelo;
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.Toast;
import vlc.com.br.agenda.R; import vlc.com.br.agenda.dao.AlunoDAO;
public class FormularioActivity extends AppCompatActivity {
private FormularioHelper helper;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_formulario);
helper = new FormularioHelper(this);
// Button botaoSalvar = (Button) findViewById(R.id.formulario_salvar); // botaoSalvar.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // Toast.makeText(FormularioActivity.this,"Aluno salvo!",Toast.LENGTH_SHORT).show(); // //Intent intentVaiPraLista = new Intent(FormularioActivity.this,ListaAlunosActivity.class); // //startActivity(intentVaiPraLista); // finish(); // // } // // }); }
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_formulario,menu); return super.onCreateOptionsMenu(menu); }
@Override public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){ case R.id.menu_formulario_ok: Aluno aluno = helper.pegaAluno(); AlunoDAO dao = new AlunoDAO(this); dao.insere(aluno); dao.close();
Toast.makeText(FormularioActivity.this,"Aluno salvo!",Toast.LENGTH_SHORT).show(); finish(); break; }
return super.onOptionsItemSelected(item); } }