Vote count:
0
i have been doing a android project lately and i can't connect my login activity with the next activity that contains the fragments.But every time i run the code,the app crashes,What can i do? Please can anyone tell me what's wrong in my code:- this java class contains the login page
MainActivity.java
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText edUsername = (EditText) findViewById(R.id.editText1);
final EditText edPassword = (EditText)findViewById(R.id.editText2);
Button btnValidate = (Button)findViewById(R.id.btn1);
btnValidate.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
String uname = edUsername.getText().toString();
String pass = edPassword.getText().toString();
if(uname.equals("sahu") && pass.equals("12345"))
{
Intent intent = new Intent(MainActivity.this,MainActivity2.class);
/*intent.putExtra("UserName",edUsername.getText().toString());*/
startActivity(intent);
}
else
{
Toast.makeText(MainActivity.this, "Invalid Usename password pair.", Toast.LENGTH_LONG).show();
}
}
});
}
}
This activity below is the main activity for the next two fragment classes:-
MainActivity2
import android.os.Bundle;
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.FragmentActivity;
public class MainActivity2 extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity2);
}
}
MenuFragment
public class MenuFragment extends ListFragment {
String[] food = new String[]{"Breakfast", "Lunch", "Dinner"};
String[] item = new String[]{"Idli Sambar", "Dam Aloo", "Paneer Butter Masala"};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list_fragment, container, false);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, food);
setListAdapter(adapter);
return view;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
TextFragment txt = (TextFragment) getFragmentManager().findFragmentById(R.id.fragment2);
txt.change(food[position], item[position]);
getListView().setSelector(android.R.color.holo_blue_dark);
}
}
This is the second fragment class
TextFragment
public class TextFragment extends Fragment{
TextView foo,it;
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
View view = inflater.inflate(R.layout.text_fragment, container, false);
foo= (TextView) view.findViewById(R.id.food);
it= (TextView)view.findViewById(R.id.item);
return view;
}
public void change(String txt, String txt1){
foo.setText(txt);
it.setText(txt1);
}
}
When i run the app and enter the username and password the app crashes and following error is displayed java.lang.RuntimeException: Unable to start activity ComponentInfo
Can anyone help me???plz
asked 42 secs ago
How do i connect my login button with another activity containing two fragments
Aucun commentaire:
Enregistrer un commentaire