Ask Your Question

Using Toast widget to display results from timer in image-manipulations Android app

asked 2013-01-15 08:58:57 -0500

KristoF124 gravatar image

updated 2013-01-15 16:10:57 -0500

I'm modifying the image-manipulations sample application for Android. I'm using System.currentTimeMillis() as a timer to measure performance of the application on several devices. I'm trying to display the results from timer on the screen. I use the following command:

           Toast.makeText(getContext(), "" + elapse + "ms is used
           to process", Toast.LENGTH_LONG).show();

When I try to run the part of the app, where the provided code is, the whole application crashes. The debugger shows me an error in file in the first line of code:

            synchronized (this) {
            if (mCamera == null) {
                Log.i(TAG, "mCamera == null");
            if (!mCamera.grab()) {
                Log.e(TAG, "mCamera.grab() failed");
            bmp = processFrame(mCamera);

The main difference between original image-manipulations sample and my modification is that my app uses image from the internal memory instead from the onboard camera. How can I fix the error and display the results of the timer on the device screen?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-01-16 22:39:04 -0500

Threading is root of the problem. All OpenCV Java samples uses separate thread for camera handling and frames processing. Toast is a GUI element and can be constructed and shown in UI thread only. See StackOverflow discussion for more details.

edit flag offensive delete link more

Question Tools


Asked: 2013-01-15 08:58:57 -0500

Seen: 1,145 times

Last updated: Jan 16 '13