sqlite with android studio

Asked

Viewed 69 times

0

is already solved. I want to add 3 data (date, location, and price) to my database. already solved some errors in database implementation. but now this error appears to me. I am not very good at expressing myself on this subject, for the reason of being learning now and alone. I have an error on line 41 (AddHistoria.addRegisto(new HistoricoCompras(data, local, preco));) where this error appears ("addhistorico in AddHistorico cannot be aplied to (.com.example.a13731.ganhemais.historico de compras)") in my activity insert.

This is my Activity insert(add):

package com.example.a13731.ganhemais;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.EditText;

public class adiciona extends AppCompatActivity {
EditText edData,edLocal, edPreco;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_adiciona);

Intent intent = getIntent();
final String value1 = intent.getStringExtra("key1");
final String value2 = intent.getStringExtra("key2");

edData = (EditText) findViewById(R.id.edit_data);
edLocal = (EditText) findViewById(R.id.edit_local);
edPreco = (EditText) findViewById(R.id.edit_preco);

}

public void inserirCompra(View v) {
AlertDialog.Builder dialogo = new AlertDialog.Builder(adiciona.this);
dialogo.setTitle("Aviso");
dialogo.setMessage("Inserir aluno?");
dialogo.setNegativeButton("Não", null);
dialogo.setPositiveButton("Sim", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String data = edData.getText().toString();
String local = edLocal.getText().toString();
String preco = edPreco.getText().toString();
AddHistoria.addRHistorico(new HistoricoCompras(data, local, preco));
AlertDialog.Builder d = new AlertDialog.Builder(adiciona.this);
d.setTitle("Aviso");
d.setMessage("Registo inserido!");
d.setNeutralButton("OK", null);
d.show();
edData.getText().clear();
edLocal.getText().clear();
edPreco.getText().clear();
}
});


}

My class (Historicocompras):

package com.example.a13731.ganhemais;

import java.io.Serializable;

/**
* Created by a13731 on 05/06/2017.
*/

public class HistoricoCompras implements Serializable {
private static String data;
private static String local;
private static String preco;
public HistoricoCompras(String data,String local,String preco)
{
this.data=data;
this.local=local;
this.preco=preco;
}
public void setdata(String data) {
this.data = data;
}
public void setlocal(String local) {
this.local = local;
}
public void setpreco(String preco) {
this.preco = preco;
}

public static String getData() {
return data;
}
public static String getLocal() {
return local;
}
public static String getPreco() {
return preco;
}
}

my database (Dbhistorico):

package com.example.a13731.ganhemais; /**
* Created by a13731 on 05/06/2017.
*/
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBhistorico extends SQLiteOpenHelper {
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "GanheMais";
// table name
private static final String TABLE_historia = "Historia";
// Shops Table Columns names
private static final String KEY_Data = "data";
private static final String KEY_local = "local";
private static final String KEY_Preco = "preco";
public DBhistorico(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_historia_TABLE = "CREATE TABLE " + TABLE_historia + "(" + KEY_Data + " TEXT,"
+ KEY_local + " TEXT, " + KEY_Preco + "Text" + ")";
db.execSQL(CREATE_historia_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_historia);
// Creating tables again
onCreate(db);
}

// Adding new shop
public void addCompra(HistoricoCompras Historia) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_Data, HistoricoCompras.getData());
values.put(KEY_local, HistoricoCompras.getLocal());
values.put(KEY_Preco, HistoricoCompras.getPreco());
// Inserting Row
db.insert(TABLE_historia, null, values);
db.close(); // Closing database connection
}
}
isto cria uma array(ADDhISTORIA):
package com.example.a13731.ganhemais;

import java.util.ArrayList;

/**
* Created by a13731 on 05/06/2017.
*/

public final class AddHistoria {


private static ArrayList<Historico> aHistorico = new ArrayList<Historico>();

/*private addHistoria()
{
aHistorico = new ArrayList<Registo>();
}
*/
public static void addRHistorico(Historico r)
{ aHistorico.add(r); }
}
  • Hello Rafael, try to describe better the problem what you have tried to solve, and what you intend with the code, would help anyone who will help you.

  • i want to add 3 data (date, location, and price) in my database. already solved some errors in database implementation. but now this error appears to me. I am not very good at expressing myself on this subject, for the reason to be learning now and alone.

  • Okay, no problem, keep adding this information to your question, just go on edit and put more infections, if someone asks you more information you will added your question.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.