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

Asked

Viewed 574 times

2

Good afternoon,

I’m having trouble with setContent it reports the following error: Cannot solves Symbol 'Main'

This is happening in the ->

protected void onCreate(Bundle savedInstanceState) {

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

Java tools.

    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);
    }

}
  • 1

    I believe that the name of your layout can not be Main with more letters, try to refactor it to layout_principal

  • All right, I’ll be right back.

  • Unfortunately not solved. Thank you

1 answer

2


This could be happening for two reasons:

1. Uppercase

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

2. Check your import’s

There are several classes R on 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;

In order to import items related to your project, you need to import from the project!

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

In your case, it should be equal to the package of your project.

Follow an example:

import seu.projeto.R; 
  • This import is already added. But it still hasn’t solved :(

  • Fixed the answer! leave the file name Main.xml as main.xml

  • And setContentView(R.layout.Home); as setContentView(R.layout.main);

  • Thank you champion!

  • Another thing, mark as correct the answer, only if it helped you or was useful! I suggest this reading

Browser other questions tagged

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