MemeCreator stuck on last step

0 Superman HC · October 24, 2015
So I have followed all the videos of bucky on meme creator for hours... and now when I am one step away it's showing error

package com.example.app4;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity implements TopSectionFragment.TopSectionListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    
    
// Gets called by topsectionfragment when button is clicked
    @Override
public void createMeme(String top, String bottom) {
// TODO Auto-generated method stub
bottom_section_fragment bottomFragment = (bottom_section_fragment) getSupportFragmentManager().findFragmentById(R.id.fragment2);
bottomFragment.setMemeText(top,bottom);
    }


@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}


It said the method getSupportFragmentManager() is undefined for the main activity... 
I have looked up for this on net and try to implement fragment activity and do it with getFragmentManager but in vain..

Please suggest something !!!

Post a Reply

Replies

Oldest  Newest  Rating
0 Gary Whitney · October 24, 2015
The code looks right.
Fragments weren't supported until Honeycomb so I am wondering what your min API is.
But then I notice you are extending Activity and not ActionBarActivity which requires import android.support.v7.app.ActionBarActivity;

The key to your problem is Activity does not have a getSupportFragmentManager() method it has a getFragmentManager() method.
0 Superman HC · October 25, 2015
thanks for your valuable comment... the minimum api i am using is froyo...
and the code doesn't support
android.support.v7 so i used android.support.v4 and it only supports extending Activity.
0 Amir Fahd Hadji Usop · October 26, 2015
That is because I suspect that you are importing the wrong library:

Instead of using,


import android.app.Fragment;



try using,


import android.support.v4.app.Fragment;



:)
  • 1

Java / Android Development

107,090 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator