unfortunately Application has stopped

0

Good afternoon. I'm starting with the Android development and I'm trying to make a navigation between several screens however the error occurs unfortunately TCC has stopped at the time of running in the emulator. I already researched and could not find the problem. can anybody help me? Thanks

My Activity

public class MenuActivity extends Activity {

private Button btnLancamentos;
private Button btnObjetivos;
private Button btnSobre;
public  Button btnObjInserir;

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

    btnLancamentos = (Button)findViewById(R.id.btnLancamentos);
    btnObjetivos   = (Button)findViewById(R.id.btnObjetivos);
    btnSobre       = (Button)findViewById(R.id.btnSobre);
    btnObjInserir  = (Button)findViewById(R.id.btnObjInserir);

    btnLancamentos.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            TelaLanc();     
        }
    });

    btnObjetivos.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            TelaObj();      
        }
    });

    btnSobre.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            TelaSobre();        
        }
    }); 

    btnObjInserir.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            TelaObjInserir();       
        }
    }); 

    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment())
                .commit();
    }

}

protected void TelaLanc() {
    Intent intent = new Intent(this, TelaLancActivity.class);
    startActivity(intent);
}

protected void TelaObj() {
    Intent intent = new Intent(this, TelaObjActivity.class);
    startActivity(intent);
}

protected void TelaSobre() {
    Intent intent = new Intent(this, TelaSobreActivity.class);
    startActivity(intent);
}

protected void TelaObjInserir() {
    startActivity(new Intent (MenuActivity.this, TelaObjInserirActivity.class));

}

@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, 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();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_menu, container, false);
        return rootView;
    }
}

}

Screen call class

package pacote.tcc;

public class TelaObjActivity extends Activity{

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tela_obj);
}

}

Screen call class

package pacote.tcc;

public class TelaObjInserirActivity extends Activity{

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tela_obj_inserir);

    Button btVoltar = (Button) findViewById(R.id.btVoltar);
    btVoltar.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                startActivity(new Intent (TelaObjInserirActivity.this, MenuActivity.class));
                finish();
            }
});

}

}

    
asked by anonymous 16.08.2014 / 22:20

1 answer

1

You have fragment on Activity , check that activity_menu.xml contains the btnLancamentos , btnObjetivos , btnSobre and btonObjInserir buttons, or if they are in fragment_menu.xml . If they are in the fragment, the

btnLancamentos = (Button)findViewById(R.id.btnLancamentos);
btnObjetivos   = (Button)findViewById(R.id.btnObjetivos);
btnSobre       = (Button)findViewById(R.id.btnSobre);
btnObjInserir  = (Button)findViewById(R.id.btnObjInserir);

will return null and the next line, btnLancamentos.setOnClickListener(…) will launch NullPointerException , causing the crash. If this is the case, move the code into PlaceholderFragment .

    
17.08.2014 / 06:42