0

I just started to learn about Android App Development, and I am about to create a simple application for starter right now.

I followed a tutorial on YouTube, but I don't know why I get some errors when I'm trying to run my app. It says they expect a ;, ), and more. I tried to look into my code, and i've made sure that every ( have ), and every line has ;

But the list expands and I don't know what's actually wrong.

package org.kosmik.infokosmik;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.FrameLayout;
public class MainActivity extends AppCompatActivity {
private BottomNavigationView mMenuUtama;
private FrameLayout mFrameUtama;
private berandaFragment berandaFragment;
private beritaFragment beritaFragment;
private radioFragment radioFragment;
private kegiatanFragment kegiatanFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 mFrameUtama = (FrameLayout) findViewById(R.id.frame_utama);
 mMenuUtama = (BottomNavigationView) findViewById((R.id.menu));
 berandaFragment = new berandaFragment();
 beritaFragment = new beritaFragment();
 radioFragment = new radioFragment();
 kegiatanFragment = new kegiatanFragment();
 mMenuUtama.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
 @Override
 public boolean onNavigationItemSelected(@NonNull MenuItem item) {
 switch (item.getItemId())) {
 case R.id.menu_beranda :
 setFragment(berandaFragment);
 return true;
 case R.id.menu_berita :
 setFragment(beritaFragment);
 return true;
 case R.id.menu_radio :
 setFragment(radioFragment);
 return true;
 case R.id.menu_kegiatan :
 setFragment(kegiatanFragment);
 return true;
 default:
 return false;
 }
 }
 }
}
public void setFragment(Fragment fragment) {
 FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
 fragmentTransaction.replace(R.id.frame_utama, fragment);
 fragmentTransaction.commit();
};}

This is my code on MainActivity.java . Anyway, i would really appreciate it if you would answer and explain it.

Stuti Rastogi
1,1882 gold badges16 silver badges26 bronze badges
asked Jun 19, 2018 at 16:07
5
  • Need to remove an extra closing bracket from switch (item.getItemId())). Your brackets should always match up. Commented Jun 19, 2018 at 16:11
  • 1
    Android Studio should highlight where missing ; are in red, look down the right hand side scrollbar and you will see a red indicator. Commented Jun 19, 2018 at 16:12
  • You also only need one set of brackets for findViewById((R.id.menu)) Commented Jun 19, 2018 at 16:13
  • Finally, you don't need the ; at the end of the setFragment function. Commented Jun 19, 2018 at 16:14
  • And it looks like a closing bracket ) needs to be added after (new BottomNavigationView.OnNavigationItemSelectedListener(), before the opening curly brace {. It would help if you included the error message(s) that you are getting. Commented Jun 19, 2018 at 16:23

1 Answer 1

2

Dear You started a method parenthesis named setOnNavigationItemSelectedListener but never closed, please close the method parenthesis as below:

default:
 return false;
 }
 }
 });
}
public void setFragment(Fragment fragment) {
 FragmentTransaction fragmentTransaction = 
 getSupportFragmentManager().beginTransaction();
 fragmentTransaction.replace(R.id.frame_utama, fragment);
 fragmentTransaction.commit();
}
krisz
2,6952 gold badges13 silver badges19 bronze badges
answered Jun 19, 2018 at 16:18
Sign up to request clarification or add additional context in comments.

2 Comments

also need to remove extra parenthesis from switch (item.getItemId())) ... should be like as switch (item.getItemId())
Thank you very much for the help. I thought i have checked all the parenthesis, seems i need to be more careful.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.