Hello i use AVD and I don’t know how to error stack when I get -> app stopped working force quit…
I wanted to code simple listener but there was an error -> i know that error is caused by setOnClick listener and this is probalby null pointer exception, but I would like to see it on stack error. Please tell me also why there is an exception. I attach the part of XML
package com.example.pierwsza;
import android.os.Bundle;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.support.v4.app.NavUtils;
class MainActivity extends Activity implements OnClickListener{
Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button) findViewById(R.id.button3);
// b.setOnClickListener((android.view.View.OnClickListener) this); <--- ERROR
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onClick(DialogInterface dialog, int which) {
//b.setText("Ale to dziwne");
}
}
XML of that BUTTON
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/linearLayout1"
android:layout_marginBottom="29dp"
android:layout_toLeftOf="@+id/textView1"
android:text="Jakis przycisk" />
If you are using Eclipse to code, go to Window -> Show View -> LogCat to see the error stack thrown by your app.
To fix this particular error change this:
To use a View.OnClickListener() like this:
And press Ctrl+Shift+O to update your import statements from DialogInterface.OnClickListener to View.OnClickListener.