Android - Error with setContentView (R.layout.Principal);

2

Good afternoon,

I am having problems with setContent it reports the following error: Can not resolve symbol 'Principal'

This is occurring at ->

protected void onCreate(Bundle savedInstanceState) {

This 'Main' file is in: app - > res - > layout - > Principal.xml

Tools.java

    package view;

public class Tools extends Activity {

    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    @Override
    public void onStart() {

        super.onStart();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client.connect();
        AppIndex.AppIndexApi.start(client, getIndexApiAction());
    }

    @Override
    public void onStop() {

        super.onStop();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        AppIndex.AppIndexApi.end(client, getIndexApiAction());
        client.disconnect();

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.Principal);
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */

    public Action getIndexApiAction() {
        Thing object = new Thing.Builder()
                .setName("Main Page") // TODO: Define a title for the content shown.
                // TODO: Make sure this auto-generated URL is correct.
                .setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
                .build();
        return new Action.Builder(Action.TYPE_VIEW)
                .setObject(object)
                .setActionStatus(Action.STATUS_TYPE_COMPLETED)
                .build();
    }

    public void call_Desligar(View tools) {

        try {
            Process proc = Runtime.getRuntime().exec(new String[]{"su", "-c", "reboot -p"});
            proc.waitFor();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    public void call_Reiniciar(View tools) {

        try {
            Process proc = Runtime.getRuntime().exec(new String[]{"su", "-c", "reboot"});
            proc.waitFor();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    public void call_Sair(View tools) {
        System.exit(0);
    }

}
    
asked by anonymous 14.12.2016 / 17:30

1 answer

2

This may be happening for two reasons:

1. Uppercase

  

This property must contain only lowercase characters.   When trying to run the application the following error will occur: Error: 'P' is not   a valid file-based resource name character: the names   file-based resources must contain only lowercase az,   0-9 or underlined /

2. Check your import's

There are several R classes in an android project!

Example:

// referente a biblioteca recyclerview 
 android.support.v7.recyclerview.R;
// referente a biblioteca Support Design 
  android.support.design.R;
// referente a biblioteca CardView 
  android.support.v7.cardview.R;

To import the items for your project, you need to import the project!

To identify, check the package where this R class comes from!

In your case, it should be the same as your project package.

Here's an example:

import seu.projeto.R; 
    
14.12.2016 / 18:14