Pergunta

I have used the HelloAndroid example of the OrmLite and modified it according to my requirements and it works perfectly fine.

But then I added another Bean(POJO with proper annotations) and also updated my Config.txt file for the new table Added like this

# --table-start--
dataClass=com.example.helloandroid.SchoolDataBean

@DatabaseField(generatedId = true)
tableName=schooltable
# --table-fields-start--

# --field-start--
fieldName=rollNo
generatedId=true
# --field-end--

# --field-start--
fieldName=name
indexName=simpledata_string_idx
# --field-end--

# --field-start--
fieldName=gender
# --field-end--

# --field-start--
fieldName=presence
# --field-end--

# --table-fields-end--
# --table-end--

# --table-start--
dataClass=com.example.helloandroid.CompanyDataBean

@DatabaseField(generatedId = true)
tableName=companytable
# --table-fields-start--

# --field-start--
fieldName=companyId
generatedId=true
# --field-end--

# --field-start--
fieldName=name
indexName=simpledata_string_idx
# --field-end--

# --field-start--
fieldName=designation
# --field-end--

# --field-start--
fieldName=annualPay
# --field-end--

# --table-fields-end--
# --table-end--

Similar to the first table i have added the second table, i believe that there is something I am doing wrong with the Config class itself.

The Exception says this

java.sql.SQLException: Could not find declared field with name 'companyId' for class com.example.helloandroid.SchoolDataBean

There must be some way to tell the compiler that the first table has ended and the new table is to be read now, as its reading the second table's column name in the first table.

public class CompanyDataBean {

    //id is generated by the database and set on the object automagically
    @DatabaseField(generatedId = true)
    int companyId;
    @DatabaseField(index = true)
    String name;
    @DatabaseField
    String designation;
    @DatabaseField
    String annualPay;

    public CompanyDataBean() {
    }

    public CompanyDataBean(int companyId,String name, String designation, String annualPay){
        this.companyId=companyId;
        this.name=name;
        this.designation=designation;
        this.annualPay=annualPay;
    }   
}

Thats how my BEAN looks like. thanks.

Foi útil?

Solução

I suspect that there is some syntax error in your configuration file that isn't immediately obvious in your cut and paste. I would highly recommend that you don't generate this file by hand. You need to remove these lines to start.

@DatabaseField(generatedId = true)

Aside from those, I don't see any problems with the file although you need to make sure that all of the # lines are not indented. If you post the actual file to http://pastebin.com/ and edit your question with the URL, maybe we can help more.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top