Hey there!

I'm currently working on a component that's retrieving contact
information and creating an RDF model (FOAF tbe) from the data
provided. I started off with the HelloAndroid example and tried some
code in there. Everything worked out fine, so I wanted to put
everything in a seperate class which can be accessed via an interface.

However, now I'm getting a NullPointer Exception when I want to call a
managedQuery().
So I tried to create a ContentResolver in order to perform a query().
But as soon as I call the getContentResolver() I'm getting a
NullPointer Exception as well.

I think this could be a problem concerning the AndroidManifest.xml or
lack of knowledge about how to handle Activities and the likes? I've
been struggling with that for quite some hours now and think that I
won't solve this on my own, so I'd like to get your opinions and
ideas!

However, here's my code:
--------------------------------------------------------------------------
package com.example.helloandroid;

import it.polimi.elet.contextaddict.microjena.rdf.model.Model;
import it.polimi.elet.contextaddict.microjena.rdf.model.ModelFactory;
import it.polimi.elet.contextaddict.microjena.rdf.model.Resource;
import it.polimi.elet.contextaddict.microjena.vocabulary.RDF;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;

public class CPAddressbook extends Activity implements
IBasicContextProvider {

     Model contextModel;

     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          contextModel = ModelFactory.createDefaultModel();
     }

     @Override
     public void detectContext(Model model) {

          Uri contactsURI = ContactsContract.Data.CONTENT_URI;

          String[] projection = new String[] {
                    ContactsContract.Data._ID,
                    ContactsContract.Data.CONTACT_ID,
                    ContactsContract.Data.MIMETYPE,
                    ContactsContract.Data.DATA1,
                    ContactsContract.Data.DATA2,
                    ContactsContract.Data.DATA3,
                    ContactsContract.Data.DATA4,
                    ContactsContract.Data.DATA5,
                    ContactsContract.Data.DATA_VERSION
          };
          String where =      ContactsContract.Data.MIMETYPE + " = ?
OR " +
                              ContactsContract.Data.MIMETYPE + " = ?
OR " +
                              ContactsContract.Data.MIMETYPE + " = ?
OR " +
                              ContactsContract.Data.MIMETYPE + " = ?";

          String[] whereArgs = new String[] {
 
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE,
 
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
 
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE,
 
ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
          };

          Cursor contactsTable = managedQuery(contactsURI, projection,
where, whereArgs, null);

          writeToContextModel(contactsTable);
     }
...
--------------------------------------------------------------------------


This is the class that calls the detectContext():
--------------------------------------------------------------------------
package com.example.helloandroid;

import it.polimi.elet.contextaddict.microjena.rdf.model.Model;
import it.polimi.elet.contextaddict.microjena.rdf.model.ModelFactory;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.TextView;

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello Android!");

       IBasicContextProvider cpAddressbook = new CPAddressbook();
       cpAddressbook.detectContext(ModelFactory.createDefaultModel());
       Model model = cpAddressbook.getContextModel();

       setContentView(tv);

   }
}
--------------------------------------------------------------------------
This is also where I had my query before. It was exactely the same
code!

and finally my AndroidManifest.xml:
--------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
      package="com.example.helloandroid"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/
app_name">
        <activity android:name=".HelloAndroid"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



<activity android:name=".CPAddressbook" android:label="@string/
app_name" android:permission="android.permission.READ_CONTACTS"></
activity>
</application>
    <uses-sdk android:minSdkVersion="5" />

<uses-permission android:name="android.permission.READ_CONTACTS"></
uses-permission>
<uses-library android:name="it.polimi.elet.contextaddict.microjena"></
uses-library>
</manifest>
--------------------------------------------------------------------------

I tried it with and without the additional permission within
the .CPAddressbook and it didn't make any difference.

Is it about something in the AndroidManifest.xml or do I handle
Activities incorrectly? Or both?

Any help would be appreciated Smile

Thanks for your time!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to