Nonstatic variable xx cannot be accessed in a static context ---Help Needed Urgently

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • uhdam
    New Member
    • Mar 2009
    • 50

    Nonstatic variable xx cannot be accessed in a static context ---Help Needed Urgently

    Hi

    I am unable to access a non static variable in a static context

    The variable is an arrayList and in a separate file

    I cannot change the corresponding non-static class into static class

    Please help me to resolve this problem

    I have also tried using getter method
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by uhdam
    Hi

    I am unable to access a non static variable in a static context

    The variable is an arrayList and in a separate file

    I cannot change the corresponding non-static class into static class

    Please help me to resolve this problem

    I have also tried using getter method
    Take it easy; non-static variables belong to an object, an instantiation, of the class. If you don't have an object, you don't have it's non-static variable; e.g. a Person instance has an age; if you don't have a Person object you don't have an age.

    kind regards,

    Jos

    Comment

    • uhdam
      New Member
      • Mar 2009
      • 50

      #3
      Thankyou sir,

      But when i created an instance for that nonstatic class and accessed through that instance i am getting the ArrayList size as zero.

      Comment

      • uhdam
        New Member
        • Mar 2009
        • 50

        #4
        Please Reply soon sir... I am in need of it badly...

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by uhdam
          Thankyou sir,

          But when i created an instance for that nonstatic class and accessed through that instance i am getting the ArrayList size as zero.
          Top level classes (not nested) can't be non-static or static; they just exist. I don't undrerstand your question. And where does that ArrayList come in?

          kind regards,

          Jos

          ps. no need to try to rush us.

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            It would be better if you shown us the code.
            Please show us the code ;)

            Comment

            Working...