Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Class cannot be read from Sqlite3 database. #20

Closed
hendrikschneider opened this issue May 15, 2013 · 10 comments
Closed

Error: Class cannot be read from Sqlite3 database. #20

hendrikschneider opened this issue May 15, 2013 · 10 comments

Comments

@hendrikschneider
Copy link

My Class:
public class BankAccount extends SugarRecord{
String name;
String alias;

public BankAccount(Context context) {
    super(context);
}

public BankAccount(Context context, String name) {
    super(context);
    this.name = name;
    this.alias = name;
}

public BankAccount(Context context, String name, String alias) {
    super(context);
    this.name = name;
    this.alias = alias;
}

I can create new entries (The logs are saying that):
BankAccount bankAccount = new BankAccount(context, sms.getAccount());
bankAccount.save();

But I when I try to get a list of all entries with:
List bankAccounts = BankAccount.listAll(BankAccount.class);

I get a list with all entries but this error, too:
05-15 19:22:37.977: ERROR/Sugar(13045): Class cannot be read from Sqlite3 database.

@noelb
Copy link

noelb commented May 17, 2013

I'm seeing the same error when using the 1.1 jar. It cleared up when I pulled down the latest source and just dropped it in directly. The jar may need to be rebuilt?

@satyan
Copy link
Collaborator

satyan commented May 17, 2013

Yes. It has been corrected in the latest code. It was an incorrect path in the inflate method of SugarRecord. You could build the jar again or use it as library. I'll release the 1.2 jar soon.

thanks.
Satya

@noelb
Copy link

noelb commented May 19, 2013

Thanks Satyan! Terrific library, btw, extremely simple and lightweight.

@satyan
Copy link
Collaborator

satyan commented May 19, 2013

Thanks @noelb .. Let me know if you have any ideas to improve it further..

Closing this issue.

@satyan satyan closed this as completed May 19, 2013
@hendrikschneider
Copy link
Author

Thanks. Cool lib by the way :)

@Marwen1990
Copy link

Hi, I use the version 1.2 of sugar and I have an error message "class cannot be read from sqlite3 database" so I can't modify the value of a column. Any suggestions to fix this?

@satyan
Copy link
Collaborator

satyan commented Aug 5, 2013

@Marwen1990 can you post your class here (or in private to me).. thanks.

@Marwen1990
Copy link

package com.example.newproject;

import android.content.Context;

import com.orm.SugarRecord;

public class Contact extends SugarRecord{

private static Context context;
private String nom;
private String phoneNo;
Groupe groupe;
boolean selected = false;

public Contact(Context context){
    super(context);
}

public Contact(String nom, String phoneNo, boolean selected) {
  super(context);
  this.nom = nom;
  this.phoneNo = phoneNo;
  this.selected = selected;
 }

public Contact(Context context, String nom, String phoneNo,Groupe groupe) {
    super(context);
    this.nom = nom;
    this.phoneNo=phoneNo;
    this.groupe=groupe;
}

public Contact(String nom, String phoneNo,Groupe groupe) {
    super(null);
    this.nom = nom;
    this.phoneNo=phoneNo;
    this.groupe=groupe;
}

public String getNom() {
    return nom;
}

public void setNom(String nom) {
    this.nom = nom;
}



public String getPhoneNo() {
    return phoneNo;
}

public void setPhoneNo(String phoneNo) {
    this.phoneNo = phoneNo;
}

public Groupe getGroupe() {
    return groupe;
}

public void setGroupe(Groupe groupe) {
    this.groupe = groupe;
}

@Override
public String toString() {
    return  nom + "\r\n" + phoneNo + " "+id ;
}

public boolean isSelected() {
      return selected;
}

public void setSelected(boolean selected) {
      this.selected = selected;
}

}

Activity :

package com.example.newproject;

import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ListView;

import com.orm.query.Select;

public class CheckActivity extends ListActivity {

private ListView listview;


protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contactbase);


    listview = (ListView) findViewById(android.R.id.list);
    getListView().setOnCreateContextMenuListener(this);

    @SuppressWarnings("unchecked")
    List<Contact> contacts = Select.from(Contact.class).list();
    ContactAdapter3 objAdapter = new ContactAdapter3(CheckActivity.this, R.layout.contact_check, contacts);
    listview.setAdapter(objAdapter);
}

public void MyHandler(View v) {
    CheckBox cb = (CheckBox) v;

    if (cb.isChecked()) {
        CharSequence nom = cb.getText();
        String nom1= nom.toString();
        List<Contact> con = Contact.find(Contact.class, "nom= ?", nom1);
        Contact coo = con.get(0);
        Contact cc=Contact.findById(Contact.class,coo.getId() );
        System.out.println("la position est : "+coo.getId());
        cc.setSelected(true);


    } else {
        CharSequence nom = cb.getText();
        String nom1= nom.toString();
        List<Contact> con = Contact.find(Contact.class, "nom= ?", nom1);
        Contact coo = con.get(0);
        Contact cc=Contact.findById(Contact.class,coo.getId() );
        System.out.println("la position est : "+coo.getId());

        cc.setSelected(false);
    }
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add( 1 , 1 , 3 , "Enregistrer");
    return super.onCreateOptionsMenu(menu);
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {

    Intent i = new Intent (getApplicationContext(), GroupeListActivity.class);
    startActivity(i);
    return super.onOptionsItemSelected(item);
}

}

@satyan
Copy link
Collaborator

satyan commented Aug 5, 2013

Do you need the context property in contact class? That looks like the issue.
You can remove that and try. If you want to retain that, please annotate with @ignore

That would make sure that sugar doesn't try to persist context.
Let me know if this resolves the issue.

@Marwen1990
Copy link

Or without Context haw can I save an element in the table contact for example? I tried to remove the Context but when I try to save an element an error "Nullpointerexception" was made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants