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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:43:13+00:00 2026-05-28T13:43:13+00:00

In this opportunity I try to do a simple activity that get a EditText

  • 0

In this opportunity I try to do a simple activity that get a EditText, a Button and make an intent when I press the button to call to the number in the EditText.

The activity start, but throw an exception like this…

01-23 14:41:13.760: E/AndroidRuntime(305): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{android.testcall/android.testcall.TestCallActivity}: java.lang.NullPointerException

Tell me if you need more info, or code to view…

code class:

public class TestCallActivity extends Activity {
private TelephonyManager _CurrTelephonyManager;
    private PhoneStateListener phoneListener;
    final TextView textview = (TextView) findViewById(R.id.TvResulState);
    final EditText phoneNumber = (EditText)findViewById(R.id.EtPhoneNumber);
    private Date lastIdleTime;
    private String currentPhoneState = "CALL_STATE_IDLE";

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

        phoneListener = new PhoneStateListener()
        {
            @Override
            public void onCallStateChanged(int state, String incomingNumber)
            {
                switch (state) 
                {
                    case TelephonyManager.CALL_STATE_IDLE:
                        lastIdleTime = new Date();
                        currentPhoneState = "CALL_STATE_IDLE";
                    break;
                    case TelephonyManager.CALL_STATE_OFFHOOK:
                        currentPhoneState = "CALL_STATE_OFFHOOK";    
                    break;
                    case TelephonyManager.CALL_STATE_RINGING:
                        currentPhoneState = "CALL_STATE_RINGING";
                    break;
                }
                textview.setText("Phone State: " + currentPhoneState);
            }
        };      
        _CurrTelephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);


    } catch (Exception error) {
        // TODO: handle exception
        error.printStackTrace();
    }

    final Button btCall = (Button) findViewById(R.id.BtCallNumber);
        btCall.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_CALL);
                String uri = "tel:" + phoneNumber.toString().trim() ;
                intent.setData(Uri.parse(uri));
                startActivity(intent);
            }
    });
}

Full error stack:

01-23 15:25:17.234: E/AndroidRuntime(309): FATAL EXCEPTION: main
01-23 15:25:17.234: E/AndroidRuntime(309): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{android.testcall/android.testcall.TestCallActivity}: java.lang.NullPointerException
01-23 15:25:17.234: E/AndroidRuntime(309):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
01-23 15:25:17.234: E/AndroidRuntime(309):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-23 15:25:17.234: E/AndroidRuntime(309):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-23 15:25:17.234: E/AndroidRuntime(309):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-23 15:25:17.234: E/AndroidRuntime(309):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-23 15:25:17.234: E/AndroidRuntime(309):  at android.os.Looper.loop(Looper.java:123)
01-23 15:25:17.234: E/AndroidRuntime(309):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-23 15:25:17.234: E/AndroidRuntime(309):  at java.lang.reflect.Method.invokeNative(Native Method)
01-23 15:25:17.234: E/AndroidRuntime(309):  at java.lang.reflect.Method.invoke(Method.java:521)
01-23 15:25:17.234: E/AndroidRuntime(309):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-23 15:25:17.234: E/AndroidRuntime(309):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-23 15:25:17.234: E/AndroidRuntime(309):  at dalvik.system.NativeStart.main(Native Method)
01-23 15:25:17.234: E/AndroidRuntime(309): Caused by: java.lang.NullPointerException
01-23 15:25:17.234: E/AndroidRuntime(309):  at android.app.Activity.findViewById(Activity.java:1637)
01-23 15:25:17.234: E/AndroidRuntime(309):  at android.testcall.TestCallActivity.<init>(TestCallActivity.java:21)
01-23 15:25:17.234: E/AndroidRuntime(309):  at java.lang.Class.newInstanceImpl(Native Method)
01-23 15:25:17.234: E/AndroidRuntime(309):  at java.lang.Class.newInstance(Class.java:1429)
01-23 15:25:17.234: E/AndroidRuntime(309):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-23 15:25:17.234: E/AndroidRuntime(309):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
  • 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-05-28T13:43:14+00:00Added an answer on May 28, 2026 at 1:43 pm

    Move these in your onCreate method after setContentView:

    final TextView textview = (TextView) findViewById(R.id.TvResulState);
    final EditText phoneNumber = (EditText)findViewById(R.id.EtPhoneNumber);
    

    Also, remove the try…catch. It doesn’t do good.

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

Sidebar

Related Questions

So just this week I had the opportunity to re-build my development machine and
This is my first post here and I wanted to get some input from
This error just started popping up all over our site. Permission denied to call
This most be the second most simple rollover effect, still I don't find any
Can jQuery provide a fallback for failed AJAX calls? This is my try: function
In my spare time, I am building a Sudoku solver to try to get
I have this query: (from r in gServiceContext.CreateQuery(opportunity) join c in gServiceContext.CreateQuery(contact) on ((EntityReference)r[new_contact]).Id
This is a bit of a long shot, but if anyone can figure it
This is starting to vex me. I recently decided to clear out my FTP,
This is kinda oddball, but I was poking around with the GNU assembler today

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.