Java 为什么该计划会给出;“类型”的非法启动;错误?
以下是相关的代码片段:Java 为什么该计划会给出;“类型”的非法启动;错误?,java,syntax,return,syntax-error,Java,Syntax,Return,Syntax Error,以下是相关的代码片段: public static Rand searchCount (int[] x) { int a ; int b ; int c ; int d ; int f ; int g ; int h ; int i ; int j ; Rand countA = new Rand () ; for (int l= 0; l<x.length; l++)
public static Rand searchCount (int[] x)
{
int a ;
int b ;
int c ;
int d ;
int f ;
int g ;
int h ;
int i ;
int j ;
Rand countA = new Rand () ;
for (int l= 0; l<x.length; l++)
{
if (x[l] = 0)
a++ ;
else if (x[l] = 1)
b++ ;
}
}
return countA ;
}
这里怎么了?这个错误消息是什么意思 在
return
语句之前有一个放错位置的右大括号。在return类型之前有一个额外的“{”。
您可能还希望在if和else条件下使用“==”而不是“=”。hi以下代码适用于android中的AR应用程序。代码给出错误消息: 错误:类型catch的非法开始 在“catch”语句之前,我检查了大量代码,以确定右大括号是否放错位置。还有分号。那么为什么java会给出上述错误?请检查我的代码。也许我检查错了
public class HelloArActivity<exception> extends
AppCompatActivity implements GLSurfaceView.Renderer {
private static final String TAG =
HelloArActivity.class.getSimpleName();
private GLSurfaceView surfaceView;
private boolean installRequested;
private int session;
Set up tap listener.
private GestureDetector gestureDetector = new
GestureDetector(
this,
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
onSingleTap(e);
return true;
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
onLongPressDown(e);
}
});
private Snackbar messageSnackbar;
private DisplayRotationHelper displayRotationHelper;
private final BackgroundRenderer backgroundRenderer =
new BackgroundRenderer();
private final ObjectRenderer virtualObject = new
ObjectRenderer();
private final ObjectRenderer virtualObjectShadow = new
ObjectRenderer();
private final PlaneRenderer planeRenderer = new
PlaneRenderer();
private final PointCloudRenderer pointCloud = new
PointCloudRenderer();
private final float[] anchorMatrix = new float[16];
private final ArrayBlockingQueue<MotionEvent>
queuedSingleTaps = new ArrayBlockingQueue<>(16);
private final ArrayList<Anchor> anchors = new
ArrayList<>();
private Object UnavailableArcoreNotInstalledException;
private Object
UnavailableUserDeclinedInstallationException;
@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
surfaceView = findViewById(R.id.surfaceview);
displayRotationHelper = new
DisplayRotationHelper(/*context=*/ this);
surfaceView.setOnTouchListener(
new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
surfaceView.setPreserveEGLContextOnPause(true);
surfaceView.setEGLContextClientVersion(2);
surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); //
Alpha used for plane blending.
surfaceView.setRenderer(this);
surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUoSLY);
installRequested = false;
}
private void onLongPressDown(MotionEvent e) {
anchors.clear();
}
@Override
protected void onResume() {
super.onResume();
installRequested = false;
}
private void onLongPressDown(MotionEvent e) {
anchors.clear();
}
@Override
protected void onResume() {
super.onResume();
Exception exception;
if (session == Integer.parseInt(null)) {
exception = null;
String message = null;
try {
session = 0;
int onDrawFrame = 60;
Class<Session> frame = new session();
} catch (IOException e) {
e.printStackTrace();
}
switch (ArCoreApk.getInstance().requestInstall(this, !installRequested)) {
case INSTALL_REQUESTED:
installRequested = true;
return;
case INSTALLED:
break;
}
// ARCore requires camera permissions to operate. If we did not yet obtain runtime
// permission on Android M and above, now is a good time to ask the user for it.
if (!CameraPermissionHelper.hasCameraPermission(this)) {
CameraPermissionHelper.requestCameraPermission(this);
return;
}
session = new Session(/* context= */ this);
}
final UnavailableUserDeclinedInstallationException unavailableUserDeclinedInstallationException = (com.google.ar.core.exceptions.UnavailableUserDeclinedInstallationException) UnavailableUserDeclinedInstallationException;
{
message = "Please install ARCore" | (UnavailableArcoreNotInstalledException);
exception = e;
}
final Exception e = new
ThreadLocal<UnavailableApkTooOldException>();
message = "Please update ARCore";
}
catch(IOError) {
公共类活动扩展
AppCompatActivity实现GLSurfaceView.Renderer{
私有静态最终字符串标记=
HelloArActivity.class.getSimpleName();
私人GLSURFACHEVIEW SURFACHEVIEW;
要求提供私人服务;
非公开会议;
设置tap侦听器。
私人手势检测器手势检测器=新建
手势检测器(
这
新的GestureDetector.SimpleOnGestureListener(){
@凌驾
公共布尔onSingleTapUp(运动事件e){
onSingleTap(e);
返回true;
}
@凌驾
公共布尔onDown(运动事件e){
返回true;
}
@凌驾
公开无效在线新闻(运动事件e){
仅长按(e);
}
});
私有Snackbar消息Snackbar;
私有显示RotationHelper显示RotationHelper;
私人最终背景渲染器背景渲染器=
新背景渲染器();
私有最终ObjectRenderer virtualObject=new
ObjectRenderer();
私有最终ObjectRenderer virtualObjectShadow=新建
ObjectRenderer();
专用最终平面渲染器平面渲染器=新建
平面渲染器();
私有最终PointCloudRenderer pointCloud=新建
PointCloudRenderer();
私人最终浮动[]主播矩阵=新浮动[16];
专用最终ArrayBlockingQueue
queuedSingleTaps=新的ArrayBlockingQueue(16);
私有最终ArrayList锚点=新建
ArrayList();
私有对象不可用ArcoreNotInstalledException;
私有对象
UnavailableUserDeclinedInstallationException;
@SuppressLint(“ClickableViewAccessibility”)
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
surfaceView=findViewById(R.id.surfaceView);
displayRotationHelper=新建
DisplayRotationHelper(/*上下文=*/this);
surfaceView.setOnTouchListener(
新视图。OnTouchListener(){
@凌驾
公共布尔onTouch(视图v,运动事件){
返回gestureDetector.onTouchEvent(事件);
}
});
surfaceView.setPreserveEGLContextOnPause(true);
surfaceView.setEGLContextClientVersion(2);
surfaceView.setEGLConfigChooser(8,8,8,8,16,0);//
用于平面混合的Alpha。
surfaceView.setRenderer(此);
surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_连续);
installrequest=false;
}
仅限私人无效长按(运动事件e){
锚。清除();
}
@凌驾
受保护的void onResume(){
super.onResume();
installrequest=false;
}
仅限私人无效长按(运动事件e){
锚。清除();
}
@凌驾
受保护的void onResume(){
super.onResume();
例外情况;
if(session==Integer.parseInt(null)){
异常=空;
字符串消息=null;
试一试{
会话=0;
int onDrawFrame=60;
类框架=新会话();
}捕获(IOE异常){
e、 printStackTrace();
}
开关(ArCoreApk.getInstance().requestInstall(this,!installRequested)){
要求安装的案例:
installrequest=true;
返回;
已安装的机箱:
打破
}
//ARCore需要摄像头权限才能操作。如果我们尚未获得运行时
//安卓M及以上版本的权限,现在是向用户申请的好时机。
如果(!CameraPermissionHelper.hasCameraPermission(此)){
CameraPermissionHelper.requestCameraPermission(此);
返回;
}
会话=新会话(/*context=*/this);
}
最终不可用UserDeclinedInstallationException不可用UserDeclinedInstallationException=(com.google.ar.core.exceptions.UnavailableUserDeclinedInstallationException)不可用UserDeclinedInstallationException;
{
message=“请安装ARCore”|(不可用ArcoreNotInstalledException);
例外=e;
}
最终例外情况e=新
ThreadLocal();
message=“请更新ARCore”;
}
捕获(IOError){
此外,如果(x[l]=0)可能不是预期的,您的意思是如果(x[l]=0)?
public class HelloArActivity<exception> extends
AppCompatActivity implements GLSurfaceView.Renderer {
private static final String TAG =
HelloArActivity.class.getSimpleName();
private GLSurfaceView surfaceView;
private boolean installRequested;
private int session;
Set up tap listener.
private GestureDetector gestureDetector = new
GestureDetector(
this,
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
onSingleTap(e);
return true;
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
onLongPressDown(e);
}
});
private Snackbar messageSnackbar;
private DisplayRotationHelper displayRotationHelper;
private final BackgroundRenderer backgroundRenderer =
new BackgroundRenderer();
private final ObjectRenderer virtualObject = new
ObjectRenderer();
private final ObjectRenderer virtualObjectShadow = new
ObjectRenderer();
private final PlaneRenderer planeRenderer = new
PlaneRenderer();
private final PointCloudRenderer pointCloud = new
PointCloudRenderer();
private final float[] anchorMatrix = new float[16];
private final ArrayBlockingQueue<MotionEvent>
queuedSingleTaps = new ArrayBlockingQueue<>(16);
private final ArrayList<Anchor> anchors = new
ArrayList<>();
private Object UnavailableArcoreNotInstalledException;
private Object
UnavailableUserDeclinedInstallationException;
@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
surfaceView = findViewById(R.id.surfaceview);
displayRotationHelper = new
DisplayRotationHelper(/*context=*/ this);
surfaceView.setOnTouchListener(
new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
surfaceView.setPreserveEGLContextOnPause(true);
surfaceView.setEGLContextClientVersion(2);
surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); //
Alpha used for plane blending.
surfaceView.setRenderer(this);
surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUoSLY);
installRequested = false;
}
private void onLongPressDown(MotionEvent e) {
anchors.clear();
}
@Override
protected void onResume() {
super.onResume();
installRequested = false;
}
private void onLongPressDown(MotionEvent e) {
anchors.clear();
}
@Override
protected void onResume() {
super.onResume();
Exception exception;
if (session == Integer.parseInt(null)) {
exception = null;
String message = null;
try {
session = 0;
int onDrawFrame = 60;
Class<Session> frame = new session();
} catch (IOException e) {
e.printStackTrace();
}
switch (ArCoreApk.getInstance().requestInstall(this, !installRequested)) {
case INSTALL_REQUESTED:
installRequested = true;
return;
case INSTALLED:
break;
}
// ARCore requires camera permissions to operate. If we did not yet obtain runtime
// permission on Android M and above, now is a good time to ask the user for it.
if (!CameraPermissionHelper.hasCameraPermission(this)) {
CameraPermissionHelper.requestCameraPermission(this);
return;
}
session = new Session(/* context= */ this);
}
final UnavailableUserDeclinedInstallationException unavailableUserDeclinedInstallationException = (com.google.ar.core.exceptions.UnavailableUserDeclinedInstallationException) UnavailableUserDeclinedInstallationException;
{
message = "Please install ARCore" | (UnavailableArcoreNotInstalledException);
exception = e;
}
final Exception e = new
ThreadLocal<UnavailableApkTooOldException>();
message = "Please update ARCore";
}
catch(IOError) {