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 7817685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:18:43+00:00 2026-06-02T06:18:43+00:00

MakeMissedCallActivity.java: package com.android.main; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import

  • 0

MakeMissedCallActivity.java:

package com.android.main;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.os.Bundle;
import android.util.Log;

public class MakeMissedCallActivity extends Activity {
    private Button button;
    private static boolean mCallMadeFromApp = false;
    private String LOG_TAG = "MakeMissedCall App";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Listen for call state changes before making the call through button
        CallStateListener callStateListener = new CallStateListener();
        TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);

        // add button and add dial functionality 
        button = (Button) findViewById(R.id.buttonCall);
        button.setOnClickListener(new OnClickListener() {
            //@Override
            public void onClick(View arg0) {
                mCallMadeFromApp = true;
                Log.i(LOG_TAG, "Button clicked");
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:+918028563681"));
                startActivity(callIntent);
            }
        });
    }

    public boolean getmCallMadeFromApp() {
        Log.i(LOG_TAG, "mCallMadeFromApp=" +mCallMadeFromApp);
        return mCallMadeFromApp;
    }

    public void setmCallMadeFromApp(boolean mNewValue) {
        mCallMadeFromApp = mNewValue;
    }
}

CallStateListener.java:

package com.android.main;

import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;

//monitor phone call activities
public class CallStateListener extends PhoneStateListener {
    private String LOG_TAG = "MakeMissedCall App";
    MakeMissedCallActivity makeMissedCallActivity;

    CallStateListener() {
        MakeMissedCallActivity makeMissedCallActivity = new MakeMissedCallActivity();
    }

    @Override
    public void onCallStateChanged(int call_state, String incomingNumber) {
        switch(call_state) {
            case TelephonyManager.CALL_STATE_RINGING:
                Log.i(LOG_TAG, "CALL_STATE_RINGING");
                break;

            case TelephonyManager.CALL_STATE_OFFHOOK:
                Log.i(LOG_TAG, "CALL_STATE_OFFHOOK. mCallMadeFromApp=" + makeMissedCallActivity.getmCallMadeFromApp());
                break;

            case TelephonyManager.CALL_STATE_IDLE:
                if (makeMissedCallActivity.getmCallMadeFromApp() == true) {
                    makeMissedCallActivity.setmCallMadeFromApp(false);
                }
                Log.i(LOG_TAG, "CALL_STATE_IDLE");
                break;
        }
    }
}

When I run the app, I get a nullPointerException in the line if (makeMissedCallActivity.getmCallMadeFromApp() == true) in CallStateListener.java.

Any idea what may be the problem?

  • 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-02T06:18:44+00:00Added an answer on June 2, 2026 at 6:18 am

    Your problem seems to be in this block of code;

    MakeMissedCallActivity makeMissedCallActivity;
    
    CallStateListener() {
        MakeMissedCallActivity makeMissedCallActivity = new MakeMissedCallActivity();
    }
    

    You’re creating a private variable, but in your constructor, you’re creating a new local variable with the same name and assign the new activity to that. When you exit the constructor, the private variable will still be null.

    What you mean to do is probably just simply;

    MakeMissedCallActivity makeMissedCallActivity;
    
    CallStateListener() {
        makeMissedCallActivity = new MakeMissedCallActivity();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.