# ERROR: The constructor "......" does not exist

**URL:** <https://discourse.processing.org/t/error-the-constructor-does-not-exist/40116>\
**Category:** Beginners\
**Created:** [December 11, 2022, 12:56am UTC](https://discourse.processing.org/t/error-the-constructor-does-not-exist/40116 "2022-12-11T00:56:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![onosecond](https://avatars.discourse-cdn.com/v4/letter/o/e274bd/32.png) [@onosecond](https://discourse.processing.org/u/onosecond)\
**Post date:** [December 11, 2022, 12:56am UTC](https://discourse.processing.org/t/error-the-constructor-does-not-exist/40116/1 "2022-12-11T00:56:16Z")

</div>

```auto
Question [] questions; 
PImage [] bg;
int nr_img=10;
int counter=0;
void setup(){
  size(600,600);
  
  String [] text=loadStrings("questions.txt");//load the file
  questions=new Question[text.length]; 
  for(int i=0;i<questions.length;i++){
    String [] q=(split(text[i],","));
    questions[i]=new Question(q[i+1]);
  }
}
class Question{
  String [] options;
  int qnumber;
  int score;
Question(String [] options_){
  options=options_;
  
}
  void showQuestion(){
   for(int i=0;i<10;i++){
      text(options[i],300,300);
    }
  }

```

Hi everyone!  
What I am trying to do here is use the questions from my text file which has 10 lines, so that I can show them on screen. I am using split to get a question per index using comma as a delimiter. I get the error that this constructor does not exist. While this is not close to done, it is what I have so far.  
I hope the code is in the right format.  
Any type of help would be greatly appreciated!  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![onosecond](https://avatars.discourse-cdn.com/v4/letter/o/e274bd/32.png) [@onosecond](https://discourse.processing.org/u/onosecond)\
**Post date:** [December 11, 2022, 1:49am UTC](https://discourse.processing.org/t/error-the-constructor-does-not-exist/40116/3 "2022-12-11T01:49:10Z")

</div>

Hello and thank you for responding!  
I am using text.length so that the size of my array of Question objects is set according to the number of lines on my file.  
The error does not appear when I use string instead of array of strings in the class attributes and constructor.  
Is there a different approach that will not give me this error?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 11, 2022, 1:53am UTC](https://discourse.processing.org/t/error-the-constructor-does-not-exist/40116/4 "2022-12-11T01:53:22Z")

</div>

Hello,

Minimal changes to your code:

```auto
Question [] questions; 
PImage [] bg;
int nr_img=10;
int counter=0;
void setup()
  {
  size(600,600);
  
  String [] text=loadStrings("questions.txt"); //load the file
  questions=new Question[text.length]; 
  for(int i=0;i<questions.length;i++)
    {
    String [] q=(split(text[i],","));
    questions[i]=new Question(q); // Instantiate with an array! :)
    }

  questions[0].showQuestion(); 
  questions[1].showQuestion(); 
  questions[2].showQuestion(); 
  }

class Question{
  String [] options;
  int qnumber;
  int score;
Question(String [] options_)
  {
  options=options_;
  }
  
  void showQuestion()
    {
      for(int i=0;i<options.length;i++)
      {
      println(options[i]);
      }
    }
  }

```

I took at guess at format (not content) of your text file based on your code.

Text file:

> who, what, where, why, when, how  
> 0, 1, 2, 3, 4, 5  
> 6, 7, 8, 9, 10

Output has leading spaces you can remove with _trim()_… see reference for this.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/7/8/78f41d90def9b96cf8fcf85e254f1e5b9eaf0735.png)

`:)`

---

<div class="post-metadata">

**Author:** ![onosecond](https://avatars.discourse-cdn.com/v4/letter/o/e274bd/32.png) [@onosecond](https://discourse.processing.org/u/onosecond)\
**Post date:** [December 11, 2022, 3:06am UTC](https://discourse.processing.org/t/error-the-constructor-does-not-exist/40116/5 "2022-12-11T03:06:00Z")

</div>

Thank you so much it finally works!
