Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7820807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:26:11+00:00 2026-06-02T07:26:11+00:00

I’m getting a NullPointerException in my application when trying to detect a shake. In

  • 0

I’m getting a NullPointerException in my application when trying to detect a shake.

In my application I have a service running in the background, and an activity that calls the method cameraIntent().

public class Run1 extends Activity implements Shaker.Callback {
public static final int MEDIA_TYPE_IMAGE = 1;
public static final int MEDIA_TYPE_VIDEO = 2;
public static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
public static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200;
private Uri fileUri;
private static final String TAG = Shaker.class.getSimpleName();
final Handler handle = new Handler();
Shaker shaker;
shakeCameraService shakecamera;


public void miThread() {
    Thread t = new Thread() {
        public void run() {
            handle.post(proceso);
        }
    };
    t.start();

}

public final Runnable proceso = new Runnable() {
    public void run() {         
        cameraIntent();


    }
};



/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Log.e("ONCREATE RUN1 ", "ONCREATE RUN1");
    startService(new Intent(this, shakeCameraService.class));       

}

public void cameraIntent() {
    shaker = new Shaker(this, 5.0d, 500, this);
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to
                                                        // // save the image
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file
                                                        // name
    // start the image capture Intent
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);


}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {

            if (fileUri != null) {
                Log.e(TAG, "Result ok");
                Log.e(TAG, "Image saved to:\n" + fileUri);
                Log.e(TAG, "Image path:\n" + fileUri.getPath());
                // uri.getLastPathSegment()
                // if store
                // in folder
            }

        } else if (resultCode == RESULT_CANCELED) {
            Log.e(TAG, "RESULT CANCELED");

        } else {
            // Image capture failed, advise user
        }
    }

}

private static Uri getOutputMediaFileUri(int type) {
    return Uri.fromFile(getOutputMediaFile(type));
}

/** Create a File for saving an image or video */
private static File getOutputMediaFile(int type) {
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.

    File mediaStorageDir = new File(
            Environment.getExternalStorageDirectory() + "/DCIM/Camera");
    // This location works best if you want the created images to be shared
    // between applications and persist after your app has been uninstalled.

    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d("ShakerCam", "failed to create directory");
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
            .format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "IMG_" + timeStamp + ".jpg");
    } else {
        return null;
    }

    return mediaFile;
}

public void shakingStarted() {
    miThread();

}

public void shakingStopped() {
    // TODO Auto-generated method stub

}
}

This is my service

public class shakeCameraService extends Service implements Shaker.Callback {
Run1 run1;
Shaker shaker =null;


@Override
public void onCreate() {
    super.onCreate();
    shaker = new Shaker(this, 5.0d, 500, this);
    Log.e("ONCREATE SERVICE", "ONCREATE SERVICE");

}

@Override
public void onStart(Intent intent, int startId) {
    shaker = new Shaker(this, 5.0d, 500, this);
    Log.e("onStart Servicio ", "onStart Servicio ");
}

@Override
public void shakingStarted() {
    shaker = new Shaker(this, 5.0d, 500, this);
    Log.e("shakingstrated SERVICE", "shakingstrated SERVICE");
    run1.cameraIntent();

}


@Override
public void shakingStopped() {
    // TODO Auto-generated method stub

}

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}



}

The error is logcat me back then! And nose like really solve this problem!

04-19 23:26:30.788: ERROR/ONCREATE RUN1(356): ONCREATE RUN1
04-19 23:26:30.808: DEBUG/onCReate RUN1(356): antes de llamar a shakingstrated
04-19 23:26:30.808: DEBUG/AndroidRuntime(356): Shutting down VM
04-19 23:26:30.808: WARN/dalvikvm(356): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-19 23:26:30.822: ERROR/AndroidRuntime(356): Uncaught handler: thread main exiting due to uncaught exception
04-19 23:26:30.842: ERROR/AndroidRuntime(356): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sebastian.shakeCam/com.sebastian.shakeCam.Run1}: java.lang.NullPointerException
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at android.os.Looper.loop(Looper.java:123)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at android.app.ActivityThread.main(ActivityThread.java:4363)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at java.lang.reflect.Method.invokeNative(Native Method)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at java.lang.reflect.Method.invoke(Method.java:521)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at dalvik.system.NativeStart.main(Native Method)
04-19 23:26:30.842: ERROR/AndroidRuntime(356): Caused by: java.lang.NullPointerException
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at com.sebastian.shakeCam.Run1.onCreate(Run1.java:57)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-19 23:26:30.842: ERROR/AndroidRuntime(356):     ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:26:14+00:00Added an answer on June 2, 2026 at 7:26 am

    The onStart(...) method of Service is deprecated.

    You should implement onStartCommand (...) instead. See the docs for onStartCommand.

    I’m not sure if it will fix your problem though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.