java - Creating a new class with similar functions as an ArrayList, errors in adding values? -


import java.util.arraylist;  public class sequence {  private arraylist<integer> values;  public void sequence(){          values = new arraylist<integer>();      }  public void addvalue(int ad){         this.values = values;         values.add(ad);               }  public string tostring(){         return values.tostring();     }  public static void main(string[] args) {     sequence = new sequence();     a.addvalue(1);     a.addvalue(2);     system.out.println(a.tostring()); } } 

i'm relatively new programming, bet silly question, cannot figure out why i'm getting error this. idea of assignment create class called sequence similar arraylist, , give new methods, can't method add new values arraylist. i'd appreciate help!

the reason why you're getting nullpointerexception because haven't defined constructor, instead have defined method called sequence. constructor not have return type, void , instead defined, in case, as:

public sequence() {      values = new arraylist<integer>(); } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -