protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textview=findViewById(R.id.textView);
Button button=findViewById(R.id.button);
FragmentManager fragmentManager = getSupportFragmentManager();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int num=0;
while(true) {
num = random.nextInt(7);
if(num!=0)
break;
}
Log.i("","Button Clicked");
int finalNum = num;
textview.setText(Integer.toString(finalNum));
if(num==1)
fragmentManager.beginTransaction()
.replace(R.id.frag_one, One.class, null)
.setReorderingAllowed(true)
.addToBackStack("name") // name can be null
.commit();
else if(num==2)
fragmentManager.beginTransaction()
.replace(R.id.frag_two, Two.class, null)
.setReorderingAllowed(true)
.addToBackStack("name") // name can be null
.commit();
else if(num==3)
fragmentManager.beginTransaction()
.replace(R.id.frag_three, Three.class, null)
.setReorderingAllowed(true)
.addToBackStack("name") // name can be null
.commit();
else if(num==4)
fragmentManager.beginTransaction()
.replace(R.id.frag_four, Four.class, null)
.setReorderingAllowed(true)
.addToBackStack("name") // name can be null
.commit();
else if(num==5)
fragmentManager.beginTransaction()
.replace(R.id.frag_five, Five.class, null)
.setReorderingAllowed(true)
.addToBackStack("name") // name can be null
.commit();
else if(num==1)
fragmentManager.beginTransaction()
.replace(R.id.frag_six, Six.class, null)
.setReorderingAllowed(true)
.addToBackStack("name") // name can be null
.commit();
}
});
I'm a beginner, I tried to make this simple dice app, created 6 fragments and in each fragment included an imageview that would display the image for every turn of dice....After compiling the code, I am getting errors stating " java.lang.IllegalArgumentException: No view found for id 0x7f0800c4 (com.example.rollingdice:id/frag_three) for fragment Three{cff507d}" and the app is crashing adruptly.