# Referencing a class using a string stored in another class?

**URL:** <https://discourse.processing.org/t/referencing-a-class-using-a-string-stored-in-another-class/14268>\
**Category:** Coding Questions\
**Created:** [September 29, 2019, 8:12am UTC](https://discourse.processing.org/t/referencing-a-class-using-a-string-stored-in-another-class/14268 "2019-09-29T08:12:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inertia\_Squared](https://avatars.discourse-cdn.com/v4/letter/i/ce7236/32.png) [@Inertia\_Squared](https://discourse.processing.org/u/Inertia_Squared)\
**Post date:** [September 29, 2019, 8:12am UTC](https://discourse.processing.org/t/referencing-a-class-using-a-string-stored-in-another-class/14268/1 "2019-09-29T08:12:47Z")

</div>

I’m having trouble getting a class to reference a variable from another class using a string, it gives me the error ‘that the global variable “variableName” does not exist.’

How could I get this to work? For an example of what I’m trying to do I’ll see if I can write a bit of pseudo code with all the important bits.

```auto
//Class to grab the variable from
class main{
int class1Value;
main(int c1){
class1Value=c1;
}
}

//the class member to be referenced from main is input in 'inputString'
class grabber{
String refString;
int class2Value;
grabber(String inputString){
 refString=inputString;
}
void update(){
class2Value = refString.class1Value;
}
}

```

Any way I can do this without any errors?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 29, 2019, 11:02am UTC](https://discourse.processing.org/t/referencing-a-class-using-a-string-stored-in-another-class/14268/2 "2019-09-29T11:02:49Z")

</div>

imo make a hashMap in main and in grabber use the String as a value to get the value from the hashMap

see reference
