Reputation: 1857
Hi I encountered this error when I created a custom backbone app for my application. What it does is to send to its parent constructor a target container where the fragment will be installed. The custom class is simply zero-arg constructor and supers an integer to its a parent which stores the targetContainer. But when I ran my application I get a runtime exception.
Here is my code:
Here is a custom class specific to the app I plan to build:
public class NoteActivity extends BackboneActivity
{
public NoteActivity()
{
super(R.id.fragmentContainer);
addFragment(new NoteFragment());
}
}
Now here is backbone app so I can add fragments at will. I want a dynamic control over the app and fragment using this class:
public class BackboneActivity extends ActionBarActivity
{
private FragmentManager fragmentManager;
private int targetContainer = -1;
public BackboneActivity(int target)
{
super();
targetContainer = target;
}
protected boolean addFragment(Fragment fragment)
{
if(fragment == null) return false;
fragmentManager.beginTransaction()
.add(targetContainer, fragment)
.commit();
return true;
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(targetContainer);
fragmentManager = getSupportFragmentManager();
}
}
I am still in the learning process for Android and Java and I have a bit of programming experience so I am not quite sure what I have been missing.
The error I get is access to Constructor is not allowed. Is this technically different than other post here which describes access to class not allowed?
I admit I feel so &&(& dumb with this error.
Thanks.
Upvotes: 1
Views: 922
Reputation: 49410
Can you not do something like:
public NoteActivity()
{
super();
addFragment(new NoteFragment());
}
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(targetContainer);
// you will have to put a getter/setter in BackboneActivity or change access modifiers
this.setTargetContainer(R.id.fragmentContainer);
fragmentManager = getSupportFragmentManager();
}
Upvotes: 1