publicvoid getobjrecipie(String compare)
{
int num = 0;
try {
for (recipie recipes: objlist)
{
num++;
if (recipes.getname().equals(compare))
{
break;
}
}
}
catch (Exception e)
{
System.out.printf("nah we don't have that, or ... %s", e);
}
objlist.get(num).printrecipie();//this is wrong, it works but i think its not correct, that and catch is called :/
}
}
@LB do you know why i get an error "non static method cannot be referenced from static context?" I solved this before by having said thing in a function, this time its i a function :/ and if i take off extends it says cannot resolve, i guess its inherited nothing, oh dear bended head its late i need sleep and WAY more practice.
Im trying to convert the problem into c++ness so i can solve it in mah head
For what line of code does it say that? It sounds like you're trying to call an instance method (a method without the static qualifier, hence a non-static method) via the name of the class (which is a static context) instead of via the name of an object or 'this' (which is an instance/non-static context)
This is why we dont ask java problems in a c++ forum, people arnt as good at it :P
Eh! Look at post # 2 in this thread. There're already Java classes for what you're trying to accomplish -- no need to make your own (based on your stated goal).
* Don't take it personally, but the standard implementations (minus certain hack-jobs therein) are generally better to use than hand rolled randoms.
@devonrevenge the main method in Java is Static, so everything you want to call from it also has to be Static. Static is an infectious disease, remember?
You don't need to use any static besides one in main.
@Luc Lieber
Static does not belong to the OOP world. While it may have some good use cases - to implement singletons reliably or static constants or static (stateless) utilities methods, it is like goto in structural programming. The better your language is at OOP, the less you need static (Scala dropped static from Java in favor of native support for singletons, Javascript also doesn't have it - programmers are very happy with lack of static).
In most cases appearance of static state in your code means designers were lazy and didn't do the architecture well enough.
@Luc Lieber, I havn't learnt hash and map stuff yet, guess it was already time, You know i looked at that and thought i would learn it later, Bucky didnt let me in on that secret did he, nooh, he kept it to himself >:(
Can you help me finish this hackish hackjob tho, or is it impossible?
yeah theres no way i could use the objectlist if eveything starts being static because theres an error.
Im not sure if i have perfectly grasped static now :/