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

  • SEARCH
  • Home
  • 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 8145433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:39:38+00:00 2026-06-06T13:39:38+00:00

I have this function in my onDestroy function and it’s causing a crash: @Override

  • 0

I have this function in my onDestroy function and it’s causing a crash:

@Override
protected void onDestroy() {
    Server.setPresence(false, CONSTANTS.USER.userId);
    super.onDestroy();
}

Server.Java

private static final String TAG = "Cove Server";
private static final String PATH = "http://10.0.0.2:8001/data_connection";
private static HttpResponse response = null;
private static StringEntity se = null;
private static final int TIMEOUT = 30000;
private static HttpParams hParams = new BasicHttpParams();
private static HttpClient client;
private static HttpPost post = null;
public static String actionKey = null;

private static JSONObject sendRequest(JSONObject req) {
    try {
        HttpConnectionParams.setConnectionTimeout(hParams, TIMEOUT);
        client = new DefaultHttpClient(hParams);
        actionKey = req.getString("actionKey");
        se = new StringEntity(req.toString());
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_ENCODING,
                "application/json"));
        se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
                "application/json"));
        post = new HttpPost(PATH);
        post.setEntity(se);

        Log.d(TAG, "http request is being sent");
        response = client.execute(post);
        Log.d(TAG, "http request was sent");

        if (response != null
                && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            InputStream in = response.getEntity().getContent();
            String a = convertFromInputStream(in); // CALLS A FUNCTION THAT PARSES THE RESPONSE TO String
            in.close();
            return new JSONObject(a);
        }

    } catch (UnsupportedEncodingException e) {
        Log.d(TAG, "encoding request to String entity faild!");
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        Log.d(TAG, "executing the http POST didn't work");
        e.printStackTrace();
    } catch (IOException e) {
        Log.d(TAG, "executing the http POST didn't work");
        e.printStackTrace();
    } catch (JSONException e) {
        Log.d(TAG, "no ActionKey");
        e.printStackTrace();
    }
    return null;
}

public static JSONObject setPresence(boolean isActive, String userId) {
    JSONObject request = new JSONObject();
    try {
        request.put("actionKey", (isActive) ? "UserPresenceActive"
                : "UserPresenceInactive");
        request.put("userId", userId);
        return sendRequest(request);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}

logcat

06-28 12:59:11.970: E/AndroidRuntime(19806): FATAL EXCEPTION: main
06-28 12:59:11.970: E/AndroidRuntime(19806): java.lang.RuntimeException: Unable to destroy activity {com.yishai/com.thepoosh.MyActivity}: java.lang.NullPointerException
06-28 12:59:11.970: E/AndroidRuntime(19806):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3124)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3142)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at android.app.ActivityThread.access$1200(ActivityThread.java:127)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1192)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at android.os.Looper.loop(Looper.java:137)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at android.app.ActivityThread.main(ActivityThread.java:4507)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at java.lang.reflect.Method.invokeNative(Native Method)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at java.lang.reflect.Method.invoke(Method.java:511)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at dalvik.system.NativeStart.main(Native Method)
06-28 12:59:11.970: E/AndroidRuntime(19806): Caused by: java.lang.NullPointerException
06-28 12:59:11.970: E/AndroidRuntime(19806):    at com.thepoosh.MyActivity.onDestroy(MyActivity.java:340)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at android.app.Activity.performDestroy(Activity.java:4629)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1082)
06-28 12:59:11.970: E/AndroidRuntime(19806):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3111)
06-28 12:59:11.970: E/AndroidRuntime(19806):    ... 11 more

I’m suspecting that since the server is not sending back a response and the Server.setPresence() doesn’t return and therefore the app goes into ANR.

Is that correct? What should I do to fix this? Is there a different reason for the crash?

  • 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-06T13:39:40+00:00Added an answer on June 6, 2026 at 1:39 pm
    06-28 12:59:11.970: E/AndroidRuntime(19806): Caused by: java.lang.NullPointerException
    06-28 12:59:11.970: E/AndroidRuntime(19806):    at com.thepoosh.MyActivity.onDestroy(MyActivity.java:340)
    06-28 12:59:11.970: E/AndroidRuntime(19806):    at android.app.Activity.performDestroy(Activity.java:4629)
    

    looks on onDestroy is last function is stacktrace so call not went to Server.setPresence yet .. so it looks USER in CONSTANTS.USER.userId may be only null at that line. so put a check to test out that.

    @Override
    protected void onDestroy() {
        if(null==CONSTANTS.USER){
        Server.setPresence(false, CONSTANTS.USER.userId);
        }else{
             Toast.makeText(this,"is null",Toast.LENGHT_LONG).show();
          }
        super.onDestroy();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code running in my onDestroy function: @Override protected void onDestroy() {
I have this function I have to implement: protected override ValidationResult IsValid( Object value,
I have this function: public static void Play(string FileName, bool Async = false) {
I have this function: public bool IsValidProduct(int productTypeId) { bool isValid = false; if
i have this function pymssql.connect(host=my host,user=my user,password=my pass,database=mydb) I want to read the user
I have this function: void ToUpper(char * S) { while (*S!=0) { *S=(*S >=
I have this function to register a new user in the DB: this.registerUser =
I have this function; static public void Print(Object[] arr) { for(int i = 0;
I have this function in my PHP : setcookie(UserPusser, $user, time() + 604800, /pusser/beta/);
I have this function signature I have to match typedef int (*lua_CFunction) (lua_State *L);//target

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.