I want to make a simple action in which when i press a button then i should jump to another activity. But in this program whenever i press submit button an error is occurred and program terminated.
Please check my code and help me what error i have done.
My first activity
package login.test;
import android.app.Activity;
import android.os.Bundle;
import android.content.*;
import android.widget.*;
import android.view.View;
import android.view.View.OnClickListener;
public class login extends Activity
{
/** Called when the activity is first created. */
EditText e;
Button b;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b=(Button)findViewById(R.id.submit);
e=(EditText)findViewById(R.id.editText1);
b.setOnClickListener( new OnClickListener()
{
@Override
public void onClick(View v)
{
if (v.getId() == R.id.submit)
{
Intent myIntent = new Intent(v.getContext(), some.class);
startActivityForResult(myIntent, 0);
}
else
{
e.setText("cant go");
}
}
});
}
}
second Activity
package login.test;
import android.os.Bundle;
import android.app.Activity;
import android.content.*;
import android.widget.*;
import android.view.View;
import android.view.View.OnClickListener;
public class some extends Activity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
}
}
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="saan"
/>
<Button android:text="Submit" android:id="@+id/submit" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="EditText" android:id="@+id/editText1"></EditText>
</LinearLayout>
welcome.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:text="You are welcome" android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
</LinearLayout>
I think you missed add your second activity in menifest..
So plz add second activity in menifest.
and second thing is no need to check
because you setOnClickListener on button so v will always button.
remove this condition
compare my code with your..