android - 空对象引用上的“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);
}
但它仍然无法正常工作,有人可以帮我解决这个问题吗?
解决方案
推荐阅读
- istio - Istio,使用 mTLS 和现有证书的自定义出口
- tomcat - Tomcat访问日志中奇怪的服务器主机名
- azure - 防止盗版我的 Azure VMI 解决方案软件的程序检查
- c - 如何在C中接收用户的三个输入
- winforms - powershell winforms函数输出到文本框
- python - matplotlib 2.0.2 之后的极坐标图问题
- node.js - 如何从链接/子函数(子函数到父函数)返回布尔值?节点
- php - 在自定义主题上获取 Woocommerce 产品
- php - 无法连接到 mssql 服务器或 sqlsrv 未显示在 phpinfo 上
- javascript - 数组解构 - 意外行为