有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法在我的Android应用程序中启动Chrome CustomTabsInt

我正在尝试在我的Android应用程序中使用Chrome自定义选项卡。我的MainActivity类扩展了AppCompatActivity。在onCreate中,我调用startCustomTabs。下面是代码:

private void startCustomTab(){
    CustomTabsIntent intent = new CustomTabsIntent.Builder().setToolbarColor(getResources().getColor(R.color.colorPrimary)).build();
    intent.launchUrl(this, Uri.parse("http://github.com/black-dragon/SaavnExtractor"));
}

应用程序一启动就会崩溃,出现以下错误:

11-16 10:55:38.561 30093-30093/com.nick.saavnextractor
E/AndroidRuntime: FATAL EXCEPTION: main
   Process: com.nick.saavnextractor, PID: 30093
   java.lang.NoSuchMethodError: No static method
startActivity(L安卓/app/Activity;L安卓/content/Intent;L安卓/os/Bundle;)V
in class L安卓/support/v4/app/ActivityCompat; or its super classes
(declaration of '安卓.support.v4.app.ActivityCompat' appears in
/data/data/com.nick.saavnextractor/files/instant-run/dex/slice-com.安卓.support-support-compat-25.0.0_15c83dd4ec129d2d74bfda2e34f6aeeb93d83fa1-classes.dex)
       at 安卓.support.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:262)
       at com.nick.saavnextractor.MainActivity.startCustomTab(MainActivity.java:325)
       at com.nick.saavnextractor.MainActivity.onCreate(MainActivity.java:111)
       at 安卓.app.Activity.performCreate(Activity.java:6311)
       at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
       at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
       at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2539)
       at 安卓.app.ActivityThread.access$900(ActivityThread.java:159)
       at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1384)
       at 安卓.os.Handler.dispatchMessage(Handler.java:102)
       at 安卓.os.Looper.loop(Looper.java:148)
       at 安卓.app.ActivityThread.main(ActivityThread.java:5507)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:616)

注意:如果我在一个新的应用程序中使用相同的方法执行相同的代码,那么自定义选项卡可以正常启动


共 (1) 个答案

  1. # 1 楼答案

    好的,这就是决议。我使用的是构建工具版本25.0.0,但我的SDK平台是24

    更新构建工具、平台工具和;SDK到同一版本,然后你就不会面临这个问题