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 Intents and Multiple Activities Getting Data from an Intent

Megan Allred
Megan Allred
1,522 Points

[SOLVED] on compile I get this error: error: type annotations are not supported in -source 1.7. What is the fix?

When I try to compile the code from this video, I get this error: "error: type annotations are not supported in -source 1.7 (use -source 8 or higher to enable type annotations)" I don't understand what it is trying to tell me.

here is my code from my StoryActivity class:

package org.byui.meg21allred.interactivestory;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class StoryActivity extends AppCompatActivity {

    public static final String Tag = StoryActivity.class.getSimpleName()
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_story);

        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        if (name == null || name.isEmpty()) {
            name = "Friend";
        }




        Log.d(Tag, name);
    }
}

And here is the code from my MainActivity class:

package org.byui.meg21allred.interactivestory;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private EditText nameField;
    private Button startButton;

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

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

        startButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = nameField.getText().toString();

                //Toast.makeText(MainActivity.this, name, Toast.LENGTH_LONG).show();
                startStory(name);
            }
        });
    }

    private void startStory(String name) {
        Intent intent = new Intent(this, StoryActivity.class);
        intent.putExtra("name", name);
        startActivity(intent);

    }
}

1 Answer

Megan Allred
Megan Allred
1,522 Points

It looks like I forgot a semi colon after this line "public static final String Tag = StoryActivity.class.getSimpleName()" now the program compiles!