Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build an Interactive Story App (Retired) Intents and Multiple Activities Adding a Second Activity

Can't Add a Second Activity

Because I have several orange highlighted words in my Main Activity (Interactive Story) and hence red squigglies under the names for MainActivity and AndroidManifets tabs at the top, I believe this is stopping me from starting a new activity. The problems appear to be dealing with the mStartButton entry. It says something about being converted to a local variable. I was just told this shouldn't be a problem, but I am stuck.

hey, post your code as a comment...

In my MainActivity: package com.example.twesq.interactivestory;

import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;

public class MainActivity extends Activity {

private EditText mNameField;
private Button mStartButton;

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

    mNameField = (EditText)findViewById(R.id.nameEditText);
    mStartButton = (Button)findViewById(R.id.startButton);

    mStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String name = mNameField.getText().toString();
            Toast.makeText(MainActivity.this, name, Toast.LENGTH_LONG).show();


        }
    });
}


}

}

And in my Android Manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.twesq.interactivestory" >

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation=""

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

Thanks for the help

3 Answers

delete that set with the word activity, because you have that one below, you just need to have android:screenOrientation="portrait">

OK I got that and now the AndroidManifest is not highlighted. My MainActivity is still red underlined, but I'll try to add a new Activity and see how it goes.

oh ok, please post your logcat

hey, so far, I realized one error in the AndroidManifest file, which is android:screenOrientation=""

you need to input "portrait" between the quotation marks as below android:screenOrientation="portrait" and also close it as below.

android:screenOrientation="portrait">

I wish that helps.

Thanks, I just tried it and I got an other set of <> with the word "activity" in it. Actually this is what it looks like now, and there are a lot more red squigglies.

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.twesq.interactivestory" >

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"></activity>

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

When I hover over the orange highlights I get "Reports empty tag body. The validation works in XML / JSP / JSPX / HTML/ XHTML file types."

how about the red squigglies ???

My mStartButton is still highlighted orange, but there are no more red squigglies. Thanks again. I'm able to work on the next lesson.