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

Having trouble with Android Studio, please help!

I have just created a new project in which I am using ActivityA and ActivityB for my activity names. In addition I also named activity_layout for my layout name. When the project is created and loads up in android studio, I am receiving a error message after clicking on the first activity which is activityA. The error message states this "<identifier> expected" and will not run app. Please take a look at the code on line 27 where there is a wiggle line under a common which is causing the error. Thanks!

package Hour2App.hour2app;

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

public class ActivityB extends Activity {

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


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu., menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

This line of code in the code above I receive a wiggle line under the comma after the first menu.(R.menu.,)

getMenuInflater().inflate(R.menu., menu);

1 Answer

Hi Michael,

In your onCreateOptionsMenu() method you have the following line:

getMenuInflater().inflate(R.menu., menu);

You should have a reference to a menu like R.menu.menu_main.

If you don't want to have a menu for your application for now, you can safely delete the entire onCreateOptionsMenu() method, or alternatively add an appropriate menu.

I hope this helps.

Thanks! I have been trying to fix this issue for the last 12hours and every time I try to reference something it just turns the color red and the wiggle line is gone. I will have to do without the menu options for now I guess but i really do appreciate your feed back. Thanks again Jon, great job with such a quick response!