0

I am creating a thread in the following manner:

GraphThread  thread = new GraphThread(context, handler, string);

Note that handler is a static Handler object, which could be causing the problem. I have been getting an error exactly at this line of code. But, the error does not appear in other virtual devices such as API 23 and 25, as well as my physical device(Nougat).

I did try to set up a try{}catch block, but it is not catching the exception, which is unusual. The stack trace is as follows:

java.lang.IllegalStateException: Could not execute method for android:onClick
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
        at android.view.View.performClick(View.java:4438)
        at android.view.View$PerformClick.run(View.java:18422)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        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:515)
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick**(AppCompatViewInflater.java:384)
        at android.view.View.performClick(View.java:4438) 
        at android.view.View$PerformClick.run(View.java:18422) 
        at android.os.Handler.handleCallback(Handler.java:733) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:136) 
        at android.app.ActivityThread.main(ActivityThread.java:5017) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
        at dalvik.system.NativeStart.main(Native Method) 
     Caused by: java.lang.VerifyError: noodlesoup/solver/GraphThready
        at noodlesoup.solver.MainActivity.clikButton(MainActivity.java:4985)

It comes down to java.lang Verifyerror that I believe is created by passing the parameter static Handler. I don't know why this is happening in API 19 virtual device and not in the other virtual device which I have tested.

Any ideas or suggestions?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
i_o
  • 777
  • 9
  • 25
  • is noodlesoup/solver/GraphThready package part of your application or its a dependencie? could you please post the method called into your MainActivity(clikButton) – Anis BEN NSIR Sep 21 '18 at 15:40
  • is a thread class in my application. Not, a dependency. However, I used several libraries in order to create graphs inside this thread. @AnisBENNSIR – i_o Sep 21 '18 at 15:41
  • So, basically the VerifyError is thrown if the compiled version is different between runtime version, this can be du to some gradle exclude transitive dependencies... or corrupted jar/aar dependencies... Could you please add your gradle? – Anis BEN NSIR Sep 21 '18 at 15:45
  • Why would it have to do with a transitive dependency if the Thread object is not even created. The constructor is not even called. Once the thread object is created, it is when the code starts calling 3rd party libraries for computations. @AnisBENNSIR – i_o Sep 21 '18 at 15:54
  • Ok, you thread class has dependencies of other classes from library, the class loader may load them too... Could you try to comment the code using external library and check if the issue is due to external dependencies or not, if so, you can enable dependencies one bye one to find the source of this error... – Anis BEN NSIR Sep 21 '18 at 16:02

1 Answers1

0

After reading through many posts, I came across the following idea: The void run method in my Thread class was too complex. There were too many variables defined inside the run method; There were too many decisions to make in a method that contained over 4000 lines of code. The post and answer that gave me the idea was the following VerifyError - Verifier rejected class

So, all I had to do was create extra methods within the Thread class were the sum of their work was equal to the 4000+ lines of code inside the run method.

In the end the Thread class structure looks like this, and it compiles without no more verify errors:

public class GraphThready extends Thread{
//...
GraphThready(){
//...
}

public void run(){

super.run();

if(some condition)
methodToDoTask1();

if(another condition)
methodToDoTask2();

if(a different condition)
methodToDoTask3();

}

private void methodToDoTask1(){

}


private void methodToDoTask2(){

}

private void methodToDoTask3(){

}

}
i_o
  • 777
  • 9
  • 25