-2

I'm learning to program for Android on the Android Studio . When I start the application, the following message appears on the AVD " Unfortunalety , GuitarStoreV2 has stopped ."

Can anybody help me ? (Sorry if some stupid mistake , do not have much familiarity with the language , and excuse the error Portuguese , because I am Brazilian and I do not speak English fluently )

Grateful for the attention Mark Tonial

public class MainActivity extends AppCompatActivity {

Button btn_iniciaapp;

public void Inicia ()
{
    Button btn_inciaapp = (Button) findViewById(R.id.btn_iniciaapp);
}

// Iniciando a tela de produtos
public void iniciaProd()
{

    Intent ActivityProd = new Intent(this, ActivityProd.class);
    startActivity(ActivityProd);
}

// Evento ao clicar no Botão
public void IniciaListener()
{
    this.btn_iniciaapp.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            MainActivity.this.iniciaProd();
        }
    });
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.activity_main);
    this.Inicia();
    this.IniciaListener();
}

}

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Tonial
  • 3
  • 2
  • Please read [this post](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this), and then come back and [edit] your question with the logcat, thanks. – OneCricketeer Jun 01 '16 at 20:23
  • If you go to http://pt.stackoverflow.com/ you can ask *entirely* in Portuguese. Just so you know :) – Laurel Jun 01 '16 at 21:57

1 Answers1

0
Button btn_iniciaapp;

public void Inicia ()
{
    Button btn_inciaapp = (Button) findViewById(R.id.btn_iniciaapp);
}

Your program is likely crashing with a NullPointerException. Here, Inicia isn't setting the value of your class's btn_iniciaapp: it's creating a locally scoped Button which is shadowing your class's btn_iniciaapp. You're setting the value of the local Button, not the class's.

Since the class's btn_iniciaapp is never set, it remains null, and the call to this.btn_iniciaapp.setOnClickListener will trigger a NullPointerException.

cf-
  • 8,598
  • 9
  • 36
  • 58