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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:31:43+00:00 2026-06-17T10:31:43+00:00

I am trying to pass my book issue number UrlPagerAdapter pagerAdapter = new UrlPagerAdapter(this,items,issue);

  • 0

I am trying to pass my book issue number

UrlPagerAdapter pagerAdapter = new UrlPagerAdapter(this,items,issue);

and then in my UrlPagerAdapter class, I logged the issue value in some methods to test out if my value has been successfully passed and yes, it did. but when i tried to create my own method to log the value, it doesn’t work!

public int getIssueNumber(){
    Log.d("issue - getIssueNumber()", String.valueOf(issue));
    return issue;
}

this is my urlpageradapter class

public class UrlPagerAdapter extends PagerAdapter {

    private List<String> mResources;
    private Context mContext;
    private int issue;

    public UrlPagerAdapter(Context context, List<String> resources, int issue){
        this.mResources = resources;
        this.mContext = context;
        this.issue = issue;
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        super.setPrimaryItem(container, position, object);
        ((GalleryViewPager)container).mCurrentView = ((UrlTouchImageView)object).getImageView();
    }


    @Override
    public Object instantiateItem(View collection, int position){
        UrlTouchImageView iv = new UrlTouchImageView(mContext);
        iv.setUrl(mResources.get(position));
        iv.setLayoutParams(new Gallery.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
        ((ViewPager) collection).addView(iv, 0);
        return iv;


    }

    @Override
    public void destroyItem(View collection, int position, Object view){
        ((ViewPager) collection).removeView((View) view);
    }

    @Override
    public int getCount(){
        return mResources.size();
    }

    public int getIssueNumber(){
        return issue;
    }

    @Override
    public boolean isViewFromObject(View view, Object object){
        return view.equals(object);
    }

    @Override
    public void finishUpdate(View arg0){
    }

    @Override
    public void restoreState(Parcelable arg0, ClassLoader arg1){
    }

    @Override
    public Parcelable saveState(){
        return null;
    }

    @Override
    public void startUpdate(View arg0){
    }

}

and in another class, i tried to test out the method. my application crashes!

public class UrlTouchImageView extends RelativeLayout {
    protected ProgressBar mProgressBar;
    protected TouchImageView mImageView;

    protected Context mContext;
    UrlPagerAdapter pagerAdapter;
    String[] mImageIds;
    ArrayList<String>  mStringList= new ArrayList<String>();

    public UrlTouchImageView(Context ctx)
    {
        super(ctx);
        mContext = ctx;

        init();

    }
    public UrlTouchImageView(Context ctx, AttributeSet attrs)
    {
        super(ctx, attrs);
        mContext = ctx;
        init();
    }
    public TouchImageView getImageView() { return mImageView; }

    protected void init() {


        int v = pagerAdapter.getIssueNumber();
        Log.d(" v - ImageLoadTask", String.valueOf(v));

        mImageView = new TouchImageView(mContext);
        LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        mImageView.setLayoutParams(params);
        this.addView(mImageView);
        mImageView.setVisibility(GONE);

        mProgressBar = new ProgressBar(mContext, null, android.R.attr.progressBarStyleHorizontal);
        params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.CENTER_VERTICAL);
        params.setMargins(30, 0, 30, 0);
        mProgressBar.setLayoutParams(params);
        mProgressBar.setIndeterminate(true);
        this.addView(mProgressBar);
    }

    public void setUrl(String imageUrl)
    {
        new ImageLoadTask().execute(imageUrl);
    }
    //No caching load
    public class ImageLoadTask extends AsyncTask<String, Integer, Bitmap>
    {
        //RETRIEVES LINK FROM GALLERYACTIVITY
        //READ MNT/SDCARD/....

        @Override
        protected Bitmap doInBackground(String... strings) {
            //String url = strings[0];

            Bitmap bm = null;
            try {
            File strPath = new File(Environment.getExternalStorageDirectory() + "/issue0");
            int lists = strPath.listFiles().length; 
            Log.d("number of items in array ",String.valueOf(lists));

            File yourDir = new File(strPath, "");
            for (File f : yourDir.listFiles()) {
                if (f.isFile())
                {
                    String name = f.getName();
                    String v = strPath + "/" + name;
                    mStringList.add(v);
                }
            }

            mImageIds = new String[mStringList.size()];
            mImageIds = mStringList.toArray(mImageIds);

                bm = BitmapFactory.decodeFile(mImageIds[0]);

            } catch (Exception e) {
                e.printStackTrace();
            }

            return bm;
        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            mImageView.setImageBitmap(bitmap);
            mImageView.setVisibility(VISIBLE);
            mProgressBar.setVisibility(GONE);
        }
    }
}

this is my logcat output

01-14 10:59:45.130: E/AndroidRuntime(21843): FATAL EXCEPTION: main
01-14 10:59:45.130: E/AndroidRuntime(21843): java.lang.NullPointerException
01-14 10:59:45.130: E/AndroidRuntime(21843):    at com.example.touchview.UrlTouchImageView.init(UrlTouchImageView.java:67)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at com.example.touchview.UrlTouchImageView.<init>(UrlTouchImageView.java:53)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at com.example.gallery.UrlPagerAdapter.instantiateItem(UrlPagerAdapter.java:58)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:801)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.support.v4.view.ViewPager.populate(ViewPager.java:930)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.support.v4.view.ViewPager.populate(ViewPager.java:881)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1366)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.view.View.measure(View.java:12723)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1017)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:555)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.view.View.measure(View.java:12723)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.view.View.measure(View.java:12723)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.view.View.measure(View.java:12723)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.view.View.measure(View.java:12723)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.os.Looper.loop(Looper.java:137)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at android.app.ActivityThread.main(ActivityThread.java:4446)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at java.lang.reflect.Method.invokeNative(Native Method)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at java.lang.reflect.Method.invoke(Method.java:511)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-14 10:59:45.130: E/AndroidRuntime(21843):    at dalvik.system.NativeStart.main(Native Method)

What went wrong?

  • 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-17T10:31:45+00:00Added an answer on June 17, 2026 at 10:31 am

    Your method UrlTouchImageView.init() (which is called in constructor) accesses the value of the field pagerAdapter in this line:

    int v = pagerAdapter.getIssueNumber();
    

    but the value of pagerAdapter is never set. I believe this is the cause of your NPE. You must set this field to a non-null value. Either in constructor or in init() method. Passing UrlPagerAdapter in constructor can be done like so:

    1. In UrlTouchImageView pass the value in constructor:

      public UrlTouchImageView(Context ctx, UrlPagerAdapter pagerAdapter) {
          super(ctx);
          mContext = ctx;
          this.pagerAdapter = pagerAdapter;
          init();
      }
      
    2. In UrlPagerAdapter.instantiateItem() pass this:

      UrlTouchImageView iv = new UrlTouchImageView(mContext, this);
      

    This is also the cause of your issue number not being logged – since the NPE is thrown before the call to getIssueNumber(), the Log.d() is never called.

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

Sidebar

Related Questions

I am trying pass class as value in hashmap. I need to get the
Trying to pass a string argument to a function, which will then be used
im trying to pass two parameters to a function, i being an int value
I am trying to learn some PHP using the book titled PHP for Absolute
I'm doing a homework and I'm trying to follow a class diagram. In Book.cpp
Trying to pass a form value into a global var to be use in
Im trying to pass some values into a text box from a child page
Trying to pass in a value for a input in a form seems to
A book I have says this: a) Place each value of the one-dimensional array
Trying to pass the root of my Binary Search Tree (BST) to the UI

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.