0

Here is my main:

package com.example.frags;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;


public class NewMessage extends FragmentActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_message);

        //Set new fragment
        FragA fragA = new FragA();
        FragmentTransaction transaction = getSupportFragmentManager()
                .beginTransaction();
        transaction.add(R.id.container_id, fragA);
        transaction.commit();

    }


}

My FragA class:

package com.example.frags;


import android.os.Bundle;
import android.text.style.SuperscriptSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class FragA extends android.support.v4.app.Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.choose_pill_frag, container, false);
    }
}

This problem is very similar to a problem I had a few days ago, but I'm applying that solution to this application and I still can't get it to work.

I'm getting a red line under .add with the message saying The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, fragA)

This is aggravating because in another sample application I have this code written. Which looks identical, but it works!

Community
  • 1
  • 1
EGHDK
  • 17,818
  • 45
  • 129
  • 204
  • Post your `FragA` class, I'd bet you forgot to import `android.support.v4.app.Fragment;` in it – Barak Jul 29 '12 at 16:05
  • https://stackoverflow.com/questions/11619573/fragment-add-or-replace-not-working Heres your solution! Cheers. – AntoMNE Jun 29 '18 at 12:28

1 Answers1

5

Hmm... I just did a clean, deleted my R.java and restarted eclipse. And now it works. Oh boy.

EGHDK
  • 17,818
  • 45
  • 129
  • 204
  • 2
    You've gotta love eclipse (she says sarcastically). I hope by now (almost 2 years later) you've switched to beautiful Android Studio :) – marienke Mar 13 '15 at 11:51