Some errors on Android

Asked

Viewed 123 times

4

I’m trying to start programming on Android. I created the project and came this code:

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

@Override
public boolean onCreateOptionsMenu(Menu menu) 
{
    getMenuInflater().inflate(R.menu.main1, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) 
{
    int id = item.getItemId();
    if (id == R.id.action_settings) 
    {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

but with those mistakes:

How to solve ??

  • 1

    It means that the tela_1 is not present in the presentation of the APK.

  • But the project was created like this, I didn’t change anything.

  • https://missaodeveloper.wordpress.com/2013/09/11/activity-do-android-e-o-metodo-oncreate/ [EN]

  • 1

    The problem should be the import of the R class. See the Imports in the class and first remove the import from the R class, then position the cursor on the variable with the error, press the ALT+ENTER shortcut and import it again

  • 1

    See the folder res > layout if there is a file called tela_1.xml. If you don’t have this problem.

  • 2

    First of all I suggest you migrate to Android Studio, since Eclipse support has been discontinued and also the code generated by it is from a discontinued version of SDK.

Show 1 more comment

2 answers

0

The answer from @Jose Vieira Neto is also valid, but I believe the problem lies in some layout XML or even strings, Dimensions or something like that. This must be causing error in generating the R.java file which is the interchange file between the application’s Resources and the source code.

0

Note that Actionbaractivity’s Heritage is deprecated because when created an android project it already tries to configure appcompatv7 lib in your project sometimes the ide Uga. Check if your project was imported to appcompatv7 and then Clean the project .

If not imported automatically do this

   Eclipse -> Import -> Existing Android Code into workspace.

Search for the SDK folder

   sdk/extras/android/support/v7/appcompat to your Eclipse workspace.

After importing add the library to your project

   Select Android -> Library -> Add.

Clean the project and try again

Browser other questions tagged

You are not signed in. Login or sign up in order to post.