jeudi 21 mai 2015

App crashes when starting a navigationDrawer Activity from a blank activity

This is my sarting activity...

public class first extends ActionBarActivity {

public String superusername=null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_first);

    Button okbtn = (Button) findViewById(R.id.okbtn);
    final EditText username = (EditText) findViewById(R.id.username);

    okbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            superusername = username.getText().toString();
            Intent intent = new Intent(first.this, NavigationDrawerFragment.class);
            startActivity(intent);

        }
    });

}

when I click the ok button, the app crashes. Why???

How can I successfully start the NavigationDrawer Activity???

This is my manifest file...

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
    <activity
        android:name=".first"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.FIRST" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

The navigationDrawerActivity is default which is produced by android studio.

Aucun commentaire:

Enregistrer un commentaire