Skip to content

报错,求指教 #64

Description

@liguangze

image
你好我在基类上写上了,为什么报错呢
ParameterizedType type = (ParameterizedType) getClass().getGenericSuperclass();
Class cls = (Class) type.getActualTypeArguments()[0];
try {
Method inflate = cls.getDeclaredMethod("inflate", LayoutInflater.class);
viewBinding = (T) inflate.invoke(null, getLayoutInflater());
setContentView(viewBinding.getRoot());
} catch (Exception e) {
e.printStackTrace();
}

2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: java.lang.NoSuchMethodException: inflate [class android.view.LayoutInflater]
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at java.lang.Class.getMethod(Class.java:624)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at java.lang.Class.getDeclaredMethod(Class.java:586)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at com.akax.haofangfa.pen.base.BaseActivity.onCreate(BaseActivity.java:68)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at com.akax.haofangfa.pen.ui.MainActivity.onCreate(MainActivity.java:23)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.Activity.performCreate(Activity.java:6279)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2499)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2606)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.ActivityThread.-wrap11(ActivityThread.java)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1444)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.os.Looper.loop(Looper.java:148)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5647)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at java.lang.reflect.Method.invoke(Native Method)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions