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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:44:11+00:00 2026-06-17T06:44:11+00:00

I’m newbie Android developer. My project goal is to make a downloader app. I

  • 0

I’m newbie Android developer. My project goal is to make a downloader app. I decided to do that with fragments. I got an NPE, and i havent got any idea what’s wrong.
These are my codes:

activity_main.xml

    <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <android.support.v4.view.PagerTitleStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#33b5e5"
        android:paddingBottom="4dp"
        android:paddingTop="4dp"
        android:textColor="#fff" 
        />

</android.support.v4.view.ViewPager>

list.xml:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/dlist"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:focusable="false" >
    </ListView>


</RelativeLayout>

row.xml:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/downloadFileName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"

        android:text="FILENAME" />

    <TextView
        android:id="@+id/percent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="%"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/downloadFileName"
        android:text="time" />

    <TextView
        android:id="@+id/data"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/time"
        android:text="data" />

    <TextView
        android:id="@+id/speed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/percent"
        android:text="speed"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ProgressBar
        android:id="@+id/downloadProgressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/speed" />

</RelativeLayout>

MainActivity.java

public class MainActivity extends FragmentActivity {

    SectionsPagerAdapter mSectionsPagerAdapter;
    ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.setTitle(null);

        // Create the adapter that will return a fragment for each of the three
        // primary sections of the app.
        mSectionsPagerAdapter = new SectionsPagerAdapter(
                getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager.setOffscreenPageLimit(2);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch(position){
            case 0:
                Fragment fragment = new DownloadingFragment();
                Bundle args = new Bundle();
                args.putInt(DownloadingFragment.ARG_SECTION_NUMBER, position + 1);
                fragment.setArguments(args);
                return fragment;
            case 1:
                Fragment fragment2 = new FinishedFragment();
                Bundle args2 = new Bundle();
                args2.putInt(FinishedFragment.ARG_SECTION_NUMBER, position + 1);
                fragment2.setArguments(args2);
                return fragment2;
            }
            return null;
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
            case 0:
                return getString(R.string.title_section1).toUpperCase();
            case 1:
                return getString(R.string.title_section2).toUpperCase();

            }
            return null;
        }
    }
    public static class DownloadingFragment extends ListFragment {

        public static final String ARG_SECTION_NUMBER = "section_number";

        public DownloadingFragment() {
        }

        @Override
        public View onCreateView (LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View V = inflater.inflate(R.layout.list, container, false);
            ListView dlistView = (ListView) V.findViewById(android.R.id.list);
            ((ViewGroup)container.getParent()).removeView(container);
            List<DownloadInfo> downloadInfo = new ArrayList<DownloadInfo>();
            downloadInfo.add(new DownloadInfo("File", 1000));
            DownloadInfoArrayAdapter diaa = new DownloadInfoArrayAdapter(getActivity().getApplication(),android.R.id.list, downloadInfo);

            dlistView.setAdapter(diaa);// Null point exception line 142!

        return dlistView;
        }
    }
    public static class FinishedFragment extends Fragment {
        public static final String ARG_SECTION_NUMBER = "section_number";

        public FinishedFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            // Create a new TextView and set its text to the fragment's section
            // number argument value.
            TextView textView = new TextView(getActivity());
            textView.setGravity(Gravity.CENTER);
            textView.setText(Integer.toString(getArguments().getInt(
                    ARG_SECTION_NUMBER)));
            return textView;
        }
    }

}

Downloadinfo.java

public class DownloadInfo {
    public enum DownloadState {
        NOT_STARTED, DOWNLOADING, COMPLETE
    }

    public DownloadInfo(String filename, Integer size) {
        super();
        mFilename = filename;
        mProgress = 0;
        mFileSize = size;
        mProgressBar = null;
        mPercent = 0;
        mTime = " ";
        mSpeed = 0;
        mData = " ";
    }

    private volatile DownloadState mDownloadState = DownloadState.NOT_STARTED;
    private final String mFilename;
    private volatile Integer mProgress;
    private final Integer mFileSize;
    private volatile ProgressBar mProgressBar;
    private volatile Integer mPercent;
    private volatile String mTime;
    private volatile Integer mSpeed;
    private volatile String mData;

    public ProgressBar getProgressBar() {
        return mProgressBar;
    }

    public void setProgressBar(ProgressBar mProgressBar) {
        this.mProgressBar = mProgressBar;
    }

    public Integer getProgress() {
        return mProgress;
    }

    public void setProgress(Integer mProgress) {
        this.mProgress = mProgress;
    }

    public String getFilename() {
        return mFilename;
    }

    public Integer getFileSize() {
        return mFileSize;
    }

    public Integer getPercent() {
        return mPercent;
    }

    public void setPercent(Integer mPercent) {
        this.mPercent = mPercent;
    }

    public String getTime() {
        return mTime;
    }

    public void setTime(String mTime) {
        this.mTime = mTime;
    }

    public Integer getSpeed() {
        return mSpeed;
    }

    public void setSpeed(Integer mSpeed) {
        this.mSpeed = mSpeed;
    }

    public String getData() {
        return mData;
    }

    public void setData(String mData) {
        this.mData = mData;
    }

    public DownloadState getDownloadState() {
        return mDownloadState;
    }

    public void setDownloadState(DownloadState mDownloadState) {
        this.mDownloadState = mDownloadState;
    }
}

DonwloadInfoArrayAdapter.java

public class DownloadInfoArrayAdapter extends ArrayAdapter<DownloadInfo> {

    //private final Context context;
    //private List<DownloadInfo> downloadinfo;
    public DownloadInfoArrayAdapter(Context downloadingFragment,int id,List<DownloadInfo> objects) {
        super(downloadingFragment, id,  objects);
        //this.context=downloadingFragment;
        //this.downloadinfo=objects;
        // TODO Auto-generated constructor stub
    }
    private static class ViewHolder {
        TextView downloadFilename;
        TextView speed;
        TextView time;
        TextView percent;
        TextView data;
        ProgressBar progressBar;
        DownloadInfo info;
      }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.d("downloadinfoarrayadapter", "lefutott");
        View row = convertView;
        DownloadInfo info = getItem(position);
        ViewHolder holder = new ViewHolder();
        if(null == row) {

            LayoutInflater inflater = (LayoutInflater)
                    getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate (R.layout.row, parent,false);

            holder.downloadFilename = (TextView) row.findViewById(R.id.downloadFileName);
            holder.data = (TextView) row.findViewById(R.id.data);
            holder.speed = (TextView) row.findViewById(R.id.speed);
            holder.time = (TextView) row.findViewById(R.id.time);
            holder.percent = (TextView) row.findViewById(R.id.percent);
            holder.progressBar = (ProgressBar) row.findViewById(R.id.downloadProgressBar);

            holder.info = info;

            row.setTag(holder);
          } else {
            holder = (ViewHolder) row.getTag();

            holder.info.setProgressBar(null);
            holder.info.setData(null);
            holder.info.setSpeed(null);
            holder.info.setTime(null);
            holder.info.setPercent(null);
            holder.info = info;
            holder.info.setProgressBar(holder.progressBar);
            holder.info.setData(holder.data.toString());
            holder.info.setSpeed(Integer.getInteger(holder.speed.toString()));
            holder.info.setTime(holder.time.toString());
            holder.info.setPercent(Integer.getInteger(holder.percent.toString()));

          }
        holder.downloadFilename.setText(info.getFilename().toString());
        holder.data.setText(info.getData().toString());
        holder.speed.setText(info.getSpeed().toString());
        holder.time.setText(info.getTime().toString());
        holder.percent.setText(info.getPercent().toString());
        holder.progressBar.setProgress(info.getProgress());
        holder.progressBar.setMax(info.getFileSize());
        Log.d("downloadinfoarrayadapter", "ez lefutott");
        info.setProgressBar(holder.progressBar);
        return row;
    }
}

edit:

The NPE issue solved, thanks to blackbelt, but the app run into another problem.
changed rows:

View V = inflater.inflate(R.layout.list, null);
ListView dlistView = (ListView) V.findViewById(R.id.dlist);

After that:

01-11 10:53:48.285: E/AndroidRuntime(3714): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

I tried to figure out which view is the concrete child, but i don’t know.

Edit:
This is the new stack:

    01-11 16:12:51.056: E/AndroidRuntime(2973): FATAL EXCEPTION: main
01-11 16:12:51.056: E/AndroidRuntime(2973): android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.content.res.Resources.getResourceName(Resources.java:1679)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at com.velsorange.filedownloader.MainActivity$DownloadingFragment.onCreateView(MainActivity.java:140)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.support.v4.view.ViewPager.populate(ViewPager.java:1012)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.support.v4.view.ViewPager.populate(ViewPager.java:881)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1366)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.View.measure(View.java:15513)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.View.measure(View.java:15513)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.View.measure(View.java:15513)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.View.measure(View.java:15513)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.Choreographer.doFrame(Choreographer.java:532)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.os.Handler.handleCallback(Handler.java:725)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.os.Looper.loop(Looper.java:137)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at android.app.ActivityThread.main(ActivityThread.java:5191)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at java.lang.reflect.Method.invokeNative(Native Method)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at java.lang.reflect.Method.invoke(Method.java:511)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-11 16:12:51.056: E/AndroidRuntime(2973):     at dalvik.system.NativeStart.main(Native Method)
  • 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-17T06:44:12+00:00Added an answer on June 17, 2026 at 6:44 am
    ListView dlistView = (ListView) V.findViewById(android.R.id.list); 
    

    should be

     ListView dlistView = (ListView) V.findViewById(R.id.dList);
    

    since you are declaring it with @+id/dList

    It is a lot code to go through. Next time you should show only relevant snippet of code.

     View V = inflater.inflate(R.layout.list, container, false);
    

    that’s wrong. Change it in:

     View V = inflater.inflate(R.layout.list, null);
    

    also return the V object instead of the list

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.