I changed the code to just use the following array for testing purposes and
i still get the null pointer exception. anyone have any ideas as to why?

String[] array = {"this", "is", "driving", "me", "crazy"};

Spinner spinner_drawings = (Spinner) findViewById(R.id.spinner_drawings);
ArrayAdapter<String> adapter = newArrayAdapter(this,
android.R.layout.simple_spinner_item, array);
adapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
spinner_drawings.setAdapter(adapter);//this is where it bombs out and i have
to close the application






On Tue, Jan 13, 2009 at 1:55 PM, Josh Dobbs <[email protected]> wrote:

> I changed the code to read
>   if (c != null) { .....
>         int MyNameColumn = c.getColumnIndexOrThrow("drawingName");
>        c.moveToFirst();
>   }
> Im catching the exception which is java.lang.NullPointerException.
> I don't understand why tho. There is data in the array, i see it get filled
> when i step through the code. any thoughts on what is going on ?
>
> Thanks!
>
>
>  On Tue, Jan 13, 2009 at 7:22 AM, android_soft <[email protected]>wrote:
>
>>
>>  int MyNameColumn = c.getColumnIndexOrThrow("drawingName");
>>   c.moveToFirst();
>>   if (c != null) { .....}
>>
>> 1. You are checking for null after using it above twice which is
>> redundant......
>> 2. Catch the exception
>> 3. If catching and you are getting a NullPointer then use Lod.e(TAG,
>> exception.getMessage() + ""); // nullpointers, leaving out the "" will
>> break the code.
>>
>> Hope this helps,
>> Chander
>>
>>
>>
>>
>>
>>
>>
>> On Jan 13, 11:57 am, Josh <[email protected]> wrote:
>> > This is still eluding me. here is the log.
>> >
>> > 01-12 22:53:58.836: DEBUG/AndroidRuntime(446): Shutting down VM
>> > 01-12 22:53:58.836: WARN/dalvikvm(446): threadid=3: thread exiting
>> > with uncaught exception (group=0x40010e28)
>> > 01-12 22:53:58.912: ERROR/AndroidRuntime(446): Uncaught handler:
>> > thread main exiting due to uncaught exception
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):
>> > java.lang.NullPointerException: println needs a message
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.util.Log.println(Native Method)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.util.Log.e(Log.java:208)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > com.joshuadobbs.peglites.PegLites.getDrawingsFromDataBase
>> > (PegLites.java:242)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > com.joshuadobbs.peglites.PegLites.showSaveOpenDialog(PegLites.java:
>> > 1284)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > com.joshuadobbs.peglites.PegLites.access$3(PegLites.java:1279)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > com.joshuadobbs.peglites.PegLites$4.onClick(PegLites.java:1338)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.view.View.performClick(View.java:2109)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.view.View.onTouchEvent(View.java:3523)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.widget.TextView.onTouchEvent(TextView.java:4410)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.view.View.dispatchTouchEvent(View.java:3178)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > com.android.internal.policy.impl.PhoneWindow
>> > $DecorView.superDispatchTouchEvent(PhoneWindow.java:1561)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent
>> > (PhoneWindow.java:1085)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.app.Dialog.dispatchTouchEvent(Dialog.java:569)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > com.android.internal.policy.impl.PhoneWindow
>> > $DecorView.dispatchTouchEvent(PhoneWindow.java:1545)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.view.ViewRoot.handleMessage(ViewRoot.java:1140)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.os.Handler.dispatchMessage(Handler.java:88)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.os.Looper.loop(Looper.java:123)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > android.app.ActivityThread.main(ActivityThread.java:3742)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > java.lang.reflect.Method.invokeNative(Native Method)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > java.lang.reflect.Method.invoke(Method.java:515)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
>> > (ZygoteInit.java:739)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
>> > 01-12 22:53:59.221: ERROR/AndroidRuntime(446):     at
>> > dalvik.system.NativeStart.main(Native Method)
>> > 01-12 22:53:59.432: INFO/Process(51): Sending signal. PID: 446 SIG: 3
>> > 01-12 22:53:59.562: INFO/dalvikvm(446): threadid=7: reacting to signal
>> > 3
>> > 01-12 22:53:59.612: INFO/dalvikvm(446): Wrote stack trace to '/data/
>> > anr/traces.txt'
>> >
>> > Thanks in advance.
>> >
>> > On Jan 11, 8:46 pm, Josh <[email protected]> wrote:
>> >
>> > > I am querying the database and adding the results to a list.
>> > > everything works fine until i set the adapter (setAdapter) on
>> myspinnercontrol. I get the error "the application has stopped
>> > > unexpectadely". can anyone tell me what Im doing wrong?
>> >
>> > >                 List<String> results = new ArrayList<String>();
>> >
>> > >                 Cursor c = myDB.rawQuery("SELECT PKDrawingID,
>> drawingName FROM " +
>> > > MY_DATABASE_TABLE,null);
>> > >                 /* Get the column index */
>> > >                 int MyNameColumn =
>> c.getColumnIndexOrThrow("drawingName");
>> >
>> > >                 c.moveToFirst();
>> > >                 if (c != null) {
>> > >                         /* See if we got any results */
>> > >                     if (c.isFirst()) {
>> > >                         int i = 0;
>> > >                         do {
>> > >                                         i++;
>> > >                                         String drawingName =
>> c.getString(MyNameColumn);
>> > >                                         results.add(drawingName);
>> > >                         } while(c.moveToNext());
>> > >                         }
>> > >                     }
>> > >            Spinnerspinner_drawings = (Spinner) findViewById
>> > > (com.test.test3.R.id.spinner_drawings);
>> > >            ArrayAdapter<CharSequence> adapter = newArrayAdapter(this,
>> > > android.R.layout.simple_spinner_item, results);
>> > >            adapter.setDropDownViewResource
>> > > (android.R.layout.simple_spinner_dropdown_item);
>> > >            spinner_drawings.setAdapter(adapter);//this is where it
>> > > bombs out and i have to close the application
>> >>
>>
>
>

--~--~---------~--~----~------------~-------~--~----~
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