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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:58:54+00:00 2026-05-30T01:58:54+00:00

I have an overriding Object class (Guide) with a subclass (Session). public class Guide

  • 0

I have an overriding Object class (Guide) with a subclass (Session).

public class Guide
  private class Session
     ...

  ArrayList<Session> sessions;

  public ArrayList<Session> getSessionsByTrack(int n) {
    ArrayList<Session> tracks = new ArrayList<Session>();
    for (Session session : this.sessions) {
        if (session.track == n) {
            tracks.add(session);
        }
    }
    Collections.sort(tracks); // sort by start and end time.
    return tracks;
}

I have a ListAdapter that should handle the list to display a 2-line listview:

public class SessionListAdapter extends BaseAdapter {
    private ArrayList<Session> sessions;
    //private Session[] sl;
    private LayoutInflater mInflater;

    public SessionListAdapter(Context context, ArrayList<Session> sl) {
        sessions = sl;
        mInflater = LayoutInflater.from(context);
    }
    public int getCount() {
        return sessions.size();
    }
    public Object getItem(int position) {
        return sessions.get(position);
    }
    public long getItemId(int position) {
        return position;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.session_two_line_list, null);
            holder = new ViewHolder();
            holder.title = (TextView) convertView.findViewById(R.id.session_title);
            holder.time = (TextView) convertView.findViewById(R.id.session_time);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.title.setText(sessions.get(position).getTitle());
        holder.time.setText(sessions.get(position).getTimeSpan());
        return convertView;
    }

    static class ViewHolder {
        TextView title;
        TextView time;
    }
}

In my main activity I am trying to display the list using the list adapter:

...
this.lv1 = (ListView) view.findViewById(R.id.SessionListView);

        // get sessions
        this.sessionList = Guide.getSessionsByTrack(0); // errors here and complains that this method must be static
        final SessionListAdapter lv1adapter = new SessionListAdapter(this, this.sessionList);
        lv1.setAdapter(lv1adapter);
...

My only problem in the Guide.getSessionsByTrack method doesn’t allow me to utilize this.sessions while that method is static. Must the sessionList be static, what if I wanted to update the list, shouldn’t this not be static?

This little hiccup is the only thing keeping me from my goal and any help would be greatly appreciated.

  • 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-05-30T01:58:54+00:00Added an answer on May 30, 2026 at 1:58 am

    You have two problems there.

    Firstly doing something like this…

    Guide.getSessionsByTrack(...);
    

    …means you are attempting to reference a method by it’s parent class name rather than via a referenced (and instantiated) instance of a Guide object. In this case, yes, the method must be declared as static because you’re not explicitly instantiating an instance of the Guide class.

    The second problem you have is that getSessionsByTrack(...) isn’t actually a method that belongs to the Guide class itself, rather it belongs to a private inner class (Session). Basically this method isn’t reachable anyway.

    You need to fix both of those before it will work. Either create a public static method in your Guide class which in itself calls a static method in the Session class or create an instance of Guide and provide a similar get method that can be accessed publicly.

    Also you seem to have a misunderstanding about static in that you think it means things cannot be updated. That would be final (in other words ‘constant’) the use of static has a different meaning. I’d suggest you read up on the Java final and static usage.

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

Sidebar

Related Questions

I have a class called Object : class Object { public: Vector pos; float
This is my scenario. I have a generic class: public class Tuple<T> extends ArrayList<T>
I have the following base class: abstract class Base { public abstract object Var
I have two classes : import android.cla; public class CW { public static void
So I have this: class Parent(object): def __init__(self, val): print 'enter Base init' self._set_x(val)
I have this class. public class Foo { public Guid Id { get; set;
Below is a sample implementation of overriding Object.Equals() for an entity base class from
I have a class where I want 'each' to yield another custom object, so
I have some classes layed out like this class A { public virtual void
I have the following code: class Test(object): _spam = 42 @classmethod def get_spam(cls): cls._spam

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.