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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:34:07+00:00 2026-06-18T10:34:07+00:00

I have a separate asynctask class which creates a url for me. I tried

  • 0

I have a separate asynctask class which creates a url for me. I tried to use an interface in the onPostExecute to send the url to my fragment, but could not managed it. I was always doing the same process in the fragments by forcing to implement the interface in onAttach.

After myTask.execute(), i simply wait for the result with a progress dialog on the screen. Everything works fine until the interface’s callback method is called.(nullpointerexception)

How can I force the fragment to make it implement the interface? (I need to send the data directly to the fragment, not via activity)

Thank you very much for your time.

  • 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-18T10:34:08+00:00Added an answer on June 18, 2026 at 10:34 am

    Alright I found my mistake finally. As ePeace mentioned in his answer. In my Asyntask class, I created a constructor which throws nullpointerexception is the listener is null.

    AsyncListener listener;
    public ReportFactory(AsyncListener a)
    {
        if(a == null)
        {
            throw new NullPointerException("Listener cant be null");
        }
    
        this.setListener(a);
    }
    
    public interface AsyncListener {
        public void onComplete(String url);
    }
    
    
    public void setListener(AsyncListener listener) {
        this.listener = listener;
    }
    

    After that, in the fragment class, I created a listener. (Have a global reference in the class to the listener, so that you can use it on the other places in the fragment lifecycle)

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    
      listener = new AsyncListener()
    {
    
        @Override
        public void onComplete(String url)
        {
            URL = url;          
            webview.loadUrl(URL);         
        }
    };      
    }
    

    And finally, in the onCreate method I created my Asyntask and gave the listener as a paramater.

    ReportFactory factory = new ReportFactory(listener);
    factory.execute(usr, designFile);     
    

    Hope it works for you who might need it later. Thank you very much for your time ePeace.

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

Sidebar

Related Questions

I have a Loader class which just creates a ProgressDialog and show it. Now,
I have web application which we deployed in a production . We have separate
I use subversion to manage my yii website (php framework) and have separate backend
The problem I have is concerning two separate Asynctask classes. The first asynctask uses
I have a MainActivity and an AsyncTask MyTask. They are separate classes. In MyTask,
I have separate php files. I have a master file that I use by
k so i have all my css in separate files but it wont load,
I have an android app, written in java which uses AsyncTask to download data.
In my application I have two threads (I'm using AsyncTask class). in doInBackground() method
I am trying to use an AsyncTask class that I created to update a

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.