Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: can not find symbol error in java (android studio)

  1. #1
    Junior Member
    Join Date
    Mar 2021
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default can not find symbol error in java (android studio)

    hi i am interested in develop AR app by Java in android studio and i wrote below codes from a book as title: "Learn ARCore - Fundamentals of Google ARCore" 2018 by Micheal Lanham.

    but in chapter 6 he wrote " add the following line:

    Frame frame = mSession.update(); "
    when Run , give me errors as "can not find symbol- symbol = mSession" once and i modify the codes a little and see same errors
    as :
    can not find symbol- symbol = frame (variable for Frame)

    i dont know problem rise from Update method because some times give me error as : " Update method has 2 arguments"

    mSession.update( , )

    i dont know anything about two arguments for update into parenthesis .
    please help me quickly because I searched many sites for solve my errors from 3 weeks to Now but I did not find any solution that solve my errors. specially about 2 arguments for Update method.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: can not find symbol error in java (android studio)

    can not find symbol- symbol = mSession
    That message says that the compiler can not find where the symbol mentioned in the message has been defined in scope where it is being used.
    Roughly, in scope means within the same pair of {}s

    It is hard to say more without seeing the full code. Be sure to wrap all posted code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2021
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: can not find symbol error in java (android studio)

    hi, you said that i must define mSession (variable) in first, before using this variable??

    --- Update ---

    /*
    * Copyright 2017 Google Inc. All Rights Reserved.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    * http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */

    package com.google.ar.core.examples.java.helloar;

    import android.opengl.GLES20;
    import android.opengl.GLSurfaceView;
    import android.os.Bundle;
    import android.support.design.widget.BaseTransientBottomB ar;
    import android.support.design.widget.Snackbar;
    import android.support.v4.media.session.IMediaSession;
    import android.support.v7.app.AppCompatActivity;
    import android.util.Log;
    import android.view.GestureDetector;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.WindowManager;
    import android.widget.Toast;
    import com.google.ar.core.Anchor;
    import com.google.ar.core.ArCoreApk;
    import com.google.ar.core.Camera;
    import com.google.ar.core.Config;
    import com.google.ar.core.Frame;
    import com.google.ar.core.HitResult;
    import com.google.ar.core.Plane;
    import com.google.ar.core.Point;
    import com.google.ar.core.Point.OrientationMode;
    import com.google.ar.core.PointCloud;
    import com.google.ar.core.Session;
    import com.google.ar.core.Trackable;
    import com.google.ar.core.TrackingState;
    import com.google.ar.core.examples.java.helloar.rendering .BackgroundRenderer;
    import com.google.ar.core.examples.java.helloar.rendering .ObjectRenderer;
    import com.google.ar.core.examples.java.helloar.rendering .ObjectRenderer.BlendMode;
    import com.google.ar.core.examples.java.helloar.rendering .PlaneRenderer;
    import com.google.ar.core.examples.java.helloar.rendering .PointCloudRenderer;
    import com.google.ar.core.exceptions.UnavailableApkTooOld Exception;
    import com.google.ar.core.exceptions.UnavailableArcoreNot InstalledException;
    import com.google.ar.core.exceptions.UnavailableSdkTooOld Exception;
    import com.google.ar.core.exceptions.UnavailableUserDecli nedInstallationException;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Observable;
    import java.util.Observer;
    import java.util.concurrent.ArrayBlockingQueue;
    import javax.microedition.khronos.egl.EGLConfig;
    import javax.microedition.khronos.opengles.GL10;

    /**
    * This is a simple example that shows how to create an augmented reality (AR) application using the
    * ARCore API. The application will display any detected planes and will allow the user to tap on a
    * plane to place a 3d model of the Android robot.
    */
    public class HelloArActivity extends AppCompatActivity implements GLSurfaceView.Renderer {
    private static final String TAG = HelloArActivity.class.getSimpleName();

    // Rendering. The Renderers are created here, and initialized when the GL surface is created.
    private GLSurfaceView surfaceView;

    private boolean installRequested;

    private int session;
    private GestureDetector gestureDetector;
    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();

    // Temporary matrix allocated here to reduce number of allocations for each frame.
    private final float[] anchorMatrix = new float[16];

    // Tap handling and UI.
    private final ArrayBlockingQueue<MotionEvent> queuedSingleTaps = new ArrayBlockingQueue<>(16);
    private final ArrayList<Anchor> anchors = new ArrayList<>();
    private Object UnavailableArcoreNotInstalledException;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    surfaceView = findViewById(R.id.surfaceview);
    displayRotationHelper = new DisplayRotationHelper(/*context=*/ this);

    // Set up tap listener.
    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);
    }
    });

    surfaceView.setOnTouchListener(
    new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    return gestureDetector.onTouchEvent(event);
    }
    });

    // Set up renderer.
    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 _CONTINUOUSLY);

    installRequested = false;
    }

    private void onLongPressDown(MotionEvent e) {
    anchors.clear();
    }

    @Override
    protected void onResume() {
    super.onResume();


    if (session = Integer.parseInt(null)) {
    Exception exception = null;
    String message = null;

    try {
    session = 0;
    int onDrawFrame = 60;
    Class<Session> frame = Session.class;

    frame = new session();
    } catch (Exception 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(thi s);
    return;
    }

    session = new Session(/* context= */ this);
    line 179 = } (UnavailableArcoreNotInstalledException) || (UnavailableUserDeclinedInstallationException) {
    message = "Please install ARCore";
    exception = e;
    }
    } catch (UnavailableApkTooOldException e) {
    message = "Please update ARCore";
    exception = e;
    } catch (UnavailableSdkTooOldException e) {
    message = "Please update this app";
    exception = e;
    } catch (Exception e) {
    message = "This device does not support AR";
    exception = e;
    }

    if (message != null) {
    showSnackbarMessage(message, true);
    Log.e(TAG, "Exception creating session", exception);
    return;
    }

    // Create default config and check if supported.
    Config config = new Config(session);
    if (!session.isSupported(config)) {
    showSnackbarMessage("This device does not support AR", true);
    }
    session.configure(config);
    }

    showLoadingMessage();
    // Note that order matters - see the note in onPause(), the reverse applies here.
    session.resume();
    surfaceView.onResume();
    displayRotationHelper.onResume();
    }

    @Override
    public void onPause() {
    super.onPause();
    if (session != null) {
    // Note that the order matters - GLSurfaceView is paused first so that it does not try
    // to query the session. If Session is paused before GLSurfaceView, GLSurfaceView may
    // still call session.update() and get a SessionPausedException.
    displayRotationHelper.onPause();
    surfaceView.onPause();
    session.pause();
    }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] results) {
    if (!CameraPermissionHelper.hasCameraPermission(this) ) {
    Toast.makeText(this, "Camera permission is needed to run this application", Toast.LENGTH_LONG)
    .show();
    if (!CameraPermissionHelper.shouldShowRequestPermissi onRationale(this)) {
    // Permission denied with checking "Do not ask again".
    CameraPermissionHelper.launchPermissionSettings(th is);
    }
    finish();
    }
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
    // Standard Android full-screen functionality.
    getWindow()
    .getDecorView()
    .setSystemUiVisibility(
    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_FULLSCREEN
    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    getWindow().addFlags(WindowManager.LayoutParams.FL AG_KEEP_SCREEN_ON);
    }
    }

    private void onSingleTap(MotionEvent e) {
    // Queue tap if there is space. Tap is lost if queue is full.
    queuedSingleTaps.offer(e);
    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    GLES20.glClearColor(0.1f, 0.1f, 0.1f, 1.0f);

    // Create the texture and pass it to ARCore session to be filled during update().
    backgroundRenderer.createOnGlThread(/*context=*/ this);

    // Prepare the other rendering objects.
    try {
    virtualObject.createOnGlThread(/*context=*/ this, "andy.obj", "andy.png");
    virtualObject.setMaterialProperties(0.0f, 3.5f, 1.0f, 6.0f);

    virtualObjectShadow.createOnGlThread(/*context=*/ this, "andy_shadow.obj", "andy_shadow.png");
    virtualObjectShadow.setBlendMode(BlendMode.Shadow) ;
    virtualObjectShadow.setMaterialProperties(1.0f, 0.0f, 0.0f, 1.0f);
    } catch (IOException e) {
    Log.e(TAG, "Failed to read obj file");
    }
    try {
    planeRenderer.createOnGlThread(/*context=*/ this, "trigrid.png");
    } catch (IOException e) {
    Log.e(TAG, "Failed to read plane texture");
    }
    pointCloud.createOnGlThread(/*context=*/ this);
    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
    displayRotationHelper.onSurfaceChanged(width, height);
    GLES20.glViewport(0, 0, width, height);
    }

    @Override
    public void onDrawFrame(GL10 gl) {
    // Clear screen to notify driver it should not load any pixels from previous frame.
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    if (session == null) {
    return;
    }
    // Notify ARCore session that the view size changed so that the perspective matrix and
    // the video background can be properly adjusted.
    displayRotationHelper.updateSessionIfNeeded(sessio n);

    try {
    session.setCameraTextureName(backgroundRenderer.ge tTextureId());

    // Obtain the current frame from ARSession. When the configuration is set to
    // UpdateMode.BLOCKING (it is by default), this will throttle the rendering to the
    // camera framerate.
    Frame frame = session.update();
    Camera camera = frame.getCamera();

    // Handle taps. Handling only one tap per frame, as taps are usually low frequency
    // compared to frame rate.

    MotionEvent tap = queuedSingleTaps.poll();
    if (tap != null && camera.getTrackingState() == TrackingState.TRACKING) {
    for (HitResult hit : frame.hitTest(tap)) {
    // Check if any plane was hit, and if it was hit inside the plane polygon
    Trackable trackable = hit.getTrackable();
    // Creates an anchor if a plane or an oriented point was hit.
    if ((trackable instanceof Plane && ((Plane) trackable).isPoseInPolygon(hit.getHitPose()))
    || (trackable instanceof Point
    && ((Point) trackable).getOrientationMode()
    == OrientationMode.ESTIMATED_SURFACE_NORMAL)) {
    // Hits are sorted by depth. Consider only closest hit on a plane or oriented point.
    // Cap the number of objects created. This avoids overloading both the
    // rendering system and ARCore.
    if (anchors.size() >= 20) {
    anchors.get(0).detach();
    anchors.remove(0);
    }
    // Adding an Anchor tells ARCore that it should track this position in
    // space. This anchor is created on the Plane to place the 3D model
    // in the correct position relative both to the world and to the plane.
    anchors.add(hit.createAnchor());
    break;
    }
    }
    }

    // Draw background.
    backgroundRenderer.draw(frame);

    // If not tracking, don't draw 3d objects.
    if (camera.getTrackingState() == TrackingState.PAUSED) {
    return;
    }

    // Get projection matrix.
    float[] projmtx = new float[16];
    camera.getProjectionMatrix(projmtx, 0, 0.1f, 100.0f);

    // Get camera matrix and draw.
    float[] viewmtx = new float[16];
    camera.getViewMatrix(viewmtx, 0);

    // Compute lighting from average intensity of the image.
    final float lightIntensity = frame.getLightEstimate().getPixelIntensity();

    // Visualize tracked points.
    PointCloud pointCloud = frame.acquirePointCloud();
    this.pointCloud.update(pointCloud);
    this.pointCloud.draw(viewmtx, projmtx);

    // Application is responsible for releasing the point cloud resources after
    // using it.
    pointCloud.release();

    // Check if we detected at least one plane. If so, hide the loading message.
    if (messageSnackbar != null) {
    for (Plane plane : session.getAllTrackables(Plane.class)) {
    if (plane.getType() == com.google.ar.core.Plane.Type.HORIZONTAL_UPWARD_FA CING
    && plane.getTrackingState() == TrackingState.TRACKING) {
    hideLoadingMessage();
    break;
    }
    }
    }

    // Visualize planes.
    planeRenderer.drawPlanes(
    session.getAllTrackables(Plane.class), camera.getDisplayOrientedPose(), projmtx);

    // Visualize anchors created by touch.
    float scaleFactor = 2.0f;
    for (Anchor anchor : anchors) {
    if (anchor.getTrackingState() != TrackingState.TRACKING) {
    continue;
    }
    // Get the current pose of an Anchor in world space. The Anchor pose is updated
    // during calls to session.update() as ARCore refines its estimate of the world.
    anchor.getPose().toMatrix(anchorMatrix, 0);

    // Update and draw the model and its shadow.
    virtualObject.updateModelMatrix(anchorMatrix, scaleFactor);
    virtualObjectShadow.updateModelMatrix(anchorMatrix , scaleFactor);
    virtualObject.draw(viewmtx, projmtx, lightIntensity);
    virtualObjectShadow.draw(viewmtx, projmtx, lightIntensity);
    }

    } catch (Throwable t) {
    // Avoid crashing the application due to unhandled exceptions.
    Log.e(TAG, "Exception on the OpenGL thread", t);
    }
    }

    private void showSnackbarMessage(String message, boolean finishOnDismiss) {
    messageSnackbar =
    Snackbar.make(
    HelloArActivity.this.findViewById(android.R.id.con tent),
    message,
    Snackbar.LENGTH_INDEFINITE);
    messageSnackbar.getView().setBackgroundColor(0xbf3 23232);
    if (finishOnDismiss) {
    messageSnackbar.setAction(
    "Dismiss",
    new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    messageSnackbar.dismiss();
    }
    });
    messageSnackbar.addCallback(
    new BaseTransientBottomBar.BaseCallback<Snackbar>() {
    @Override
    public void onDismissed(Snackbar transientBottomBar, int event) {
    super.onDismissed(transientBottomBar, event);
    finish();
    }
    });
    }
    messageSnackbar.show();
    }

    private void showLoadingMessage() {
    runOnUiThread(
    new Runnable() {
    @Override
    public void run() {
    showSnackbarMessage("Searching for surfaces...", false);
    }
    });
    }

    private void hideLoadingMessage() {
    runOnUiThread(
    new Runnable() {
    @Override
    public void run() {
    if (messageSnackbar != null) {
    messageSnackbar.dismiss();
    }
    messageSnackbar = null;
    }
    });
    }

    above is all of my codes. but in line : 127 , android studio give error message as below:
    error: not a statement
    } (UnavailableArcoreNotInstalledException) || (UnavailableUserDeclinedInstallationException) {
    above codes are from the book as: "Learn ARCore - Fundamentals
    of Google ARCore" examples of chapter 6 - HelloArActivity.java:
    Last edited by hoseinjava; March 14th, 2021 at 03:00 AM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: can not find symbol error in java (android studio)

    } (UnavailableArcoreNotInstalledException) || (UnavailableUserDeclinedInstallationException) {
    That looks like it should be part of a catch statement:
       try {
        ....
       }catch (UnavailableArcoreNotInstalledException) || (UnavailableUserDeclinedInstallationException) {
        ...
       } ...

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Start.java:22: error: cannot find symbol
    By SPatel in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 25th, 2013, 01:20 PM
  2. Cannot find symbol error in my java code
    By haliza hadi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 20th, 2013, 07:20 PM
  3. [SOLVED] cannot find symbol error
    By Topflyt in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 5th, 2011, 08:57 AM
  4. error :cannot find symbol
    By iswan in forum AWT / Java Swing
    Replies: 1
    Last Post: October 1st, 2011, 08:26 AM
  5. cannot find symbol Error
    By bananasplitkids in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 9th, 2010, 02:36 AM

Tags for this Thread