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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:35:30+00:00 2026-06-09T16:35:30+00:00

I am studying to fragmentation in android, I write this simple program: In this

  • 0

I am studying to fragmentation in android, I write this simple program:
In this application I want to create a list view and I won’t create a background thread, this thread write in a log file

This is main Activity

public class MainActivity extends FragmentActivity {
    public static final String TAG = "Test_Loader"; 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Log.i(TAG, "Start  !!!!!!!!!!!!!!");    
        if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
            getSupportFragmentManager().beginTransaction().replace(android.R.id.content, new listFragment()).commit();

        }
    }
}

This is my ListFragment:

public class listFragment extends ListFragment implements LoaderCallbacks<Void> {

    public static final String TAG = "Test_Loader";
    private ProgressBar mProgressView;
    private LinearLayout mFormView;
    private int valTest = 0;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_main, null);
        Log.i(TAG, "start listFragment");
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);


        ArrayList<Map<String, String>> list = buildData();
        String[] from = { "name", "purpose" };
        int[] to = { R.id.recordTitolo, R.id.recordDescrizione };
        SimpleAdapter adapter = new SimpleAdapter(getActivity(), list,
                R.layout.record, from, to);
        setListAdapter(adapter);

        /** IL LOADERMANAGER */
        getLoaderManager().initLoader(0, null, this);

    }


    private ArrayList<Map<String, String>> buildData() {
        ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
        list.add(putData("android", "mobile"));
        list.add(putData("winphone7 ", "windows"));
        list.add(putData("iPhone", "iPhone"));
        return list;
        // TODO Auto-generated method stub

    }


    private HashMap<String, String> putData(String name, String purpose) {
        HashMap<String, String> item = new HashMap<String, String>();
        item.put("name", name);
        item.put("purpose", purpose);
        return item;
    }


    @Override
    public Loader<Void> onCreateLoader(int id, Bundle args) {
        Log.i(TAG, "onCreateLoader(): id=" + id);
        AsyncTaskLoader<Void> loader = new AsyncTaskLoader<Void>(getActivity()) {
            @Override
            public Void loadInBackground() {

                try {

                Log.i(TAG, "loadInBackground(): doing some work....");
                    for (int i = 0; i < 4; ++i) {
                    Log.i(TAG, "backgroud: number " + i);
                    }
                    valTest = 100;
                    Thread.sleep(5000);                                     
                } catch (InterruptedException e) {
                    Log.d(TAG, "ERROR" + e);
                }

                Log.i(TAG, "Stop backgroud");
                return null;
            }
        };
        Log.i(TAG, "return");
        loader.forceLoad();
        return loader;
    }

    // metodo per implementare dopo caricato questo metido viene richiamato
    @Override
    public void onLoadFinished(Loader<Void> arg0, Void arg1) {
        toggleLoading(false);
        buildForm();
        // TODO Auto-generated method stub

    }
    private void buildForm() {

        // TODO Auto-generated method stub
        Log.i(TAG, "Valuet: " + valTest);
    }

    private void toggleLoading(boolean b) {
        // TODO Auto-generated method stub
        mProgressView.setVisibility(b ? View.VISIBLE : View.GONE); 
        mFormView.setGravity(b ? Gravity.CENTER : Gravity.TOP); 
    }

    @Override
    public void onLoaderReset(Loader<Void> arg0) {
        // TODO Auto-generated method stub
        Log.i(TAG, "start onLoaderReset()");
    }

}

here you can see the activity_main.xml

activity_main.xml

Now I think the problem is present in getLoaderManager but I don’t understand how to fix it.

Edit

When I run my application, I see this in logcat:

08-08 15:13:09.347: E/AndroidRuntime(341): FATAL EXCEPTION: main
08-08 15:13:09.347: E/AndroidRuntime(341): java.lang.NullPointerException
08-08 15:13:09.347: E/AndroidRuntime(341):  at com.example.test3.listFragment.toggleLoading(listFragment.java:128)
08-08 15:13:09.347: E/AndroidRuntime(341):  at com.example.test3.listFragment.onLoadFinished(listFragment.java:114)
08-08 15:13:09.347: E/AndroidRuntime(341):  at com.example.test3.listFragment.onLoadFinished(listFragment.java:1)
08-08 15:13:09.347: E/AndroidRuntime(341):  at android.support.v4.app.LoaderManagerImpl$LoaderInfo.callOnLoadFinished(LoaderManager.java:425)
08-08 15:13:09.347: E/AndroidRuntime(341):  at android.support.v4.app.LoaderManagerImpl$LoaderInfo.onLoadComplete(LoaderManager.java:393)
08-08 15:13:09.347: E/AndroidRuntime(341):  at android.support.v4.content.Loader.deliverResult(Loader.java:103)
08-08 15:13:09.347: E/AndroidRuntime(341):  at android.support.v4.content.AsyncTaskLoader.dispatchOnLoadComplete(AsyncTaskLoader.java:221)
08-08 15:13:09.347: E/AndroidRuntime(341):  at android.support.v4.content.AsyncTaskLoader$LoadTask.onPostExecute(AsyncTaskLoader.java:61)
08-08 15:13:09.347: E/AndroidRuntime(341):  at android.support.v4.content.ModernAsyncTask.finish(ModernAsyncTask.java:461)
08-08 15:13:09.347: E/AndroidRuntime(341):  at android.support.v4.content.ModernAsyncTask.access$500(ModernAsyncTask.java:47)
08-08 15:13:09.347: E/AndroidRuntime(341):  at android.support.v4.content.ModernAsyncTask$InternalHandler.handleMessage(ModernAsyncTask.java:474)
08-08 15:13:09.347: E/AndroidRuntime(341):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-08 15:13:09.347: E/AndroidRuntime(341):  at android.os.Looper.loop(Looper.java:123)

I think the problem is this code

private void toggleLoading(boolean b) {
    // TODO Auto-generated method stub
    mProgressView.setVisibility(b ? View.VISIBLE : View.GONE); 
    mFormView.setGravity(b ? Gravity.CENTER : Gravity.TOP);
}

when I delete this code all work well, but I don’t know because I have this situation.

  • 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-09T16:35:32+00:00Added an answer on June 9, 2026 at 4:35 pm

    You’re getting that problem because it looks like you’re not initialising the mProgressView and mFormView fields. If they’re defined in the layout, you’ll want something like this:

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_main, null);
    
        mProgressView = (ProgressBar)view.findViewById(R.id.progress_view_id);
        mFormView = (LinearLayout)view.findViewById(R.id.form_view_id);
    
        Log.i(TAG, "start listFragment");
        return view;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im studying for my programming final exam. I have to write a program which
Im studying for finals and i came across this question: write a PHP script
Studying MS Exam 70-536 .Net Foundation I've got to Chapter 11 Application Security and
I am studying an existing Perl program, which includes the following line of code:
I'm studying Javascript cookie. Basically what I want is when the first time user
While studying for the SCJP 6 exam, I ran into this question in a
I keep studying this flow of the Facebook's bigpipe technique but I have this
While studying for the 70-433 exam I noticed you can create a covering index
Currently studying bitwise arithmetic. It's really easy, because I have some CS background. But
Im studying some ruby code and I see this varx variable being used with

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.