Unreachable Statement

1

I need help, at line 107 android studio shows an error that says:

  

"Error: (107, 48) error: unreachable statement"

Since Line 106, which is AdapterView.AdapterContextMenuInfo info, is in red. When I remove line 107 which is the int id the line of AdapterView no longer turns red indicating the error.

I tried it anyway but I can not find the error.

List.java

package cliente.api_dominando.devmedia.hugo.estudos.br.devmedia_cliente.Activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.StaticLayout;
import android.util.SparseBooleanArray;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import java.util.List;

import cliente.api_dominando.devmedia.hugo.estudos.br.devmedia_cliente.ADAPTER.ClienteAdapter;
import cliente.api_dominando.devmedia.hugo.estudos.br.devmedia_cliente.DAO.ClienteDAO;
import cliente.api_dominando.devmedia.hugo.estudos.br.devmedia_cliente.R;
import cliente.api_dominando.devmedia.hugo.estudos.br.devmedia_cliente.VO.ClienteVO;

public class Listar extends Activity {


    ListView ltv;
    List<ClienteVO> lista = null;
    private Button btn_apagar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_listar);

        ltv = (ListView) findViewById(R.id.ltv_dados);
        ltv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

        registerForContextMenu(ltv);

        btn_apagar = (Button) findViewById(R.id.btn_apagar);

        ltv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                btn_apagar.setVisibility(View.VISIBLE);
            }
        });

    }




    public void Apagar_click(){
        String nome = "";
        SparseBooleanArray checkeds = ltv.getCheckedItemPositions();

        for(int i = 0; i<checkeds.size(); i++){
            nome += lista.get(checkeds.keyAt(i)).getNome();
        }
        Toast.makeText(getBaseContext(), nome, Toast.LENGTH_LONG).show();
    }




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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

        menu.setHeaderTitle(lista.get(info.position).getNome());
        menu.add(Menu.NONE, 0, 1, "Editar");
        menu.add(Menu.NONE, 0, 0, "Apagar");

    }



       @Override
        public boolean onContextItemSelected(MenuItem item) {
            return super.onContextItemSelected(item);

            AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
           int id = lista.get(info.position).getId();

            if(item.getItemId()==1){
                startActivity(new Intent(getBaseContext(), Editar.class).putExtra("id", id));
            }
           return true;

        }

    @Override
    public void onResume(){
        super.onResume();
        ClienteDAO dao = new ClienteDAO(getBaseContext());
        lista = dao.getAll();
        ltv.setAdapter(new ClienteAdapter(getBaseContext(), lista));


    }


}


/**package cliente.api_dominando.devmedia.hugo.estudos.br.devmedia_cliente.Activity;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;

import cliente.api_dominando.devmedia.hugo.estudos.br.devmedia_cliente.ADAPTER.ClienteAdapter;
import cliente.api_dominando.devmedia.hugo.estudos.br.devmedia_cliente.DAO.ClienteDAO;
import cliente.api_dominando.devmedia.hugo.estudos.br.devmedia_cliente.R;
import cliente.api_dominando.devmedia.hugo.estudos.br.devmedia_cliente.VO.ClienteVO;

public class Listar extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        ClienteVO vo = (ClienteVO) l.getAdapter().getItem(position);
        startActivity(new Intent(getBaseContext(), Editar.class).putExtra("id", vo.getId()));



    }






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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onResume(){
        super.onResume();
        ClienteDAO dao = new ClienteDAO(getBaseContext());
        setListAdapter(new ClienteAdapter(getBaseContext(), dao.getAll()));

    }

}
*/
    
asked by anonymous 15.07.2015 / 19:17

1 answer

4

The error is here:

public boolean onContextItemSelected(MenuItem item) {
    return super.onContextItemSelected(item);

    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
   int id = lista.get(info.position).getId();

    if(item.getItemId()==1){
        startActivity(new Intent(getBaseContext(), Editar.class).putExtra("id", id));
    }
   return true;

}

In fact, nothing after the first line of the method will be executed, since this first line contains a return , which forces the output of the method. Then all the code that follows is unreachable , that is, it will never be executed.

    
15.07.2015 / 19:25