Android - Cannot Make A Static Reference To The Non-static Field
The string title cannot be static because of the intent.. The string URL has to be static for the usage of it.. This means i get the error when i try to add a non-static string to
Solution 1:
If you really do need to keep your string static and final you could do
staticfinalStringURL="http://csddata.site11.com/dynamic.php?cat=%s";
Intenti= getIntent();
Stringtitle= i.getStringExtra("title");
StringfinalUrl= String.format(URL,title);
Solution 2:
This wont work because you will be getting value of title
when the present activity is launched.
The String URL is static & final. Static variables are initialized only once , at the start of the execution . These variables will be initialized first, before the initialization of any instance variables. Declaring the field as 'final' will ensure that the field is a constant and cannot change.
Intenti= getIntent();
Stringtitle= i.getStringExtra("title");
StringURL="http://csddata.site11.com/dynamic.php?cat=" + title;
Your code must fine now!!
Post a Comment for "Android - Cannot Make A Static Reference To The Non-static Field"