0

I am developing an app for recognizing images and I have got a sample code for working.. In my code when I executed there is error is showing... I am giving my code below... and the logcat can anyone help me..

logcat

07-29 02:48:30.533: E/AndroidRuntime(1332): FATAL EXCEPTION: main
07-29 02:48:30.533: E/AndroidRuntime(1332): Process: com.example.therefore, PID: 1332
07-29 02:48:30.533: E/AndroidRuntime(1332): java.lang.NoClassDefFoundError: com.example.therefore.ARFromCraftARActivity
07-29 02:48:30.533: E/AndroidRuntime(1332):     at com.example.therefore.LaunchersActivity.onClick(LaunchersActivity.java:99)
07-29 02:48:30.533: E/AndroidRuntime(1332):     at android.view.View.performClick(View.java:4438)
07-29 02:48:30.533: E/AndroidRuntime(1332):     at android.view.View$PerformClick.run(View.java:18422)
07-29 02:48:30.533: E/AndroidRuntime(1332):     at android.os.Handler.handleCallback(Handler.java:733)
07-29 02:48:30.533: E/AndroidRuntime(1332):     at android.os.Handler.dispatchMessage(Handler.java:95)
07-29 02:48:30.533: E/AndroidRuntime(1332):     at android.os.Looper.loop(Looper.java:136)
07-29 02:48:30.533: E/AndroidRuntime(1332):     at android.app.ActivityThread.main(ActivityThread.java:5017)
07-29 02:48:30.533: E/AndroidRuntime(1332):     at java.lang.reflect.Method.invokeNative(Native Method)
07-29 02:48:30.533: E/AndroidRuntime(1332):     at java.lang.reflect.Method.invoke(Method.java:515)
07-29 02:48:30.533: E/AndroidRuntime(1332):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-29 02:48:30.533: E/AndroidRuntime(1332):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-29 02:48:30.533: E/AndroidRuntime(1332):     at dalvik.system.NativeStart.main(Native Method)

LauncherActivity

public class LaunchersActivity extends Activity implements OnClickListener {

    // Howto links
    private TextView mHowToLink;
    private LinearLayout mAboutArProgrammatically;
    private LinearLayout mAboutArFromCraftAR;
    private LinearLayout mAboutRecognitionOnly;

    // Launch example links
    private LinearLayout mArProgrammatically;
    private LinearLayout mArFromCraftAR;
    private LinearLayout mRecognitionOnly;

    // Bottom links
    private ImageButton mButtonCatchoom;
    private Button mButtonSignUp;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_launchers);

        // Setup howto links
        mHowToLink = (TextView)findViewById(R.id.howto_link);
        mHowToLink.setClickable(true);
        mHowToLink.setOnClickListener(this);
        mAboutArProgrammatically = (LinearLayout)findViewById(R.id.howto_link_ar_programmatically);
        mAboutArProgrammatically.setClickable(true);
        mAboutArProgrammatically.setOnClickListener(this);
        mAboutArFromCraftAR = (LinearLayout)findViewById(R.id.howto_link_ar_from_craftar);
        mAboutArFromCraftAR.setClickable(true);
        mAboutArFromCraftAR.setOnClickListener(this);
        mAboutRecognitionOnly = (LinearLayout)findViewById(R.id.howto_link_recognition_only);
        mAboutRecognitionOnly.setClickable(true);
        mAboutRecognitionOnly.setOnClickListener(this);

        // Setup example links
        mArProgrammatically = (LinearLayout)findViewById(R.id.play_ar_programmatically);
        mArProgrammatically.setClickable(true);
        mArProgrammatically.setOnClickListener(this);
        mArFromCraftAR = (LinearLayout)findViewById(R.id.play_ar_from_craftar);
        mArFromCraftAR.setClickable(true);
        mArFromCraftAR.setOnClickListener(this);
        mRecognitionOnly = (LinearLayout)findViewById(R.id.play_recognition_only);
        mRecognitionOnly.setClickable(true);
        mRecognitionOnly.setOnClickListener(this);


        // Setup bottom Links
        mButtonCatchoom = (ImageButton)findViewById(R.id.imageButton_logo);
        mButtonCatchoom.setOnClickListener(this);
        mButtonSignUp = (Button)findViewById(R.id.button_signUp);
        mButtonSignUp.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        // Clicked on title or howto links
        Intent launchHowto = null;
        if (v == mHowToLink) {
            launchHowto = new Intent(this, HowToActivity.class);
            launchHowto.putExtra(HowToActivity.HOWTO_LAYOUT_EXTRA, R.layout.activity_howto);
        } else if (v == mAboutArProgrammatically) {
            launchHowto = new Intent(this, HowToActivity.class);
            launchHowto.putExtra(HowToActivity.HOWTO_LAYOUT_EXTRA, R.layout.activity_howto_ar_programmatically);
        } else if (v == mAboutArFromCraftAR) {
            launchHowto = new Intent(this, HowToActivity.class);
            launchHowto.putExtra(HowToActivity.HOWTO_LAYOUT_EXTRA, R.layout.activity_howto_ar_from_craftar);
        } else if (v == mAboutRecognitionOnly) {
            launchHowto = new Intent(this, HowToActivity.class);
            launchHowto.putExtra(HowToActivity.HOWTO_LAYOUT_EXTRA, R.layout.activity_howto_recognition_only);
        }
        if (launchHowto != null) {
            startActivity(launchHowto);
            return;
        }

        // Clicked on play links
        Intent playExampleIntent = null;
        if (v == mArProgrammatically) {
            playExampleIntent = new Intent(this, ARProgrammaticallyActivity.class);
        } else if (v == mArFromCraftAR) {
            playExampleIntent = new Intent(this, ARFromCraftARActivity.class);
        } else if (v == mRecognitionOnly) {
            playExampleIntent = new Intent(this, RecognitionOnlyActivity.class);

        }
        if (playExampleIntent != null) 
        {
            startActivity(playExampleIntent);
            return;
        }


        // Clicked on bottom links
        if (v == mButtonCatchoom || v == mButtonSignUp) {
            // mButtonCatchoom
            String url = "http://catchoom.com/product/?utm_source=CraftARExamplesApp&utm_medium=Android&utm_campaign=HelpWithAPI";
            if (v == mButtonSignUp) {
                url = "https://crs.catchoom.com/try-free?utm_source=CraftARExamplesApp&utm_medium=Android&utm_campaign=HelpWithAPI";
            }

            Intent launchWebView = new Intent(this, WebActivity.class);
            launchWebView.putExtra(WebActivity.WEB_ACTIVITY_URL, url);
            startActivity(launchWebView);           
            return;
        }
    }

}

