Programmatically creating a GridLayout from support library - android

In android, is it possible to create a GridLayout from the support library entirely programmatically (i.e. without writing corresponding xml)?
I create my GridLayout in a fragment (called PromotionLayoutFragment) like this:
ViewGroup fragmentView = (ViewGroup)getView();
GridLayout gridLayout = new GridLayout(fragmentView.getContext());
gridLayout.setColumnCount(2);
gridLayout.setRowCount(15);
// add views to grid ...
fragmentView.addView(gridLayout);
This works fine when i use the GridLayout class present in API level 14, but when I use the GridLayout from the support library (v7-r9), i get:
08-10 15:54:52.209: ERROR/AndroidRuntime(14687): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: android.support.v7.gridlayout.R$dimen
at android.support.v7.widget.GridLayout.<init>(GridLayout.java:255)
at android.support.v7.widget.GridLayout.<init>(GridLayout.java:274)
at android.support.v7.widget.GridLayout.<init>(GridLayout.java:282)
at net.link.redbutton.fragment.PromotionLayoutFragment.showPromotions(PromotionLayoutFragment.java:168)
at net.link.redbutton.fragment.PromotionLayoutFragment.onImageResult(PromotionLayoutFragment.java:222)
at net.link.redbutton.fragment.SchedulerResponseFragment$1.onReceiveResult(SchedulerResponseFragment.java:37)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

Turns out that you need to include the GridLayout support library as an Android library project (apklib), instead of a jar. I was using the maven Android SDK deployer, but there is currently an issue open regarding this.

Related

Android support v7 recycleview nullpoint

The recycleview first display is ok,but when scroll up from bottom this exception come out.
It's seem when recycleview reuse item cause this exception.
someone please help me to figure it out..
java.lang.NullPointerException
at android.support.v4.view.ViewCompat$ICSViewCompatImpl.setAccessibilityDelegate(ViewCompat.java:923)
at android.support.v4.view.ViewCompat.setAccessibilityDelegate(ViewCompat.java:1343)
at android.support.v7.widget.RecyclerView$Recycler.addViewHolderToRecycledViewPool(RecyclerView.java:3900)
at android.support.v7.widget.RecyclerView$Recycler.recycleCachedViewAt(RecyclerView.java:3843)
at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:3880)
at android.support.v7.widget.RecyclerView$Recycler.recycleView(RecyclerView.java:3804)
at android.support.v7.widget.RecyclerView$LayoutManager.removeAndRecycleViewAt(RecyclerView.java:5529)
at android.support.v7.widget.LinearLayoutManager.recycleChildren(LinearLayoutManager.java:1143)
at android.support.v7.widget.LinearLayoutManager.recycleViewsFromEnd(LinearLayoutManager.java:1218)
at android.support.v7.widget.LinearLayoutManager.recycleByLayoutState(LinearLayoutManager.java:1242)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1268)
at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1102)
at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:959)
at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:3062)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:524)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
03-13 11:13:13.810: E/AndroidRuntime(8950): at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4819)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
I have faced same issue with my first demo project. I noticed that I was faced this issue when I used older version of android-support-v4.jar
After Puting android-support-v4.jar latest from ../adt-bundle-windows-x86-20140702\sdk\extras\android\support\v4 It solved. So Please change your jar file and run your app. I hope it will help you.

findViewById returning null TextView

This one is driving me and my team completely crazy.
We can't reproduce as it works well on all our test devices but we are getting thousands of crash reports complaining of java.lang.NullPointerException for a TextView which is obtained by findViewById in onCreate (after calling setContentView and with the correct id and layout file)
java.lang.RuntimeException: Unable to start activity ComponentInfo{xxxxxxxxxxxxx.activities.PremiumActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.NullPointerException
at xxxxxxxxx.activities.PremiumActivity.onCreate(PremiumActivity.java:258)
at android.app.Activity.performCreate(Activity.java:5163)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(NativeStart.java)
Here is the onCreate method:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.premium_activity_layout);
premiumInfoHeaderTextView = (TextView) findViewById(R.id.premiumHeaderTextView);
int themeColor = MPThemeManager.getSharedInstance(this).themeColor();
premiumInfoHeaderTextView.setTextColor(themeColor);
That last line is the one causing the nullPointerException (line 258)
Not sure if it can be related but the activity extends SherlockFragmentActivity
And of course premiumInfoHeaderTextView is declared as a TextView outside the onCreate method as we also use it elsewhere.
A crazy fix to a crazy bug!!
As expected in my earlier comment, the bug comes from the fact the an old layout xml file for tablets (under /res/layout-large) has beed removed in our latest version (we now use a single layout file under /res/layout).
Remember the line causing the Null Exception:
premiumInfoHeaderTextView = (TextView) findViewById(R.id.premiumHeaderTextView);
This is due to the fact that our former version layout did not have any view with id = premiumHeaderTextView and that on some tablets for users who upgraded from the previous to the new version, the old layout file has not been deleted and the system is therefore looking for id in the old /res/layout-large/premium_activity_layout.xml rather than in the new (common to all devices) /res/layout/premium_activity_layout.xml
Using crashlytics to understand that all crashes were happening on tablet devices was key to identify this "bug" which seems like a system bug on some tablets as they should not keep old resource files when the apk is upgrade.
So in summary, I copied the /res/layout/premium_activity_layout.xml to /res/layout-large in order to force tablet users to use the new layout and not an old "cached" version. That has completely fixed the bug

