Reputation: 107
I'm really stuck on this error (below):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vehiclerecall);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
I have the container referenced correctly to XML layout (below):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container"
tools:context="com.customerautomotivenetwork.VehicleRecall"/>
But I keep getting an error of cannot resolve method for PlacehlderFragment, any idea of what I'm doing wrong?
Upvotes: 3
Views: 3579
Reputation: 21
I had to import android.support.v4.app.Fragment to fix this problem.
In my case I was using minSdkVersion 8 and I had created a Activity class java > Package > Acitivity > BlankActivity. This created activity class had a inner class public static class PlaceholderFragment extends Fragment. This inner class was used in onCreate() in
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
}
}
Upvotes: 1
Reputation: 3562
Fragment
In your file PlaceholderFragment.java
, first make sure you extend Fragment
:
public class PlaceholderFragment extends Fragment { //...
Then, check the imports at the beginning of that file. There should be the line:
import android.app.Fragment;
and NOT the line:
import android.support.v4.app.Fragment;
Try not to mix "normal" and "v4" Fragments, they have the same name and do the same things but they are actually different classes.
Upvotes: 3