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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:02:58+00:00 2026-06-12T19:02:58+00:00

I am new to Android, know a little JAVA, but i want to learn

  • 0

I am new to Android, know a little JAVA, but i want to learn and i keep doing tutorials. The idea of what i want to do is the following:
I have a rendered menu, for example:
1. BIRDS
2. ROCKS
3. PLANTS
and when I press BIRDS I want to show pictures and a small description. The id’s of the images and the description I keep in a xml. Like this:

<signs>
    <sign id="1_1" category="1">
        <name>desc1</name>
    </sign>
    <sign id="1_2" category="1">
        <name>desc2</name>
    </sign>
    <sign id="1_3_1" category="1">
        <name>desc3</name>
    </sign>
    <sign id="1_3_2" category="1">
        <name>desc4</name>
    </sign>
</signs>

the picture goes like sign_1_1.png, sign_1_2.png in drawables.

I made the gallery, it is showing, the description and images also are visible. I made that on image gallery Selected image to show the corresponding description in a TextView.
But when I tap i get a FATAL EXCEPTION:

E/AndroidRuntime(22141): FATAL EXCEPTION: main
E/AndroidRuntime(22141): java.lang.NullPointerException
E/AndroidRuntime(22141): at apcmag.examples.singleSignListItem$ImageAdapter.getView(singleSignListItem.java:117)
E/AndroidRuntime(22141):    at android.widget.Gallery.makeAndAddView(Gallery.java:849)
E/AndroidRuntime(22141): at android.widget.Gallery.fillToGalleryRightLtr(Gallery.java:803)
E/AndroidRuntime(22141):    at android.widget.Gallery.fillToGalleryRight(Gallery.java:747)
E/AndroidRuntime(22141):    at android.widget.Gallery.layout(Gallery.java:656)
E/AndroidRuntime(22141):    at android.widget.Gallery.onLayout(Gallery.java:351)
E/AndroidRuntime(22141):    at android.view.View.layout(View.java:13754)
E/AndroidRuntime(22141):    at android.view.ViewGroup.layout(ViewGroup.java:4362)

The code is:

package apcmag.examples;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


public class singleSignListItem extends Activity
{

    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

        this.setContentView(R.layout.single_sign_gallery);

        Gallery g = (Gallery) findViewById(R.id.gallery);

        final Intent i = getIntent();
        final String REGEX = "/%%/";

        String product = i.getStringExtra("product");

        setTitle(product);

        g.setAdapter(new ImageAdapter(this));

        g.setOnItemSelectedListener(new OnItemSelectedListener() {
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                String [] products = i.getStringExtra("product_text").split(REGEX);
                Toast.makeText(singleSignListItem.this, ""+position, Toast.LENGTH_SHORT).show();
                TextView show_intro = (TextView) findViewById(R.id.show_intro);
                show_intro.setText(""+products[position]);
            }

            public void onNothingSelected(AdapterView<?> parent)
            {
                // TODO Auto-generated method stub

            }
        });
    }

    public class ImageAdapter extends BaseAdapter {
        int mGalleryItemBackground;
        private Context mContext;


//        private Integer[] mImageIds = {
//                R.drawable.sign_1_1,
//                R.drawable.sign_1_1,
//                R.drawable.sign_1_1,
//                R.drawable.sign_1_1
//        };

        private Integer[] mImages = takePhotos();

        public Integer[] takePhotos (){
            Intent g = getIntent();
            String Reg = "/%%/";
            String Reg2 = "_%_";

            String dataList = g.getStringExtra("product_text");
            String [] datastring = dataList.split(Reg);

            Integer[] imageResource = new Integer[20];

            String[] dd = null;

            for(int k = 0; k<datastring.length;k++){
                dd = datastring[k].split(Reg2);

            String imagename = "sign_"+dd[0];

            imageResource[k] = getResources().getIdentifier(imagename, "drawable", getPackageName());

            }

            return imageResource;

        }

        public ImageAdapter(Context c) {
            mContext = c;
            TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
            mGalleryItemBackground = a.getResourceId(
                    R.styleable.HelloGallery_android_galleryItemBackground, 0);
            a.recycle();
        }

        public int getCount() {
            return mImages.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView i = new ImageView(mContext);

            i.setImageResource(mImages[position]);
            i.setLayoutParams(new Gallery.LayoutParams(115, 200));
            i.setScaleType(ImageView.ScaleType.FIT_XY);
            i.setBackgroundResource(mGalleryItemBackground);

            return i;
        }
    }

}

I can’t get what the problem is for hours, and i have some ideas that it might be here:

 i.setLayoutParams(new Gallery.LayoutParams(115, 200));

but i am not so sure what to do

UPDATE

Actually i found the problem:

On Line 77 I was Initializing ImageResource with size 20

Integer[] imageResource = new Integer[20];

but the splited datastring had just 4 elements

String [] datastring = dataList.split(Reg);

so mImages variable

 private Integer[] mImages = takePhotos();

would have 20 elements from which 16 would be null
and in the end

i.setImageResource(mImages[position]);

it could not render the null elements and it crashed.

So there i have another question:

If i don’t know the size of the posible Integer[] how do I initiliaze and push in it elements ? With List ?

  • 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-12T19:02:59+00:00Added an answer on June 12, 2026 at 7:02 pm

    Actually i found the problem:

    On Line 77 I was Initializing ImageResource with size 20

    Integer[] imageResource = new Integer[20];

    but the splited datastring had just 4 elements

    String [] datastring = dataList.split(Reg);
    

    so mImages variable

     private Integer[] mImages = takePhotos();
    

    would have 20 elements from which 16 would be null and in the end

    i.setImageResource(mImages[position]);
    

    it could not render the null elements and it crashed.

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

Sidebar

Related Questions

I am new iOS development but I know android at eclipse. For example I
I'm new to programming with accelerometers on Android. I want to know how fast
I'm new to Android. I know a little about JSON parsing in Android. I'm
I am a little new to android development. I know that network activity and
I'm new here on stackoverflow. I have a little problem with my Android app,
I would know if there is the possibility to create a new Android Activity
I know that eclipse can do this, can Intellij via the new Android support
Hi i am new to android programming and i would like to know how
I know this is the list of permissions in android Is there any new
i am creating a new android application.i am using the table layout. I have

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.