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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:55:58+00:00 2026-06-10T13:55:58+00:00

I have got a problem with android fragments. If I called the Actitiy A

  • 0

I have got a problem with android fragments.

If I called the Actitiy A via Intent and the Actitiy is started before, it works.
In the other case, if I called the Actitiy A via Intent and the Actitiy is NOT started before, there will be throw a NullPointerException, if I try to get the Fragment Object.

I have to get access to the Fragment, but I got a NPE if the Activity is not running.

Code Snipped within Activity:

public class HomeActivity extends BaseFragmentActivity {

@Override
protected void onNewIntent(Intent intent) {
        if (intent.hasExtra("tab")) {
            int tab = intent.getIntExtra("tab", 0);
            mTabsHelper.setTab(tab);
            if (intent.hasExtra("id")) {
                String tickerName = intent.getStringExtra("id");
                switchToExistTicker(tickerName);
            }
        }
    }

    private TickerListFragment getTickerListFragment() {
        TickerListFragment tickerListFragment = (TickerListFragment) getSupportFragmentManager()
                    .findFragmentByTag("android:switcher:2131099811:1");
        return tickerListFragment;
    }

    private void switchToNewTicker(String name) {
        getTickerListFragment().setNewTicketName(name);
    }

    private void switchToExistTicker(String name) {
        getTickerListFragment().switchToTicker(getTickerListFragment().getTickerIdForTickerName(name), true);
    }
}

In the other Activity, which is reponsibel for sending the Intent via Notification, the following Code Snipped:

protected void sendnotification (String title, String message) {
    Intent i = new Intent("android.intent.action.MAIN");
    i.setComponent(new ComponentName("de.domain.android", "de.domain.android.HomeActivity"));
    i.putExtra("tab", 1);
    i.putExtra("id", "subject");
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);

    Notification n = new Notification(R.drawable.ic_launcher, message, System.currentTimeMillis());
    n.flags = Notification.FLAG_AUTO_CANCEL;
    n.setLatestEventInfo(getApplicationContext(), title, message, contentIntent);

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.notify(0, n);
}

After the notification was send, the user touch the notification to open the Activity A. The Activity A receive the Intent with certain extras (for more detail, please see attached code snippets). As described the Activity crashed if the Activity A is not started before, so they have to start new. In this case, the needed Fragment could not find and “null” is the return value – NullPointerException is the result.
Also as described the Activity will not crash if the Activity started before – then it works.

Following the exception stock:

  8805         AndroidRuntime  E  FATAL EXCEPTION: main
  8805         AndroidRuntime  E  java.lang.RuntimeException: Unable to start activity ComponentInfo{de.domain.android/de.domain.android.HomeActivity}: java.lang.NullPointerException
  8805         AndroidRuntime  E    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
  8805         AndroidRuntime  E    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2237)
  8805         AndroidRuntime  E    at android.app.ActivityThread.access$600(ActivityThread.java:139)
  8805         AndroidRuntime  E    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
  8805         AndroidRuntime  E    at android.os.Handler.dispatchMessage(Handler.java:99)
  8805         AndroidRuntime  E    at android.os.Looper.loop(Looper.java:154)
  8805         AndroidRuntime  E    at android.app.ActivityThread.main(ActivityThread.java:4974)
  8805         AndroidRuntime  E    at java.lang.reflect.Method.invokeNative(Native Method)
  8805         AndroidRuntime  E    at java.lang.reflect.Method.invoke(Method.java:511)
  8805         AndroidRuntime  E    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  8805         AndroidRuntime  E    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  8805         AndroidRuntime  E    at dalvik.system.NativeStart.main(Native Method)
  8805         AndroidRuntime  E  Caused by: java.lang.NullPointerException
  8805         AndroidRuntime  E    at de.domain.android.HomeActivity.switchToExistTicker(HomeActivity.java:144)
  8805         AndroidRuntime  E    at de.domain.android.HomeActivity.onNewIntent(HomeActivity.java:127)
  8805         AndroidRuntime  E    at de.domain.android.HomeActivity.onCreate(HomeActivity.java:94)
  8805         AndroidRuntime  E    at android.app.Activity.performCreate(Activity.java:4538)
  8805         AndroidRuntime  E    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
  8805         AndroidRuntime  E    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2158)
  8805         AndroidRuntime  E    ... 11 more

Any help and suggestions will be appreciated!

Regards!

  • 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-10T13:55:59+00:00Added an answer on June 10, 2026 at 1:55 pm

    Your NPE is logged with class na line, as stack trace tells:

    ... at de.domain.android.HomeActivity.switchToExistTicker(HomeActivity.java:144)
    

    since you did not provide that code you have to check your HomeActivity.java line 144 to see if you i.e. do not try to access objects that may under some condition be null. Anyway, plant a breakpoint there and debug. W/o related source I can’t give more detailed pointers.

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

Sidebar

Related Questions

I've got a problem concerning android layouts. In my xml file I have two
I have started to have a play with Android programming and I got a
I have a strange problem with my android application. I implemented maps, i got
I have got odd problem while sending intent with parcelable object. This object has
I have been reading Google's android tutorial and I got a problem... In the
I have got a new problem with my Android app. The SocketChannel tells me
again i have got a problem with socket programming in Android. My Problem is
Hi I have got a problem that I can't solve when compiling the android
I have got huge problem with my Android app and I would like to
I have got a small problem in an Android app I am working on

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.