Geek96
Geek96

Reputation: 57

Android R.id error

I have the following code and have an error in action_settings in R.id.action_settings. This is in the last method posted here so scroll down. I am not sure what is supposed to go in here. I am trying to create an app that has a login page at the start, with the potential to create a new user id in a registration page, take a picture in another page, and see a menu in another page.

package com.example.reynaldo.project1;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {

DatabaseHelper helper = new DatabaseHelper(this);

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

}

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

public void onButtonClick (View v){
    if (v.getId() == R.id.Blogin) {
        EditText a = (EditText) findViewById(R.id.TFemail);
        String str = a.getText().toString();
        EditText b = (EditText) findViewById(R.id.TFpassword);
        String pass = b.getText().toString();

        String password = helper.searchPass(str);

        if (pass.equals(password)) {

            Intent i = new Intent(MainActivity.this, Display.class);
            i.putExtra("Email", str);
            startActivity(i);

        } else {
            Toast temp = Toast.makeText(MainActivity.this, "Username and password don't match", Toast.LENGTH_SHORT);
            temp.show();
        }
    }

    if (v.getId() == R.id.Bsignup){
        Intent i = new Intent (MainActivity.this, SignUp.class);
        startActivity(i);
    }
}

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

}

Upvotes: 0

Views: 1410

Answers (5)

DB377
DB377

Reputation: 423

Check in your menu file and make sure you have created item with id = action_settings

Upvotes: 0

Hiren Gondaliya
Hiren Gondaliya

Reputation: 156

import yourpackagename.R;

For Ex:

import com.example.reynaldo.project1.R;

Upvotes: 0

e-LogicSense
e-LogicSense

Reputation: 62

import com.example.reynaldo.project1.R 

in your file and check you have a menu item with id action_settings and rebuild project.

Upvotes: 1

Swanand
Swanand

Reputation: 507

Most likely your R.menu.main xml file does not contain an item having @+id/action_settings as its id. Check your R.menu.main xml file and make sure the action_settings id is set

Upvotes: 0

Lalit Jadav
Lalit Jadav

Reputation: 1427

You have missed to import R.

import youPackage.R;

This way you can manually import R.

Please replace yourPackage with your package name of application. You can find it in your Manifest.xml file or with build.gradle file.

Upvotes: 2

Related Questions