roconmachine
roconmachine

Reputation: 2106

Attempt to invoke virtual method 'com.orm.Database com.orm.SugarApp.getDatabase()' on a null object referenc

I am using Android Studio to develop my android application. In my application i need some db sqlite operations. I start using Sugar ORM. According to the latest version sugar 1.3.jar does not need any context initialization.

So that i start coding like this

Iterator<Order> orders = Order.findAll(Order.class);

<meta-data android:name="DATABASE" android:value="dbname.db" />
    <meta-data android:name="VERSION" android:value="2" />
    <meta-data android:name="QUERY_LOG" android:value="true" />
    <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="value" />

in menifast file.

but i faced a problem is

java.lang.RuntimeException: Unable to start activity ComponentInfo{package.HomeActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.orm.Database com.orm.SugarApp.getDatabase()' on a null object referenc

Do you think i need to do something else or missed something ?? Please help.

thanks

Upvotes: 2

Views: 2930

Answers (1)

user3154785
user3154785

Reputation: 121

Your AndroidManifest.xml file should look like: And make sure you have android:name="com.orm.SugarApp" inside application tag.

<application android:label="@string/app_name" android:icon="@drawable/icon"
android:name="com.orm.SugarApp">
.
.
<meta-data android:name="DATABASE" android:value="sugar_example.db" />
<meta-data android:name="VERSION" android:value="2" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.example" />
.
.
</application>

More info: http://satyan.github.io/sugar/getting-started.html

Upvotes: 8

Related Questions