I am making a simple memegenerator app where user should enter text for the bottom and top field and that text will be added on the bottom and top section of the picture. Since I want to keep the app simple I have used only one fixed image for Meme.
I have used two fragments. One is for the Edittext areas and other is for the viwtext areas (where the etxt will be attached on the picture). In order to glue them together I have created interface which also gets called in my mainActivity's java file. Now the problem is in the following lines of code in my main java class. Here the method memeGen
is the main brain for this app. Inside it I am trying to find one of the fragment by it's id. But it seems thst its not finding that resourse.
public void memeGen(String top, String bottom) {
BottomSectionJava bjs=(BottomSectionJava)getSupportFragmentManager().findFragmentById(R.id.fragment2);
}
Everything else is working fine. Only the above line shows this error:
My log file outputs this:
C:\Users\Riyana\AndroidStudioProjects\Fragment\app\src\main\java\com\mycompany\fragment\FragmentActivity.java
Error:(20, 94) error: inconvertible types
required: BottomSectionJava
found: Fragment
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
This is the complete code for that class where the error is appearing:
public class FragmentActivity extends ActionBarActivity implements TopSectionjava.TopSectionListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
}
@Override
public void memeGen(String top, String bottom) {
BottomSectionJava bjs=(BottomSectionJava)getSupportFragmentManager().findFragmentById(R.id.fragment2);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_, menu);
return true;
}
}
BottomSectionJava:
public class BottomSectionJava extends Fragment{
private static TextView memetext_top;
private static TextView memetext_bottom;
//
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//return super.onCreateView(inflater, container, savedInstanceState);
View view=inflater.inflate(R.layout.bottom_section,container,false);
memetext_top=(TextView)view.findViewById(R.id.memetext_top);
memetext_bottom=(TextView)view.findViewById(R.id.memetext_bottom);
return view;
}
public void setTextOnThePic(String top,String bottom){
memetext_top.setText(top);
memetext_bottom.setText(bottom);
}
}