Reputation: 12735
I just started learning Android and I have following error in my first example please help me.
public class SecondActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button buttonNesnesi=(Button) findViewById(id.button1);
buttonNesnesi.setOnClickListener(
new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(SecondActivity.this, "Hello!!!",1000).show();
}
}
);
}
}
Exception:
E/AndroidRuntime(543): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.developersland/net.developersland.SecondActivity}: java.lang.NullPointerException
And this is my main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/button1"
android:layout_width="231dp"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
Upvotes: 0
Views: 113
Reputation: 18746
You are missing R.id.button1
final Button buttonNesnesi=(Button) findViewById(R.id.button1);
Upvotes: 1
Reputation: 109257
This should be,
final Button buttonNesnesi=(Button) findViewById(R.id.button1);
not a
final Button buttonNesnesi=(Button) findViewById(id.button1);
Upvotes: 2