convertView stays null

50 views Asked by At

i got a "funny" issue because i'm inflating my layout in a BaseAdapter in the getView method and my give the returned view to convertView. The funny Thing is, convertView stays null:

convertView = myInflater.inflate(R.layout.customadapter_view_layout_medium, parent);

I went trough Debugging:

enter image description here

Everything got his correct reference. Parent is referencing to GridView, myInflater is not null, the id of the layout which i inflate is also existing. But convertView stays null.

This is my logCat:

11-25 18:29:38.711: E/AndroidRuntime(2377): FATAL EXCEPTION: main
11-25 18:29:38.711: E/AndroidRuntime(2377): java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.widget.AdapterView.addView(AdapterView.java:477)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.LayoutInflater.inflate(LayoutInflater.java:497)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at com.android.faccess.NewCustomAdapter.getView(NewCustomAdapter.java:87)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.widget.AbsListView.obtainView(AbsListView.java:2159)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.widget.GridView.onMeasure(GridView.java:1040)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.View.measure(View.java:15513)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:645)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:425)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.View.measure(View.java:15513)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.View.measure(View.java:15513)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.View.measure(View.java:15513)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.View.measure(View.java:15513)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.Choreographer.doFrame(Choreographer.java:532)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.os.Handler.handleCallback(Handler.java:725)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.os.Looper.loop(Looper.java:137)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at android.app.ActivityThread.main(ActivityThread.java:5039)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at java.lang.reflect.Method.invokeNative(Native Method)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at java.lang.reflect.Method.invoke(Method.java:511)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-25 18:29:38.711: E/AndroidRuntime(2377):     at dalvik.system.NativeStart.main(Native Method)

Can anyone please tell me why this line throws a UnsupportedOperationException? Any help is appreciated.

1

There are 1 answers

1
Pedro Oliveira On BEST ANSWER

If you provide a parent you need to provide true of false as the 3rd parameter either you want to inject the inflated view on the parent or not. Also the convertview is null on that breakpoint. It will only have a value AFTER that line. But the line is throwing an exception because you miss the last parameter.

convertView = myInflater.inflate(R.layout.customadapter_view_layout_medium, parent,false);