【问题标题】:Why does the program give "illegal start of type" error?为什么程序给出“非法类型开始”错误?
【发布时间】:2011-01-27 18:32:05
【问题描述】:

这里是相关代码sn-p:

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 ;

}

(Rand是这个方法所在的类名)

在编译时得到这个错误信息:

Rand.java:77: illegal start of type
        return countA ;
        ^

这里出了什么问题?这个错误信息是什么意思?

【问题讨论】:

    标签: java syntax return syntax-error


    【解决方案1】:

    您好,以下代码适用于 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) {
    

    【讨论】:

      【解决方案2】:

      在返回类型之前有一个额外的“{”。 您可能还想在 if 和 else 条件中使用 '==' 而不是 '='。

      【讨论】:

        【解决方案3】:

        return 语句之前的右大括号放错了位置。

        【讨论】:

        • 另外,如果 (x[l] = 0) 可能不是故意的,您的意思是 if (x[l] == 0) 吗?
        猜你喜欢
        • 2014-12-17
        • 1970-01-01
        • 2022-06-11
        • 2021-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多