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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:54:28+00:00 2026-06-10T20:54:28+00:00

I’m a noob to android and i am having an issue calling a method

  • 0

I’m a noob to android and i am having an issue calling a method from another class. The method works works fine when called from within its own class, but i get a nullpointerexception when i call it from another class. Any help would be greatly appreciated. Here is my code;

Calling method in class1 from class2:

BottlesActivity  inst = new BottlesActivity();
inst.call0();               

Method in class 1:

public void call0() {
    try {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:1234567890"/*+phonenumber0*/));
        startActivity(callIntent); //<--This line causes nullpointerexception
    } catch (ActivityNotFoundException activityException) {
        Log.e("dialing-example", "Call failed", activityException);
    }
}

Here is my Logcat

09-06 20:51:33.237: E/AndroidRuntime(18192): java.lang.NullPointerException
09-06 20:51:33.237: E/AndroidRuntime(18192):    at android.app.Activity.startActivityForResult(Activity.java:2893)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at android.app.Activity.startActivity(Activity.java:3003)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at com.bryanjrichardson.GSCC.BottlesActivity.call0(GoldandSilverCoinCalculatorActivity.java:857)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at com.bryanjrichardson.GSCC.SimpleItemizedOverlay$1.onClick(SimpleItemizedOverlay.java:204)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:174)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at android.os.Looper.loop(Looper.java:130)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at android.app.ActivityThread.main(ActivityThread.java:3859)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at java.lang.reflect.Method.invokeNative(Native Method)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at java.lang.reflect.Method.invoke(Method.java:507)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-06 20:51:33.237: E/AndroidRuntime(18192):    at dalvik.system.NativeStart.main(Native Method)
  • 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-10T20:54:30+00:00Added an answer on June 10, 2026 at 8:54 pm

    If your 2 classes are 2 separated Activities, your case will cause Null Pointer Exception, because when 2nd activity is running, 1st activity is stopped (terminated) -> this is Android OS mechanism, you can not change.

    Solutions for your case:

    • (1) Activity 1 is parent of others, this case is suitable for Application class or TabHost (complicated).

    • (2) Create static method like @Zapl’s answer; But it’s still not quite nice because this static method should be in common use instead of inside Class 1 -> modify: Create a common Class like following:

    This is utility class:

    public class GlobalUtil
    {
        public static void startUrlActivity(Context context, String url) {
        try {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse(url));
            context.startActivity(callIntent); //<-- pass current activity or context
            } catch (ActivityNotFoundException activityException) {
            Log.e("dialing-example", "Call failed", activityException);
            }
        }
    }
    

    And inside any other activity class you can call it:

    GlobalUtil.startUrlActivity(this, "tel:1234567890"/*+phonenumber0*/");
    

    OR

    GlobalUtil.startUrlActivity(getBaseContext().getApplicationContext(), "your_url");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.