Exception while scrolling view

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

Exception while scrolling view

Postby grbrg » Wed Jul 15, 2009 8:47 am

Hi all,

I'm currently working myself into Android and finding the transition from J2ME enjoyable. Right now I have a weird problem, though, and hope someone here can point me into the right direction.

My activity consists of a linear layout, which holds a ListView (can't use ListActivity as there will be other stuff on the page later on). The list view contains of a number of custom views using a custom adapter. All seems to be working ok, but when I try to drag the view (for scrolling) I get some warning about unhandled key events and a NullPointerException:

Code: Select all
07-15 06:45:45.677: WARN/WindowManager(568): Key dispatching timed out sending to com.xxxx.xxxxxxxx/com.xxxx.xxxxxxxx.Xxxxxx
07-15 06:45:45.688: WARN/WindowManager(568): Dispatch state: {{KeyEvent{action=1 code=82 repeat=0 meta=0 scancode=229 mFlags=8} to Window{4369bc40 Keyguard paused=false} @ 1247640336656 lw=Window{4369bc40 Keyguard paused=false} lb=android.view.ViewRoot$W@4369b940 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{43725178 com.xxxx.xxxxxxxx/com.xxxx.xxxxxxxx.Xxxxxx paused=false}}}
07-15 06:45:45.688: WARN/WindowManager(568): Current state:  {{null to Window{43725178 com.xxxx.xxxxxxxx/com.xxxx.xxxxxxxx.Xxxxxx paused=false} @ 1247640345692 lw=Window{43725178 com.xxxx.xxxxxxxx/com.xxxx.xxxxxxxx.Xxxxxx paused=false} lb=android.os.BinderProxy@435ef530 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{43725178 com.xxxx.xxxxxxxx/com.xxxx.xxxxxxxx.Xxxxxx paused=false}}}
07-15 06:45:45.698: WARN/WindowManager(568): Continuing to wait for key to be dispatched
07-15 06:45:47.287: DEBUG/AndroidRuntime(953): Shutting down VM
07-15 06:45:47.287: WARN/dalvikvm(953): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
07-15 06:45:47.287: ERROR/AndroidRuntime(953): Uncaught handler: thread main exiting due to uncaught exception
07-15 06:45:47.528: ERROR/AndroidRuntime(953): java.lang.NullPointerException
07-15 06:45:47.528: ERROR/AndroidRuntime(953):     at android.view.ViewConfiguration.get(ViewConfiguration.java:184)
07-15 06:45:47.528: ERROR/AndroidRuntime(953):     at android.view.View.buildDrawingCache(View.java:5533)
07-15 06:45:47.528: ERROR/AndroidRuntime(953):     at android.view.View.getDrawingCache(View.java:5458)
07-15 06:45:47.528: ERROR/AndroidRuntime(953):     at android.view.ViewGroup.drawChild(ViewGroup.java:1422)
07-15 06:45:47.528: ERROR/AndroidRuntime(953):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
...


What am I missing here? Do I need to override some methods in my custom views or adapter for handling touch and/or scroll events? Or is it something completely different?

Edit: Clarified that I use a standard ListView, but a custom ListAdapter and custom views within the list.
grbrg
Developer
Developer
 
Posts: 34
Joined: Mon Jul 13, 2009 1:55 pm

Top

Postby mangaluve » Wed Jul 15, 2009 10:16 am

So, just so I know that I got it, the ListView is "filled" with custom views? It looks almost like you get an exception in the ondraw-method of your custom views, but it's hard to tell without more information..
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby grbrg » Wed Jul 15, 2009 11:15 am

Hi mangaluve,

that's right, the ListView ist filled (through a list adapter) with my custom views. I've added a try-catch to the onDraw() method of my custom view, but the exception does not seem to come from there.

If you need any more information that can help I'm happy to provide it.
grbrg
Developer
Developer
 
Posts: 34
Joined: Mon Jul 13, 2009 1:55 pm

Postby grbrg » Thu Jul 16, 2009 12:12 pm

I've now had a look at the source code and this seems to be the line 1235 (!) causing the NullPointerException:

Code: Select all
1232:      ...
1233:      } finally {
1234:           surface.unlockCanvasAndPost(canvas);
1235:      }
1236:      ...


