Question
As defined in the pseudo-code below, why does an inherited public method (setContentView
) of a parent class (MyCustomClassA
) defined in a separate package (packageB
) not resolve despite the public methods directly defined in said parent class (myPublicMethod
) do resolve?
As both myPublicMethod
and setContentView
are public methods, I'm quite confused as to why one is able to resolve while the other is not.
Minimal Example Pseudo Code
A summary of the hierarchy is shown in the pseudo-code below as well as comments describing the tooltips and errors shown by Android Studio:
package packageA;
public abstract class BaseClass extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState)
setContentView(layoutID); // Tooltip shows inheritance from android.app.Activity public void setContentView(@LayoutRes int layoutResID)
}
}
package packageB;
import packageA.BaseClass
public abstract class MyCustomClassA extends BaseClass{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState)
setContentView(layoutID); // Tooltip shows inheritance from android.app.Activity public void setContentView(@LayoutRes int layoutResID)
}
}
package packageB;
import packageB.MyCustomClassA
public abstract class MyCustomClassB extends MyCustomClassA{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState)
setContentView(layoutID); // Tooltip shows inheritance from android.app.Activity public void setContentView(@LayoutRes int layoutResID)
myPublicMethod(); // Tooltip shows this resolves to packageB.MyCustomClassA
}
public void myPublicMethod() {
}
}
package packageC;
import packageB.MyCustomClassA
public abstract class MyCustomClassC extends MyCustomClassA{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState)
setContentView(layoutID); // Error: Cannot resolve method 'setContentView' in MyCustomClassC
myPublicMethod(); // Tooltip shows this resolves to packageB.MyCustomClassA
}
}
What have I tried so far:
- Using Android Studio I Ctrl+click the parent classes and verify that they are all pointing to the correct classes.
- I Build -> Clean Project and Invalidate Caches and Restart to ensure nothing in the Cache is outdated.
- I created a dummy class
MyCustomClassB
to test whether thesetContentView
method would be resolvable within the same package. It does resolve. This led me to think it might be a package/protected or otherwise access issue, but assetContentView
is a public method in Activity, I'm stuck for additional troubleshooting ideas. - Read this , this, and this among several others related to inheritance, and everything I read only further confirms that this should be possible.
Is it possible this is gradle related? I've gone through the project and app level gradle files in great detail as well, trying to eliminate any possible duplicate dependencies, or things that might cause aliasing, but apart from that I've hit a wall for ideas. Any other ideas of where to continue looking for an error or can you explain why this fundamentally doesn't work (i.e. this is not an error in the code, but an error in my understanding of inheritance)?