&#39 ;;'表达预期| if else中的public boolean

时间:2018-04-09 18:32:37

标签: java android if-statement boolean expression



[...]

else if (id == R.id.nav_videovorschlag) {

            public boolean isOnline() {
                ConnectivityManager conMgr = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo netInfo = conMgr.getActiveNetworkInfo();

                if(netInfo == null || !netInfo.isConnected() || !netInfo.isAvailable()){
                    return false;

                    ImageButton internetok;
                    offlineDialog.setContentView(R.layout.onlinepopup);
                    internetok = (ImageButton) offlineDialog.findViewById(R.id.internetok);
                    internetok.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            offlineDialog.dismiss();
                        }
                    });
                }
                return true;

                setTitle("Videovorschlag");
                Fragment5_vorschlag fragment = new Fragment5_vorschlag();
                FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.frag_home, fragment, "Videovorschlag");
                fragmentTransaction.commit();
            }

[...]




AndroidStudio表示public boolean isOnline() {是预期的表达式(;)。 但那是错的......任何人都可以帮我解决这个问题......我坚持了一个小时: - (。

祝你好运

1 个答案:

答案 0 :(得分:1)

试试这个,

[...]

else if (id == R.id.nav_videovorschlag) {
          if(isOnline){
setTitle("Videovorschlag");
                Fragment5_vorschlag fragment = new Fragment5_vorschlag();
                FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.frag_home, fragment, "Videovorschlag");
                fragmentTransaction.commit();
             }
            }

public boolean isOnline() {
                ConnectivityManager conMgr = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo netInfo = conMgr.getActiveNetworkInfo();

                if(netInfo == null || !netInfo.isConnected() || !netInfo.isAvailable()){
                    return false;

                    ImageButton internetok;
                    offlineDialog.setContentView(R.layout.onlinepopup);
                    internetok = (ImageButton) offlineDialog.findViewById(R.id.internetok);
                    internetok.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            offlineDialog.dismiss();
                        }
                    });
                }
                return true;
}