0
This is the mistake: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.octupus.ramonteste/com.example.octupus.ramonteste.projetoEscolaAluno.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$Onclicklistener)' on a null Object Reference
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private ListView lista;
public Button btnExcl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//DRAWER LAYOUT
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//cash da listView
lista = (ListView) findViewById(R.id.listView);
btnExcl = (Button)findViewById(R.id.btnExcluir);
final List<Aluno> studentt = escolaAluno();
final ArrayAdapter<Aluno> studentSchoool = new ArrayAdapter<Aluno>(this, android.R.layout.simple_list_item_1, studentt);
lista.setAdapter(studentSchoool);
//metodo onclick do button
btnExcl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText text = (EditText)findViewById(R.id.editNome);
String name = text.getText().toString();
studentt.add(createAlunos(name));
studentSchoool.notifyDataSetChanged();
}
});
I am trying to access an xml button from another Activity, ai generates the above error, how to resolve ?
But how can I solve this Mr_anderson ? pq and I need to take the values from the field of another Activity and also need to use the "SAVE" button in another xml. Help me please ! rsr
– Ramon Lopes
Let’s assume you have Activity A and B. a Activity A is the register and a B is the confirmation. Then Voce wants for example the user to fill in Activity A and when it is to confirm, call Activity B. There you want Activity B to get the data from activitty A? That’s about it?
– Mr_Anderson
That’s right, Mr_andreson. But I got through Intent and Bundle, in the end I called Intent with Bundle with this <startActivityForResult(it, EXTRA_MESSAGE)>, and it worked. I’m grateful for your help.
– Ramon Lopes
I was going to suggest +- that. So that’s good.
– Mr_Anderson