"surface" and "canvas" are both not null. However, within canvas the "mBitmap", "mDrawFilter" and "mGL" are null. Could this be the cause of the problem? And what can I do to remedy it?
grbrg
Developer
Developer
 
Posts: 34
Joined: Mon Jul 13, 2009 1:55 pm

Postby mangaluve » Sat Jul 18, 2009 11:39 am

the source code you refer to, which class is that?
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby grbrg » Sat Jul 18, 2009 4:48 pm

Sorry for not being clear, the exception stack I get right now when trying to scroll is this one:

Code: Select all
Thread [<3> main] (Suspended (exception NullPointerException))   
   ViewRoot.draw(boolean) line: 1235   
   ViewRoot.performTraversals() line: 1030   
   ViewRoot.handleMessage(Message) line: 1482   
   ViewRoot(Handler).dispatchMessage(Message) line: 99   
   Looper.loop() line: 123   
   ActivityThread.main(String[]) line: 3948   
   Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]   
   Method.invoke(Object, Object...) line: 521   
   ZygoteInit$MethodAndArgsCaller.run() line: 782   
   ZygoteInit.main(String[]) line: 540   
   NativeStart.main(String[]) line: not available [native method]   
grbrg
Developer
Developer
 
Posts: 34
Joined: Mon Jul 13, 2009 1:55 pm

Top

Postby mangaluve » Sat Jul 18, 2009 5:46 pm

hm okey.. dont really know what the problem might be, if you have the possibility of showing your code it would be a lot easier :)
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby grbrg » Sat Jul 18, 2009 7:00 pm

I'll try to post the relevant parts of the code (there's lots of debug code in it right now). If you miss anything, let me know. :)

That's what the layout looks like:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.         android:id="@+id/linear_layout"
  7.  
  8.    android:orientation="vertical"
  9.  
  10.    android:layout_width="fill_parent"
  11.  
  12.    android:layout_height="fill_parent"
  13.  
  14.    android:background="#ff181818"
  15.  
  16.    >
  17.  
  18.                
  19.  
  20.         <ListView
  21.  
  22.                 android:id="@+id/my_list"
  23.  
  24.                 android:layout_height="wrap_content"
  25.  
  26.                 android:layout_width="fill_parent"
  27.  
  28.         />
  29.  
  30.        
  31.  
  32. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


In the onCreate() I do this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public void onCreate(Bundle savedInstanceState)
  3.  
  4. {
  5.  
  6.         super.onCreate(savedInstanceState);
  7.  
  8.         setContentView(R.layout.my_layout);
  9.  
  10.  
  11.  
  12.         this.layout = (LinearLayout) this.findViewById(R.id.linear_layout);
  13.  
  14.  
  15.  
  16.         ArrayList<MyData> list = new ArrayList<MyData>();
  17.  
  18.         list.add(new MyData());
  19.  
  20.         list.add(new MyData());
  21.  
  22.         list.add(new MyData());
  23.  
  24.  
  25.  
  26.         ListView lv = (ListView) this.layout.getChildAt(0);
  27.  
  28.         MyListAdapter la = new MyListAdapter(list);
  29.  
  30.         lv.setAdapter(la);
  31.  
  32. }
  33.  
  34.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


MyView extends View and overrides onDraw(), onMeasure() and the required constructors. I hope this points out the (obvious?) thing I'm missing... :)
grbrg
Developer
Developer
 
Posts: 34
Joined: Mon Jul 13, 2009 1:55 pm

Postby grbrg » Tue Jul 21, 2009 8:44 am

I've now mangaged to work around the problem by extending my custom class from TextView, instead of just View. I've not found any issue with extending directly from View, but most examples extend some specialized class.

Anyway, the problem is not pressing anymore. However, if anyone knows what I need to do when extending View directly, I'm still interested to know.
grbrg
Developer
Developer
 
Posts: 34
Joined: Mon Jul 13, 2009 1:55 pm

Postby mangaluve » Sun Jul 26, 2009 7:37 pm

hello :) haven't been able to answer for a week :)

It's nearly impossible to tell without seeing the code for your custom view
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests