Database problem

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Database problem

Postby Addion » Tue Nov 18, 2008 3:55 am

I want to open the contacts list in Android. I think the code really makes sense for me, but the emurator always show unexpectedly stop.
Please anyone help me out.

Thanks
Addion
Cursor C = null;
try{
C = managedQuery(Contacts.People.CONTENT_URI, null, null, null, null);
startManagingCursor(C);

}catch (Exception e) {
Log.e("ERROR", "ERROR IN CODE:"+e.toString());
System.out.println ("error--------------");
}


String[] columns = new String[] {People.NAME};
int[] names = new int[] {R.id.row_entry};

mAdapter = new SimpleCursorAdapter(this, R.layout.main,C , columns, names);
setListAdapter(mAdapter);
Addion
Developer
Developer
 
Posts: 29
Joined: Tue Nov 18, 2008 3:49 am

Top

Postby sazabo » Wed Nov 19, 2008 9:52 pm

is it dying in the Adapter?
sazabo
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Nov 19, 2008 8:04 pm

Postby Addion » Thu Nov 20, 2008 5:17 pm

Thanks for replying me.
I debug and I found my cursor was null.
so it counld not show anything. I want to know why.


THanks in advance
Addion
Addion
Developer
Developer
 
Posts: 29
Joined: Tue Nov 18, 2008 3:49 am

Postby Addion » Thu Nov 20, 2008 6:04 pm

I changed my code like this, but it still got error at "C = managedQuery(Contacts.People.CONTENT_URI, null, null, null, null); "


public class TestDatabase extends ListActivity {
Cursor C = null;
ListAdapter mAdapter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

C = managedQuery(Contacts.People.CONTENT_URI, null, null, null, null);
startManagingCursor(C);

String[] columns = new String[] {People.NAME};
int[] names = new int[] {R.id.row_entry};

mAdapter = new SimpleCursorAdapter(this, R.layout.row, C, columns, names);
setListAdapter(mAdapter);
}
}


Addion
Addion
Developer
Developer
 
Posts: 29
Joined: Tue Nov 18, 2008 3:49 am

Postby Addion » Thu Nov 20, 2008 6:07 pm

This is my log

11-21 00:04:45.908: DEBUG/AndroidRuntime(228): --- registering native functions ---
11-21 00:04:47.129: INFO/ActivityManager(53): Starting activity: Intent { flags=0x10000000 comp={com.hullomail.android/com.hullomail.android.TestDatabase} }
11-21 00:04:47.178: DEBUG/AndroidRuntime(228): Shutting down VM
11-21 00:04:47.178: DEBUG/dalvikvm(228): DestroyJavaVM waiting for non-daemon threads to exit
11-21 00:04:47.219: INFO/dalvikvm(228): DestroyJavaVM shutting VM down
11-21 00:04:47.219: DEBUG/dalvikvm(228): HeapWorker thread shutting down
11-21 00:04:47.219: DEBUG/dalvikvm(228): HeapWorker thread has shut down
11-21 00:04:47.219: DEBUG/jdwp(228): JDWP shutting down net...
11-21 00:04:47.228: DEBUG/dalvikvm(228): VM cleaning up
11-21 00:04:47.238: DEBUG/dalvikvm(228): LinearAlloc 0x0 used 539340 of 4194304 (12%)
11-21 00:04:47.267: INFO/ActivityManager(53): Start proc com.hullomail.android for activity com.hullomail.android/.TestDatabase: pid=235 uid=10017 gids={}
11-21 00:04:47.788: DEBUG/AndroidRuntime(235): Shutting down VM
11-21 00:04:47.788: WARN/dalvikvm(235): threadid=3: thread exiting with uncaught exception (group=0x40010e28)
11-21 00:04:47.798: ERROR/AndroidRuntime(235): Uncaught handler: thread main exiting due to uncaught exception
11-21 00:04:47.817: ERROR/AndroidRuntime(235): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hullomail.android/com.hullomail.android.TestDatabase}: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider uri content://contacts/people from pid=235, uid=10017 requires android.permission.READ_CONTACTS
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2156)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.os.Handler.dispatchMessage(Handler.java:88)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.os.Looper.loop(Looper.java:123)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.app.ActivityThread.main(ActivityThread.java:3742)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at java.lang.reflect.Method.invokeNative(Native Method)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at java.lang.reflect.Method.invoke(Method.java:515)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at dalvik.system.NativeStart.main(Native Method)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider uri content://contacts/people from pid=235, uid=10017 requires android.permission.READ_CONTACTS
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.os.Parcel.readException(Parcel.java:1234)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:144)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:110)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.content.ContentProviderProxy.bulkQuery(ContentProviderNative.java:259)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.content.ContentProviderProxy.query(ContentProviderNative.java:278)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.content.ContentResolver.query(ContentResolver.java:147)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.app.Activity.managedQuery(Activity.java:1442)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at com.hullomail.android.TestDatabase.onCreate(TestDatabase.java:22)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2103)
11-21 00:04:47.817: ERROR/AndroidRuntime(235): ... 11 more
11-21 00:04:47.868: INFO/Process(53): Sending signal. PID: 235 SIG: 3
11-21 00:04:47.907: INFO/dalvikvm(235): threadid=7: reacting to signal 3
11-21 00:04:47.958: INFO/dalvikvm(235): Wrote stack trace to '/data/anr/traces.txt'
11-21 00:04:49.418: INFO/jdwp(235): received file descriptor 25 from ADB
11-21 00:04:57.182: WARN/ActivityManager(53): Launch timeout has expired, giving up wake lock!
11-21 00:04:57.517: WARN/ActivityManager(53): Activity idle timeout for HistoryRecord{434f6d88 {com.hullomail.android/com.hullomail.android.TestDatabase}}
11-21 00:05:05.228: DEBUG/dalvikvm(93): GC freed 1017 objects / 53840 bytes in 188ms
Addion
Developer
Developer
 
Posts: 29
Joined: Tue Nov 18, 2008 3:49 am

SecurityException:

Postby sazabo » Thu Nov 20, 2008 6:13 pm

I'm not an expert on this but it may be that you need to setup permissions in the Manifest file to use the contact. take a look at the android docs on this.
Jeff
: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider uri content://contacts/people from pid=2
sazabo
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Nov 19, 2008 8:04 pm

Top

Postby Addion » Thu Nov 20, 2008 6:18 pm

I fixed it after I added READ_CONTACTS permission.

Thanks
Addion
Addion
Developer
Developer
 
Posts: 29
Joined: Tue Nov 18, 2008 3:49 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 4 guests