I'm trying to create a custom LinearLayout (on Android), but I keep getting compiler errors when trying to use it in my main Activity class. The extended LinearLayout needs a Context passed to it by the constructor, but I don't know where to get that Context. All the examples I see show the passing of the this pointer from the Activity. What am I doing wrong?
Compiler Error
MyApp.java:15: cannot find symbol symbol: constructor BoardLayout(com.test.program.MyApp) location: class com.test.program.BoardLayout BoardLayout board = new BoardLayout(this); BoardLayout.java
public class BoardLayout extends LinearLayout { public void BoardLayout(Context context) { // initialisation code } public BoardLayout(Context context, AttributeSet attrs) { super(context, attrs); } } MyApp.java
public class MyApp extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); BoardLayout board = new BoardLayout(this); // Doesn't work! setContentView(board); } } Solution:
Looks like the problem was two issues.
- Constructors don't have type void (careless mistake on my part).
- Had to call "super(context)" as the first instruction in the constructor.