I'm developing for 2.2 (minSdkVersion=8) and suddenly I'm getting this error:
arbitrarily rejecting large method (regs=75 count=28584)
rejected Lcom/Demo/Loyalty/SelectType;.onClick (Landroid/view/View;)V
Verifier rejected class Lcom/Demo/Loyalty/SelectType;
Class init failed in newInstance call (Lcom/Demo/Loyalty/SelectType;)
java.lang.VerifyError: com.Demo.Loyalty.SelectType
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)
at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
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 java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
It was working fine until now.
Note : SelectType class has around 16000 lines of code but that is not that large I guess.
I search a lot on net and from answers, I did following:
Clean the project
Reset the ADB
Restart emulator/device/eclipse
Checked that third party library field is checked in build path
But I'm still getting that error.
Any help appreciated.
The steps you've described probably won't help.
The thing is, it's not a Dalvik issue. Similar verifier is employed in the Oracle Java VM for example. Simple answer: your method is too complex. The error you see is mainly caused by too many:
parameters
local variables
exception handlers
code instructions
More precisely, the issue has been described in this thread: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/4qNoIdBHYFc
To quote:
The value of (number of registers * number of instruction words) is
larger than 2^21. (...)
it's intended to
prevent the verifier from bloating up an app's native heap.
You can also see similar report here: http://www.mentby.com/Group/android-developers/verifyerror-arbitrarily-rejecting-large-method.html with pointers on how to resolve the issue:
Yep, the Dalvik compiler attempts to assign a "register" to every
local variable in the method. It should be able to handle that many,
but apparently can't. By making them instance variables you remove
the compiler's need/desire to "manage" them (and also make the method
a fair amount smaller).
So to solve it, you should generally break the large method (probably onClick()?) into smaller pieces. Also, converting local variables to class fields seemed to help some people with the same issue.
Related
Guys I am getting the below error in RunTime, what is the root cause of this error?
java.lang.VerifyError: appPackageName at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2698)
at android.app.ActivityThread.access$1900(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1413)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5457)
at java.lang.reflect.Method.invokeNative(Native Method)
You are probably using or accessing something which is simply supported in higher android SDK, as the error shows here java.lang.Class.newInstanceImpl(Native Method).
I happened to have the same kind of VerifyError while I was using String.isEmplty();. It seems you have same kind of problem as the message showing error in java.lang.Class
Thrown when the "verifier" detects that a class file, though well formed, contains some sort of internal inconsistency or security problem.
Here is official docs
Possible causes:
You might have imported something which is using different support v4/v7 library version.
You are targeting something from a higher SDK version. In that case, update your support repository and SDK build version.
Thanks everyone for your support and answers, may be your answers are right but in my case I used extra variables in one method while I was testing, so this exception appeared. Now I get rid of redundant things in my code and it start working. It may help others.
We recently introduced OAuth login in our app. This means using a WebView to authenticate the user, and an AsyncTask to do necessary REST calls afterwards.
Unfortunately, after introducing this login method, we're getting reports of the app force closing. This seems to be related to other AsyncTasks that are executed after the login, but the stack traces does unfortunately not tell us much:
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3100)
at android.view.View.performClick(View.java:3627)
at android.view.View$PerformClick.run(View.java:14329)
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:4511)
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:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
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:3095)
... 11 more
Caused by: java.lang.NoClassDefFoundError: android/os/AsyncTask
at com.foo.bar.TransmissionActivity.transmit(TransmissionActivity.java:44)
... 14 more
We managed to fix the error above by using RoboAsyncTask (from RoboGuice), instead of AsyncTask from the Android SDK, but we have other activities that use WebViews. WebView apparently uses AsyncTask somewhere in its call stack, and errors similar the one shown above (Caused by: java.lang.NoClassDefFoundError: android/os/AsyncTask) have started to show in our error logs.
The error happens on different devices, and different Android versions, with no apparent pattern. We have tried to reproduce the error ourselves, without any luck.
Any ideas?
It might be an issue with the build setup. (Build order of src/gen has been known to cause some issues, the libs folder for the compat library being called lib has caused some issues for me on new sdk versions).
To see if it is create a new project (in eclipse, since that's 100% android official). Add a webview and an asynctask and then do a diff on the project with your project. Ignoring src/gen/res. Hopefully you'll find that the src/gen are built in the wrong order or something like that.
~ Anders
I just released an update and got an exception report from the wild after someone updated a previously working application.
The same code works on my phone, the resource is a raw file and not dependent on device, local dependent or anything.
I had a similar thing happen before while developing the update, I cleaned the project and it resolved it.
However this doesn't seem to be a good solution as I cannot verify the fix, don't want to just shove a version out in case it fixes the issue.
Any advice as to cause or resolution would be massively appreciated!
Stack Trace below:
java.lang.RuntimeException: Unable to create service com.beltane.apppro.TickerService:
android.content.res.Resources$NotFoundException: Resource ID #0x7f040005 at
android.app.ActivityThread.handleCreateService(ActivityThread.java:2969) at
android.app.ActivityThread.access$3300(ActivityThread.java:125) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2087) 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
java.lang.reflect.Method.invoke(Method.java:521) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) at
dalvik.system.NativeStart.main(Native Method) Caused by:
android.content.res.Resources$NotFoundException: Resource ID #0x7f040005 at
android.content.res.Resources.getValue(Resources.java:892) at
android.content.res.Resources.openRawResourceFd(Resources.java:854) at
android.media.MediaPlayer.create(MediaPlayer.java:647) at
com.beltane.apppro.TickerService.onCreate(TickerService.java:42) at
android.app.ActivityThread.handleCreateService(ActivityThread.java:2959) ... 10 more
For anyone facing a similar problem my resolution as horrible as it is:
Prepare a new release deleting all intermediate generated files, doing a clean build and re-releasing.
I trapped all media player creation code in try catch blocks for resource not found exceptions and pop up a toast explaining to the user what has occurred and to contact for a resolution.
This is pretty nasty but given that this should never occur...
I haven't heard either way from the user that returned the crash report, I have had other good feedback since, I'll update if I hear further either way.
This question already has answers here:
Java.lang.verifyerror how do I fix or even find out the root cause?
(4 answers)
Closed 9 years ago.
Hello I get this error every time I'm trying to open an activity
java.lang.VerifyError: com.karriapps.smartsiddur.Saharit
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
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 java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Can someone direct me to a solution or a way to check where the problem is coming from
thanks
A VerifyError means your compiled bytecode is referring to something that Android cannot find. In this case, it would appear that you have a reference to a com.karriapps.smartsiddur.Saharit class that Android cannot find.
As CommonsWare mentioned, a VerifyError means that you're trying to reference a class that Dalvik isn't able to load.
It's possible that this class is missing.
It's also possible that you're trying to use framework methods for an API level greater than what's present on the device, and therefore the class is being rejected as invalid.
Try setting your compiler's build level to API Level 7, which corresponds to Android 2.1. (Don't forget to set your AndroidManfest.xml's targetSdkVersion to "7" as well.) This will cause any framework calls that don't exist to raise a compiler error.
You also might want to look at the lines above/below the stack trace you received to see if there's any additional information from the verifier indicating why verification failed.
I found an interesting case that has evidence in runtime. I use:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
So some of new Android 4 capabilities are not implenented in Android 2.3 like this one:
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Ok I can manage it so runtime will not execute it, simply:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
This works well but what about Exception handling?
} catch (NetworkOnMainThreadException nomte) {
// log this exception
} catch (SocketTimeoutException socketTimeoutException) {
// log this exception
}
NetworkOnMainThreadException is not implemented in Android 2.3 so when the class is loaded the exception java.lang.VerifyError occurs.
I ran across this problem today and as CommonsWare mentioned, the issue is that my compiled bytecode was referring to something that no longer existed. But what should you do about it?
Since I'm using Eclipse SDK the simple solution for me was to perform an Eclipse's Project → Clean to remove the pre-compiled byte code in my project that was causing the problem. The Project clean put simply allowed eclipse to perform a full fresh rebuild of my project after the clean.
So I'm trying to make an HTTPS connection with Android, using a client certificate to validate. I've imported this certificate into a BKS store, and inserted in my res/raw.
All good.
However, when I come to run, I get a constant NullPointerException.
For context, I have a Connection class, extending Application, and the basic constructor should just open the cert as an InputStream and hold it ready. When I come to make the connection, this will be used. As follows (abridged):
public class RCPHandshake2 extends Application {
InputStream in;
public RCPHandshake2(){
super.onCreate();
in = getResources().openRawResource(R.raw.test);
}
}
The build-up to this runs fine, however, when we get to there (line 36 in real version), the stack trace is like so:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.<company>.t1v2/com.<company>.t1v2.SplashAndText}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
at com.<company>.<component>.RCPHandshake2.<init>(RCPHandshake2.java:36)
at com.<company>.t1v2.SplashAndText.onCreate(SplashAndText.java:43)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
... 11 more
This seems unexpected. Has anyone come across similar before?
Eternal love and appreciation in exchange for any solutions/hints/tips/pointers from someone a bit more experienced with it that me!!
PS - Basically, even though I know the raw resource is there, and it appears in R.java, this seems to think it's unable to access it? Is this the case, or am I missing something blinding?
It seems you can't access resources from constructor, as the object has not been initilized yet. Try to call it later, when you really need this first time.
I had the same problem. Turned out that I used a wrong (empty) Context, so there actually were no resources to access via getResource() -> NullPointerException...
To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.