I have a variable in the class "MainActivity" with the name modeNr, it is protected so it should be accessible from within the package, however whenever I try to alter it from a class in the same package it gives the error: "Non-static field 'modeNr' cannot be referenced from a static context". I use the following line to alter the variable:
MainActivity.modeNr = 1;
Any ideas on what the problem is and how to correct it?
you are trying to change non-static member from static function. you need to make that varible static as well or need to create object of that class. lets suppose,
class Test {
int node = 0;
static int node1 =10;
}
class changeNode {
public static void changeNode(){
new Test().node = somevalue;
//or you need to make node static and change like this
Test.node1 = some value
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments