1

I recently started the learning process of creating android apps, I am using IntelliJ IDEA 13.1.1 and I am following this tutorial of adding action bar buttons and I am getting the error cannot resolve symbol navutils. I have searched online and came across couple of stackoverflow posts (1 and 2) and in those post they seem to be talking about fixing the problem via build.gradle which i have no idea what it is and cant seem to find this file anywhere.

here is my DisplayMessageActivity.java code, so far the app seems to be working just fine, i am able to post the text and see it but this action bar button is driving me crazy.

package com.example.My_First_App;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;

public class DisplayMessageActivity extends Activity {

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_message);
        // Get the message from the intent
        Intent intent = getIntent();
        String received_message = intent.getStringExtra(MyActivity.SOME_MESSAGE);

        // Create the text view
        TextView textView = new TextView(this);
        textView.setTextSize(40);
        textView.setText(received_message);

        // Set the text view as the activity layout
        setContentView(textView);

        // Make sure we're running on Honeycomb or higher to use ActionBar APIs
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // Show the Up button in the action bar.
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

}

I will really appreciate any help in this matter as i am stuck and cant move forward with the tutorial.

Community
  • 1
  • 1
Shairyar
  • 3,268
  • 7
  • 46
  • 86

2 Answers2

3

I think you are missing

import android.support.v4.app.NavUtils;  
Swayam
  • 16,294
  • 14
  • 64
  • 102
  • i added it on top but it now says `cannot resolve symbol support` – Shairyar May 05 '14 at 07:36
  • You need to add the support library to your build path. – Swayam May 05 '14 at 07:36
  • http://stackoverflow.com/a/18300071/1393623 should make it clear for you how to add it, incase you are not familiar with it. – Swayam May 05 '14 at 07:37
  • how to do that? i added two references in my question and both seem to be saying the same thing "add library to your build path", this is what i need to know, how to add support library to build path as i cant seem to find the file `build.gradle` – Shairyar May 05 '14 at 07:37
  • You are welcome! All the best! Lemme know if anything doesn't work out. – Swayam May 05 '14 at 07:41
  • Glad to be of help! Cheers! :) – Swayam May 05 '14 at 07:47
1

I don't see you importing NavUtils anywhere.

Add import android.support.v4.app.NavUtils; to your imports.

Kayaman
  • 72,141
  • 5
  • 83
  • 121