Gridview content provider

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Gridview content provider

Postby Exeter » Mon Jan 04, 2010 9:54 am

Hey there. I'm troubleshooting a Gridview problem that's supposed to display icons from an SQLite content provider. I'm guessing that it is one or a combination of,

1. creating a Cursor within a Baseadapter class using "activity.managedQuery()"
2. calling the above cursor from another class using "gridview.setAdapter()"
3. Something else (ex database issue)



The Activity calling the Gridview is as follows:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class mView extends Activity {
  2.  
  3.  
  4.  
  5.  
  6.  
  7.         //GridView gridview = (GridView) findViewById(R.id.gridview);
  8.  
  9.         //gridview.setAdapter(new GridAdapter(this));
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. }
  18.  
  19.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4




The code returning the Cursor is as follows,



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class GridAdapter extends BaseAdapter {
  2.  
  3.  
  4.  
  5.     //Set variables
  6.  
  7.     URI uri = com.example.provider.CONTENT_URI;
  8.  
  9.     String projection[] = new String[] { Constants.KEY_ID, Constants.KEY_ICON };
  10.  
  11.     String selection = null;
  12.  
  13.     String[] selectionArgs = null;
  14.  
  15.  
  16.  
  17.     //Get Dataset from database
  18.  
  19.     Cursor cursor = fetchRecords(uri, projection, selection, selectionArgs);
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. private Cursor fetchRecords(Uri uri, String projection[], String selection, String[] selectionArgs) throws SQLException {
  28.  
  29.  
  30.  
  31.         // An array specifying which columns to return.
  32.  
  33.         Activity activity = new Activity();
  34.  
  35.         Cursor cursor = activity.managedQuery(uri, projection, // Which columns to return
  36.  
  37.                 selection, // WHERE clause; which rows to return(all rows)
  38.  
  39.                 selectionArgs, // WHERE clause selection arguments (none)
  40.  
  41.                 Constants.KEY_ID + " ASC" // Order-by clause (ascending by name)
  42.  
  43.         );      
  44.  
  45.  
  46.  
  47.                     if (cursor != null) {
  48.  
  49.                         cursor.moveToFirst();
  50.  
  51.                     }
  52.  
  53.         return mCursor;
  54.  
  55.  
  56.  
  57.      }
  58.  
  59.  
  60.  
  61.  
  62.  
  63. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4



I receive two errors when the project is run.

1. IDE side
=-=-=-=
Starting: Intent { cmp=org.me.example/com.example.mView }
Error type 3
Error: Activity class {org.me.example/com.example.mView} does not exist.

2. Emulator

The application com.example (process com.example) has stopped unexpectedly. Please try again.


FYI I refactored the package from org.me.example to com.example. I've scoured the manifest etc to ensure that no remnants of unchanged code remain.


Any help would be appreciated. :)
Exeter
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Dec 22, 2009 4:17 pm

Top

Postby Exeter » Mon Jan 04, 2010 4:28 pm

The debugger is showing a NullPointerException. Which I gather has something to do with with the way I'm passing an array to the ImageView. Any thoughts?

imageview.setImageResource(cursor.getColumnIndex(Constants.KEY_ICON));


java.lang.nullpointerexception
01-04 10:14:02.514: WARN/dalvikvm(4871): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
01-04 10:14:02.524: ERROR/AndroidRuntime(4871): Uncaught handler: thread main exiting due to uncaught exception
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.mView}: java.lang.NullPointerException
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2497)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1848)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at android.os.Handler.dispatchMessage(Handler.java:99)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at android.os.Looper.loop(Looper.java:123)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at android.app.ActivityThread.main(ActivityThread.java:4338)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at java.lang.reflect.Method.invoke(Method.java:521)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at dalvik.system.NativeStart.main(Native Method)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): Caused by: java.lang.NullPointerException
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:90)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at android.app.Activity.managedQuery(Activity.java:1495)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at com.example.GridAdapter.displayRecords(GridAdapter.java:93)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at com.example.GridAdapter.<init>(GridAdapter.java:48)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at com.example.mView.onCreate(mView.java:34)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-04 10:14:02.554: ERROR/AndroidRuntime(4871): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444)

Exeter
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Dec 22, 2009 4:17 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 6 guests