5

我正在使用 Android 做一些工作,并想用它来测试 Retrolambda。但不幸的是,我遇到了一个问题。

我有一个以 Consumer 作为参数的 Dialog 类:

public class AuthDialog extends Dialog {

    public static final String SERVER_URL = "http://cohhgas.ddns.net/auth";
    private Consumer<UserCredentials> onSuccess;

    public AuthDialog(Context context, Consumer<UserCredentials> onSuccess) {
        super(context);
        this.onSuccess = onSuccess;
    }
}

我有一个使用它的活动:

public class MainActivity extends AppCompatActivity {

    public static final String CREDENTIALS = "sharedPrefsCredentials";

    GiveAway giveAway;
    SharedPreferences sharedpreferences;

    public MainActivity() {
        EventBus.getDefault().register(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final AuthDialog auth_dialog;
        auth_dialog = new AuthDialog(MainActivity.this, userCredentials -> Log.d("cool", "works"));
        auth_dialog.show();

        TextView textView = new TextView(MainActivity.this);
        textView.setOnClickListener((view) -> {

        });
    }
}

但是启动 AuthDialog 的行向我抛出了异常!这是日志:

Process: io.github.hajto.cohhcarnagegiveawayclient, PID: 3687
                  java.lang.NoClassDefFoundError: io.github.hajto.cohhcarnagegiveawayclient.activites.MainActivity$$Lambda$1
                      at io.github.hajto.cohhcarnagegiveawayclient.activites.MainActivity.onCreate(MainActivity.java:56)
                      at android.app.Activity.performCreate(Activity.java:6013)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466)
                      at android.app.ActivityThread.access$1200(ActivityThread.java:152)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:135)
                      at android.app.ActivityThread.main(ActivityThread.java:5538)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:372)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

最有趣的是,如果我删除该行,onClick 侦听器将不会与下一个 lambda 争论。

4

0 回答 0