E Caused by: java.lang.reflect.InvocationTargetException E at java.lang.reflect.Constructor.newInstance0(Native Method) E at java.lang.reflect.Constructor.newInstance(Constructor.java:343) E at android.view.LayoutInflater.createView(LayoutInflater.java:658) E at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801) E at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) E at android.view.LayoutInflater.rInflate(LayoutInflater.java:874) E at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835) E at android.view.LayoutInflater.inflate(LayoutInflater.java:515) E at android.view.LayoutInflater.inflate(LayoutInflater.java:423) E at android.view.LayoutInflater.inflate(LayoutInflater.java:374) E at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:498) E at com.android.internal.policy.HwPhoneWindow.setContentView(HwPhoneWindow.java:342) E at android.app.Activity.setContentView(Activity.java:2941) E at xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx E at android.app.Activity.performCreate(Activity.java:7458) E at android.app.Activity.performCreate(Activity.java:7448) E at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1286) E at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3409) E at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614) E at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86) E at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) E at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) E at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199) E at android.os.Handler.dispatchMessage(Handler.java:112) E at android.os.Looper.loop(Looper.java:216) E at android.app.ActivityThread.main(ActivityThread.java:7625) E at java.lang.reflect.Method.invoke(Native Method) E at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) E at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) E Caused by: java.lang.NoSuchMethodError: No virtual method addOnTabSelectedListener(Lcom/google/android/material/tabs/TabLayout$OnTabSelectedListener;)V in class Lcom/google/android/material/tabs/TabLayout; or its super classes (declaration of 'com.google.android.material.tabs.TabLayout' appears in /data/app/xxxxxx-WbxmUkjqMEjNknQppPqeWw==/base.apk!classes2.dex)
public class TestMethodSameName { public static void foo(int i) { System.out.println("TestMethodSameName.foo:(I)V"); } public static int foo(int i) { System.out.println("TestMethodSameName.foo:(I)I"); return i; } public static void main(String[] args) { foo(123); // foo:(I)V foo(456); // foo:(I)I } }
但是如果你使用使用javac和javap命令查看方法签名时你会发现
1 2 3 4 5 6 7 8 9 10 11 12 13
javac TestMethodSameName.java javap -s -p TestMethodSameName.class Compiled from "TestMethodSameName.java" public class TestMethodSameName { public TestMethodSameName(); descriptor: ()V
public static int foo(int); descriptor: (I)I
public static void main(java.lang.String[]); descriptor: ([Ljava/lang/String;)V }