TextView animation

I find a good external lib to implement many beautiful Textview animations. The link is this: https://github.com/daimajia/AndroidViewAnimations
I have a problem to implement it. I have imported correctly all 3 libs and I use correctly the function like in the dev's example:
YoYo.with(Techniques.Tada).duration(700).playOn(findViewById(R.id.TextView1));
Eclipse doesn't segnalate me any problem. But when I launch the application, it crashes
p.s. sorry for my bad english, I'm italian :(
EDIT 1:
logcat:
FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.app.ActivityThread.main(ActivityThread.java:4960)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3675)
... 12 more
Caused by: java.lang.NoClassDefFoundError:com.daimajia.androidanimations.library.Techniques
enter code here
I had the same problem. My problem was missing dependency AndroidEasingFunctions-1.0.0. Please make sure all dependencies are included into the project correctly. See https://github.com/daimajia/AndroidViewAnimations.

NoClassDefFoundError occured while initiate fragment

java.lang.NoClassDefFoundError occured at the first line:
FirstFragment firstTab = FirstFragment.newInstance(10);
mTabsAdapter.addTab(generateTabSpec(0, mTabHost),
firstTab.getClass(), null);
But I'm pretty sure the Fragment exist! (it's a fragment so don't need to check if declared in Manifest.) Even refactoring its name or move to other package didn't fix the problem. Here's the stacktrace:
ERROR/AndroidRuntime(23608): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: dev.twothree.android.wtf.FirstFragment
at dev.twothree.android.activity.FragmentTab.setupTabHost(FragmentTab.java:110)
at dev.twothree.android.activity.FragmentTab.onCreate(FragmentTab.java:75)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2136)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2207)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4899)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Is it a bug of Intell J 12.0.4? My version is Build #IC-123.169. Later I'll try it in the Eclipse, but still hope it can be resolved in Intelli J.
After open the whole project with Eclipse, config all the dependencies ONCE AGAIN, Eclipse point out that I accidentally CAST one of the custom library class to another class. Maybe that's why no successful compiled class file existed for later invoke.
Anyway, it seems Intelli-J didn't found that error while 3rd party library is involved, it could be a bug. But the blame is also on me for not find that so obvious error.

Android: ExpandableList View crashed on scrolling more then 30 records in Android OS 4.0

The ExpandableList View crashed on scrolling more then 30 records only in Nexus running "ice cream sandwich Android OS 4.0). This problem only occurred in my Nexus phone. It works fine in my emulator even run it on Andriod 4.0 with more then 30 records.
I have used the android inflate feature (to render the layout from XML file) in getGroupView and getChildView() method of the BaseExpandableListAdapter class. If
If I render the getChildView() and getGroupView() function using the dynamic TextView then it works fine.
The problem only generated during the scroll and also in Android OS 4.0 (nexus) phone otherwise it works fine.
I got following error:
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:549)
at com.android.myexample.Custom$MyExpandableListAdapter.getChildView(Custom.java:681)
at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:450)
at android.widget.AbsListView.obtainView(AbsListView.java:2012)
at android.widget.ListView.makeAndAddView(ListView.java:1772)
at android.widget.ListView.fillUp(ListView.java:705)
at android.widget.ListView.fillGap(ListView.java:645)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4546)
at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:3813)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
the error occured on following code...
childImg.setImageBitmap(BitmapFactory.decodeStream(getAssets().open((childListDataBean.get(groups.get(groupPosition)).get(childPosition).imageId))));
You need to look up approaches to manage your memory. You're consuming too much memory than the VM is going to give you. This is your problem, look up talks by Romain Guy he does specific talks about Graphics and Bitmaps.
Finally I fixed this bug by disabling the scrolling catch of the expandablelistview using following...........................................................
<ExpandableListView
android:id="#+id/android:EL1"
propertiesandroid:overScrollMode="never"
android:scrollingCache="false"
android:transcriptMode="disabled"
android:fastScrollEnabled="false"
android:smoothScrollbar="true"
android:fastScrollAlwaysVisible="false"
android:animationCache="false"
android:persistentDrawingCache="none"
android:alwaysDrawnWithCache="false"
android:drawingCacheQuality="low"
/>

Categories

Resources