为什么程序会出现“非法启动类型”错误?

时间:2010-03-15 16:34:56

标签: 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++) 
        {
            if (x[l] = 0) 
            a++ ;
            else if (x[l] = 1) 
            b++ ;
        }
    }
    return countA ;

}

(Rand是此方法所在类的名称)

编译时会收到以下错误消息:

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

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

3 个答案:

答案 0 :(得分:20)

return声明之前你有一个错位的右括号。

答案 1 :(得分:1)

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

答案 2 :(得分:0)

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