首页 > 解决方案 > 空对象引用上的“Session.getConfig()”

问题描述

我是 Android 开发人员的新手,我正在尝试使用 ARCore 自己构建一个简单的应用程序。目前我很难使用深度功能。在我的情况下,用户按下按钮将激活 check_depth_support 功能,这就是 check_depth_support 功能:

public void check_depth_support() {
    Config config = session.getConfig();
    boolean isDepthSupported = session.isDepthModeSupported(Config.DepthMode.AUTOMATIC);

    if (isDepthSupported)
    {
        config.setDepthMode(Config.DepthMode.AUTOMATIC);
        checked = true;
    }
    else
    {
        Toast.makeText(getApplicationContext(),"Depth not support on this devices",Toast.LENGTH_SHORT);
        checked = false;
    }
    session.configure(config);
}

当我按下按钮时,我收到一个错误:“尝试在空对象引用上调用虚拟方法'com.google.ar.core.Config com.google.ar.core.Session.getConfig()'”我' m 遵循本指南 我也尝试遵循本指南,将上面的代码转换为:

    private Session session; // Global

public void check_depth_support() {
try {
    session = new Session(this);
} catch (UnavailableArcoreNotInstalledException e) {
    e.printStackTrace();
} catch (UnavailableApkTooOldException e) {
    e.printStackTrace();
} catch (UnavailableSdkTooOldException e) {
    e.printStackTrace();
} catch (UnavailableDeviceNotCompatibleException e) {
    e.printStackTrace();
}
Config config = new Config(session);
boolean isDepthSupported = session.isDepthModeSupported(Config.DepthMode.AUTOMATIC);
if (isDepthSupported)
{
    config.setDepthMode(Config.DepthMode.AUTOMATIC);
    checked = true;
}
else
{
    Toast.makeText(getApplicationContext(),"Depth not support on this devices",Toast.LENGTH_SHORT);
    checked = false;
}
session.configure(config);
}

但它仍然无法正常工作,有人可以帮我解决这个问题吗?

标签: androidarcore

解决方案


推荐阅读