NoClassDefFoundError occured while initiate fragment - android

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.

Related

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.

Android ZBar Exception only with Jenkins build

I have an android project with a QR scan activity. I use the ZBar library for this: http://sourceforge.net/projects/zbar/files/AndroidSDK/
If the project is built on a PC or Mac with exlipse, the app works fine.
If it's build by jenkins (same source from git) the app crashes.
The Exception I get is:
at controller.gui.activity.QRScanActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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)
Caused by: java.lang.NoSuchFieldError: no field with name='peer' signature='J' in class Lnet/sourceforge/zbar/ImageScanner;
at net.sourceforge.zbar.ImageScanner.init(Native Method)
at net.sourceforge.zbar.ImageScanner.<clinit>(Unknown Source)
... 16 more
I used the demo app for a base.
Is this a Jenkins config problem?
The Zbar library is not just a jar file, it's a C library with jni. So I have a jar file and 3 folders (for different architectures I think) and they have a libiconv.so and a libzbarjni.so files.
Add -keep class net.sourceforge.zbar.** { *; } to your proguard config file
I Dont know if you already figured it out, but this is a proguard issue. Seems your JNI classes are not being obfuscated correctly. You might need to change your proguard config to skip ZBar files.

What could be causing a ClassNotFoundException?

So I've been working on an app lately which runs fine on most devices. However, sometimes the app crashes at start up with the following error:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.mypackage.app/com.mypackage.app.activities.MainPager}:
java.lang.ClassNotFoundException: com.mypackage.app.activities.MainPager
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
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:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException:
com.mypackage.app.activities.MainPager
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1986)
... 12 more
I get that this is because it can't find the class called MainPager. But how is that even possible? I mean, the class should be there.. I put it there myself :) . Why on earth is it not finding it?
EDIT: I think the cause may be that in my manifest I have android:package="com.mypackage.app" defined, but that my launch activity is in the package com.mypackage.app.activities. Currently testing this theory. Still weird that it only happens on some devices, though.
This solution won't work, since I then can't update the APK in Google Play (has to be the same package name in the manifest).
Since ADT update to revision 22 (May 2013) you have to check "Android Private Libraries" check box in Project -> Properties -> Java Build Path -> Order and Export in Eclipse for your older projects to get rid of this exception ...
in the manifest you add Activity name like this
android:name=".activities.MainPager"
because you have given package name
android:package="com.mypackage.app"
Now I am using ART runtime on Nexus 5, and I am getting ClassNotFound for some apps.
You can safely ignore those if that's the case for your users.

getting stragne unexpected error sometime using ActionBarSherlock

I am using ActionBarShelock and some time get force close with this error cant find how to handle it .
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sps/com.sps.ui.activities.HomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v4.app._ActionBarSherlockTrojanHorse.onCreatePanelMenu(_ActionBarSherlockTrojanHorse.java:52)
at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:556)
at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:60)
at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:154)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:747)
at com.android.internal.policy.impl.PhoneWindow.restorePanelState(PhoneWindow.java:1677)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1627)
at android.app.Activity.onRestoreInstanceState(Activity.java:928)
at android.app.Activity.performRestoreInstanceState(Activity.java:900)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2037)
... 11 more
In the r7 support library, the version on which the current release (4.1.0) of ActionBarSherlock is based, the FragmentManager class checked if mActive != null before dispatching menu events to the fragments contained in the mAdded list. This code was copied into ActionBarSherlock since it uses its own MenuItem type and does its own dispatching.
In a subsequent release of the support library, it was found that this check was no longer representative of whether or not mAdded had been instantiated with a list or not. Commit 464b6f3c changed the conditional check to mAdded != null.
ActionBarSherlock has not had a release since this fix was made. However, it was updated on the dev branch in commit 69fe6fd to be included in the next release.

How to resolve Exception during suite construction?

I have followed the below steps to test my app.
I have created Android Project.
I have created the debug signature for my sample app and test app(which need to be tested)
Place the sampleapp_debug.apk in the bin folder (where my workspace is there)
Installed the testapp_debug.apk in the emulator.
Now i am running the project as a Android JunitTest.
I am getting the below error.. How to resolve this..
java.lang.RuntimeException: Exception during suite construction
at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:239)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
Caused by: java.lang.NullPointerException: Method name must not be null.
at java.lang.ClassCache.findMethodByName(ClassCache.java:297)
at java.lang.Class.getMethod(Class.java:985)
at android.test.suitebuilder.TestMethod.getAnnotation(TestMethod.java:60)
at android.test.suitebuilder.annotation.HasMethodAnnotation.apply(HasMethodAnnotation.java:39)
at android.test.suitebuilder.annotation.HasMethodAnnotation.apply(HasMethodAnnotation.java:30)
at com.android.internal.util.Predicates$OrPredicate.apply(Predicates.java:106)
at android.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java:42)
at android.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java:31)
at com.android.internal.util.Predicates$NotPredicate.apply(Predicates.java:122)
at android.test.suitebuilder.TestSuiteBuilder.satisfiesAllPredicates(TestSuiteBuilder.java:254)
at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:190)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:373)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4218)
at android.app.ActivityThread.access$3000(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
I faced similar type of problem before. I resolved the same by using default constructor in Testcode rather than parametrized constructor. The following tutorial was useful for me
See this tutorial
I encounter the same error and this solution worked for me:
Do not use public TestTextView(String name) but public TestTextView()
as constructor.
as what W.Elsinga mention on his comment found here Link
Your referenced code was way old.
Just add default constructor.
public StartActivityTest() {
super(StartActivity.class);
}
I think the problem at method: android.test.suitebuilder.TestMethod.getAnnotation().
Try to call the method setName() at constructor of the activity.
See: RuntimeException while using ActivityUnitTestCase, but not while ActivityInstrumentationTestCase2
The exception is caused by android.test.suitebuilder.TestMethod.getAnnotation(), too.

Categories

Resources