My code is:
public static void ToastMemoryShort (Context context) {
CharSequence text = getString(R.string.toast_memoryshort); //error here
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
return;
}
but I'm getting "Cannot make a static reference to the non-static method getString(int) from the type Context" in Eclipse. I'm trying to get ready for localising my app (getting all the hard coded strings into resources), so where I have:
getString(R.string.toast_memoryshort)
I previously had a hard coded string which was fine.
I'm not sure what's going on here (Java noob). Can anyone enlighten me please?
Many thanks
Baz
Just use this instead:
From http://developer.android.com/reference/android/widget/Toast.html
You should change
for:
The
getString
function is implemented in Context#getString(int)Change to
You could make your toast more generic like this:
Then just call when you need like this:
or by referring to strings.xml like this: