java - Trouble referencing values from array -
i have bit of issue. right now, part of chemistry program, have:
public static substance na; public static substance br; public static substance nabr; public static substance[][] combinations = { {nabr, nacl}, {na , na }, {br , cl }}; combinations[0][0] = new compound(550); addcombination(combinations[0][0] , combinations[1][0], combinations[2][0]); the goal here add combination uses na , br make nabr. unfortunately, program seems referencing "combinations[1][0]" , "combinations[2][0]" own variables instead of "na" , "br" meant reference. if substitute values "na" , "br" respectively, runs charm!... ideas on how make array recognized referencing pre-initialized "na" , "br" instead of ones in array?
any appreciated! thank in advance!
from code can assume have initialized "na" , "br" after delcaring
public static substance[][] combinations = { {nabr, nacl}, {na , na }, {br , cl }}; if initalize "na" , "br" @ top of code notice works fine, because combinations declared when 2 variables not references not exist. try this
public static substance na = new substance(...); public static substance br = new substance(...); public static substance nabr = new substance(...); public static substance[][] combinations = { {nabr, nacl}, {na , na }, {br , cl }}; and should work.
Comments
Post a Comment