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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:58:02+00:00 2026-05-15T12:58:02+00:00

I am calling intents alot in my program and I thought that I could

  • 0

I am calling intents alot in my program and I thought that I could write a public class that would have all of my intents so I can just call something like intents.testIntent(params) and then have it fire off the intent.

I tried it out but am getting a force close with a null pointer exception. This is my whole class. I know it is probably sloppy but I have just been learning java for 2 months so I still am an amateur.

Any way, my code is below and I would much appreciate your help.

    public class intents extends Activity{
     String classpkg = "com.MyApp";

     public void onCreate(Bundle savedInstanceState) {


            super.onCreate(savedInstanceState);
     } 
     public void testIntent(String name, String match){
      Log.v("AI","made It");
      Intent myIntent = new Intent();

      myIntent.setClassName(classpkg, classpkg+".Search");
      Log.v("AI","Launching Intent"); //This is where it dies
      startActivity(myIntent);
      Log.v("AI","Launced Intent");

     }

}

Log

  /AI      (17056): made It
V/AI      (17056): Launching Intent
D/AndroidRuntime(17056): Shutting down VM
W/dalvikvm(17056): threadid=3: thread exiting with uncaught exception (group=0x4001b180)
E/AndroidRuntime(17056): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(17056): java.lang.NullPointerException
E/AndroidRuntime(17056): at android.app.Activity.startActivityForResult(Activity.java:2749)
E/AndroidRuntime(17056): at android.app.Activity.startActivity(Activity.java:2855)
E/AndroidRuntime(17056): at com.MyApp.intents.testIntent(intents.java:26)
E/AndroidRuntime(17056): at com.MyApp.Starting$1.onClick(Starting.java:52)
E/AndroidRuntime(17056): at android.view.View.performClick(View.java:2364)
E/AndroidRuntime(17056): at android.view.View.onTouchEvent(View.java:4179)
E/AndroidRuntime(17056): at android.widget.TextView.onTouchEvent(TextView.java:6541)
E/AndroidRuntime(17056): at android.view.View.dispatchTouchEvent(View.java:3709)
E/AndroidRuntime(17056): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime(17056): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime(17056): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime(17056): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime(17056): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime(17056): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime(17056): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
E/AndroidRuntime(17056): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
E/AndroidRuntime(17056): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
E/AndroidRuntime(17056): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
E/AndroidRuntime(17056): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
E/AndroidRuntime(17056): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(17056): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(17056): at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(17056): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(17056): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(17056): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(17056): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(17056): at dalvik.system.NativeStart.main(Native Method)

SOLUTION:
A solution, maybe not THE solution. Was to build the intent in the intents class(renamed MyIntents) and then start it from my other class.

MyIntents intents1  = new MyIntents();
Intent arIntent = intents1.testIntent("fe", "feet");
startActivity(arIntent);

This will make my life alot easier. 🙂

  • 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-15T12:58:02+00:00Added an answer on May 15, 2026 at 12:58 pm

    I think what you are doing (strings for class names, instantiating a helper class each time you need an intent) is messy.
    I’d suggest having a helper class with factory methods like this:

    public static final String FIRST_NAME = "first_name";
    
    public static Intent getNameIntent(Context ctx, String firstName) {
        Intent intent = new Intent(ctx, NameActivity.class);
        intent.putExtra(FIRST_NAME, firstName);
        return intent;
    }
    

    and then from an Activity:

        Intent intent = getNameIntent(this, "alex");
        startActivity(intent);
        // or
        startActivityForResult(intent, 1024);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

//calling class import javax.swing.JFrame; class jcheckkbox { public static void main(String args[]) { jRadio
Im kinda stuck. I have an activity in my app that just wont go
I have an application calling a second activity using a list of objects. that
I'm calling the object here. public class TestDetails extends ListActivity { protected TextView testNameText;
Calling: Intent i = new Intent(Timer.this,TimerService.class); i.putExtra(ms, ms); startService(i); code: public class TimerService extends
Can someone tell if why when starting an activity with startActivity(intent) , calling getParent()
Calling Html.RenderPartial(~/Views/Payments/MyControl.ascx); from a view works if MyControl.ascx is a control that directly inherits
I have lots of Activities chained together with Intents and some Intents require parameters
So I can display Android's contact selecton activity by calling startActivityForResult(intent, PICK_CONTACT); and i
after calling: result=bindService(new Intent(IUdpListenerService.class.getName()), serviceConnection, Context.BIND_AUTO_CREATE); byt debugger: result return 'true' the onServiceConnected isn'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.