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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:58:18+00:00 2026-06-13T00:58:18+00:00

I am totally new to Android and trying for Fragments for the first time.

  • 0

I am totally new to Android and trying for Fragments for the first time.
I have used a ListView activity which I am converting in a fragment.
But somehow the ListView element retrieved by findViewById() is giving me null.
Can anyone please help me on this.?

Here is the code for ListView Fragment and I m getting error after I call setAdapter method.
Log value shows timeTrackerListView as null.I dont know why.!! 🙁

 package ray.kaushik.nasaapp;

import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class TimeTracker extends Fragment{
    private Time_Tracker_Adapter timeTrackerAdapter;
    private String TAG = "TimeTracker";
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        timeTrackerAdapter = new Time_Tracker_Adapter();

    }

    public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState){
            return inflater.inflate(R.layout.time__tracker_layout, container, false);
    }

    public void onActivityCreated(Bundle savedInstanceState){
        super.onActivityCreated(savedInstanceState);
        ListView timeTrackerListView = (ListView) getActivity().findViewById(R.id.time_tracker_List);
        Log.i(TAG, "timeTrackerListView-->" + timeTrackerListView);
        timeTrackerListView.setAdapter(timeTrackerAdapter);
    }
}
  • 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-13T00:58:20+00:00Added an answer on June 13, 2026 at 12:58 am

    onCreate() is called before onCreateView(). The ListView hasn’t been inflated yet, this is why you cannot find it…

    Simply move the current onCreate() code into onCreateView() or onActivityCreated().


    You should be able to set up your ListView in onCreateView() with little trouble by saving a reference to the inflated View:

    public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState){
        View view = inflater.inflate(R.layout.time__tracker_layout, container, false);
        ListView timeTrackerListView = (ListView) view.findViewById(R.id.time_tracker_List);
        timeTrackerAdapter = new Time_Tracker_Adapter();
        timeTrackerListView.setAdapter(timeTrackerAdapter);
        return view;
    }
    

    Diagram from Developer’s Guide:

    Fragment Lifecycle

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

Sidebar

Related Questions

First time poster. Im totally new to Android but I have manged to dreate
I am totally new to Android development. I'm not looking for code but what
I'm totally new to iOS programing (I'm more an Android guy..) and have to
I have stacked here, because i am totally new in android world. Can show
I am not totally new to working with the eclipse android plugin but I
I am totally new in appbiling service in android, and it seems to be
Totally new to programming so kindly excuse the silly question. I have this URL
Totally new to Capistrano. I have a local git repository that I want to
im totally new when it comes to trying to make HTML code. I was
I'm totally new to AWS. I managed to have an instance that runs PHPMyAdmin.

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.