ARFromCraftActivity

public class ARFromCraftARActivity extends CatchoomActivity implements CatchoomResponseHandler,CatchoomImageHandler {

    private final String TAG = "CatchoomTrackingExample";
    private final static String COLLECTION_TOKEN="craftarexamples1";

    private View mScanningLayout;

    CatchoomCamera mCamera;

    CatchoomCloudRecognition mCloudRecognition;
    CatchoomTracking mCatchoomTracking;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onPostCreate() {

        View mainLayout= (View) getLayoutInflater().inflate(R.layout.activity_ar_programmatically_ar_from_craftar, null);
        CatchoomCameraView cameraView = (CatchoomCameraView) mainLayout.findViewById(R.id.camera_preview);
        super.setCameraView(cameraView);
        setContentView(mainLayout);

        mScanningLayout = findViewById(R.id.layout_scanning);


        //Initialize the SDK. From this SDK, you will be able to retrieve the necessary modules to use the SDK (camera, tracking, and cloud-recgnition)
        CatchoomSDK.init(getApplicationContext(),this);

        //Get the camera to be able to do single-shot (if you just use finder-mode, this is not necessary)
        mCamera= CatchoomSDK.getCamera();
        mCamera.setImageHandler(this); //Tell the camera who will receive the image after takePicture()

        //Setup the finder-mode: Note! PRESERVE THE ORDER OF THIS CALLS
        mCloudRecognition= CatchoomSDK.getCloudRecognition();//Obtain the cloud recognition module
        mCloudRecognition.setResponseHandler(this); //Tell the cloud recognition who will receive the responses from the cloud
        mCloudRecognition.setCollectionToken(COLLECTION_TOKEN); //Tell the cloud-recognition which token to use from the finder mode



        //Start finder mode
        mCloudRecognition.startFinding();

        //Obtain the tracking module
        mCatchoomTracking = CatchoomSDK.getTracking();

        mCloudRecognition.connect(COLLECTION_TOKEN);

    }

    @Override
    public void searchCompleted(ArrayList<CatchoomCloudRecognitionItem> results) {
        if(results.size()==0){
        }else{
            CatchoomCloudRecognitionItem item = results.get(0);
            if (item.isAR()) {
                // Stop Finding
                mCloudRecognition.stopFinding();

                // Cast the found item to an AR item
                CatchoomARItem myARItem = (CatchoomARItem)item;

                // Add content to the tracking SDK and start AR experience
                mCatchoomTracking.addItem(myARItem);
                mCatchoomTracking.startTracking();

                mScanningLayout.setVisibility(View.GONE);
            }

        }
    }

    @Override
    public void connectCompleted(){
        Log.i(TAG,"Collection token is valid");
    }

    @Override
    public void requestFailedResponse(int requestCode,
            CatchoomCloudRecognitionError responseError) {
        Log.d(TAG,"requestFailedResponse"); 

    }

    //Callback received for SINGLE-SHOT only (after takePicture).
    @Override
    public void requestImageReceived(CatchoomImage image) {
        mCloudRecognition.searchWithImage(COLLECTION_TOKEN,image);
    }
    @Override
    public void requestImageError(String error) {
        //Take picture failed
    }



}

Image

Jocheved
  • 1,125
  • 3
  • 15
  • 32
  • As you can see the problem is coming from this line: `playExampleIntent = new Intent(this, ARFromCraftARActivity.class);`, the problem is not that the class cannot be found but is probably due to an error while constructing an ARFromCraftARActivity object (could you give us the constructor and the static block (if any) of this class) – ex0ns Jul 29 '14 at 07:43
  • I have given the ARFromCRAftARActivity,... please check – Jocheved Jul 29 '14 at 07:47

1 Answers1

0

Error is ClassNotFoundException it means compiler unable to find your class ARFromCraftARActivity.java file

so you need to mention this class perfectly as per my undestanding you are using library for this project if yes then follow below step to resolve error of "class not found exception"

1 ) Right click on project

2) goto properties

3) goto java build path

4) goto order and export tab

5) check in library which you include for your project

6) click ok apply the changes and compile your code