Issue
I am overriding a method that returns a CharSequence and it returns charSequecence. I have also tried returning a String. Here is the code
public String getPageTitle(int position) {
return getResource().getString(R.string.tabla_del) + ": " + (position + 1);
}
Solution
There are, generally, three reasons to fail this:
The first one, no exists a Context. Solving this, you need to pass a context object to method that use it:
public String getPageTitle(Context context, int position) {
return context.getResource().getString(R.string.tabla_del) + ": " + (position + 1);
}
Context variable is passed from Activity/Fragment but it can be avoid if method exists inside a Activity/Fragment; there only need getContext() or getApplicationContext() method depends on if it's Activity or Fragment.
public String getPageTitle(int position) {
return getContext().getResource().getString(R.string.tabla_del) + ": " + (position + 1);
}
The second one, no exists R class imported. You should check if your class exists inside subpackages, for instance:
Your main package is com.example.androidapp it is described on AndroidManifest and gradle files. So, if your class exists on com.example.androidapp.configuration you need import R class from main package:
package com.example.androidapp.configuration
...
import com.example.androidapp.R;
...
public class Configuration {
...
}
The third one, no exists strings you need on strings file. Here you should create a strings files and add strings you need.
Answered By - Juan Castaño
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.