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

  • Home
  • SEARCH
  • 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 9183191
In Process

The Archive Base Latest Questions

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

I got 3 classes. A main class, globalVariable class, and an item class. I

  • 0

I got 3 classes.
A main class, globalVariable class, and an item class.

I try to set an ArrayList in the main class. And I want to read it out in the item class.
This is what I tried:

Main:

for (int i = data.size()-1; i >= 0; i--){
    if (str_tv.contains(data.get(i).getCaption())){
        //TODO data.remove();
        String str_i = String.valueOf(i);
        checkedArray.add(str_i);

    }
}
System.out.println("MainActivity");
global.setArrList(checkedArray);
System.out.println("size = "+global.getArrList().size());

global.setArrlList does work here. Also global.getArrList works here (I get my size).

Now I try to get it from the item class:

System.out.println("Item Class");
System.out.println("size = "+global.getArrList().size());   <--gives NullPointer

But here, it isn’t working, then it gives a NullPointer.

This is my Global class:

ArrayList<String> arrList;

public ArrayList<String> getArrList() {
    return arrList;
}

public void setArrList(ArrayList<String> arrList) {
    this.arrList = arrList;
}

I did check if he maybe tried to get the ArrayList first instead of setting it. But he shows the System.out.println("MainActivity"); before the one in the item class.

Why does it give a NullPointer? What am I missing?

Logcat:

01-24 11:02:04.755: E/AndroidRuntime(30097): FATAL EXCEPTION: main
01-24 11:02:04.755: E/AndroidRuntime(30097): java.lang.NullPointerException
01-24 11:02:04.755: E/AndroidRuntime(30097):    at com.dlv.GewasBescherming3.ItemListAdapter.getView(ItemListAdapter.java:47)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.AbsListView.obtainView(AbsListView.java:2035)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.ListView.makeAndAddView(ListView.java:1772)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.ListView.fillDown(ListView.java:672)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.ListView.fillFromTop(ListView.java:732)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.ListView.layoutChildren(ListView.java:1625)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.AbsListView.onLayout(AbsListView.java:1865)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.View.layout(View.java:11278)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.View.layout(View.java:11278)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.View.layout(View.java:11278)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.View.layout(View.java:11278)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.View.layout(View.java:11278)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.os.Looper.loop(Looper.java:137)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at android.app.ActivityThread.main(ActivityThread.java:4575)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at java.lang.reflect.Method.invokeNative(Native Method)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at java.lang.reflect.Method.invoke(Method.java:511)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
01-24 11:02:04.755: E/AndroidRuntime(30097):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
01-24 11:02:04.755: E/AndroidRuntime(30097):    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-17T18:44:34+00:00Added an answer on June 17, 2026 at 6:44 pm

    Actually,

    ArrayList<String> arrList; is null.

    Just declare it like ArrayList<String> arrList = new ArrayList<String>();

    Update:

    Actually both Main and Item classes have different global object so it can not reference to same arrList.

    I would be better to add:

    public static ArrayList<String> arrList = new ArrayList<String>();
    

    in Global class and use it like this:

    Global.arrList.size();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this example Parent class Vehicle Child Classes Car , Motorcycle , &
I've got this MustInherit class called ViewerElement, from which derive classes like ViewerLine, ViewerImage,
I got 2 classes in my project. The first class(main) have a listview and
I've got two classes, Main and C2DMReceiver -- I want the receiver to obviously
I've got 3 classes namespace ServerPart { public class Car { } public class
The problem is like that: a school has got different classes. Each class has
I've got a two classes (pupil, class) in a Roo-project and their scaffolded views.
I've got following Java classes defined: mac-grek:javajunk grek$ cat A\$B.java class A$B {} mac-grek:javajunk
So here's what I got in a nutshell. I have a base item class
I've got two classes: MAIN and DBCONNECT DBCONNECT has all the coding including the

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.