Activity does not work when you add id to button

1

I have an activity whose xml code I leave below, the problem is that when I add an id to a button inside the xml of the activity, like this:

 android:id="@+id/pinbutton"

The activity no longer raises and closes the application, returns this error:

05-25 18:40:25.645 940-940/? E/EGL_emulation: tid 940: eglCreateSyncKHR(1288): error 0x3004 (EGL_BAD_ATTRIBUTE)
05-25 18:40:25.745 3225-3445/? W/EGL_emulation: eglSurfaceAttrib not implemented
05-25 18:40:25.745 3225-3445/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe3896080, error=EGL_SUCCESS
05-25 18:40:26.715 3023-3023/? W/ResourceType: No package identifier when getting value for resource number 0x00000000
05-25 18:40:26.715 3023-3023/? W/PackageManager: Failure retrieving resources for net.eqsoft.pacienteapp: Resource ID #0x0

Full xml code:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="net.eqsoft.pacienteapp.ResgistrarActivity">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:layout_gravity="center_horizontal"
            android:background="@color/black_overlay"
            android:orientation="vertical">
            <Button
                android:id="@+id/pinbutton"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="200dp"
                android:layout_height="120dp"
                android:textSize="25sp"
                android:background="@color/black_overlay"
                android:text="@string/registrar_button"/>
        </LinearLayout>
</FrameLayout>

How do I continue with the same problem, and this does not seem to be an error in layout, I'm going to place the java code involved, maybe here is the error.

Java Code of the Activity:

package net.eqsoft.pacienteapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class ResgistrarActivity extends AppCompatActivity {

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

And the piece of code from where the activity is launched as part of a menu in my main activity:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.paciente_menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.item_registrar:
            Intent i = new Intent(this, ResgistrarActivity.class);
            startActivity(i);
            return true;
        case R.id.item_salir:
            finish();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
    
asked by manduinca 27.05.2016 в 00:02
source

2 answers

1

I recommend you use Butterknife for injections of sight, apart from saving you code makes it faster and those annoying lines of findViewById() are no longer needed.

    
answered by 27.05.2016 в 19:00
0

Reviewing in detail the error message you have:

  

No package identifier when getting value for resource number   0x00000000

and

  

PackageManager: Failure retrieving resources for   net.eqsoft.pacienteapp: Resource ID # 0x0

If you mention that adding an id to an element marks an error, it is probably the tools:context , which specifies that activity is associated with the layout.

Ensure that it is actually the activity that loads your Layout:

tools:context="net.eqsoft.pacienteapp.ResgistrarActivity">

Maybe within activity ResgistrarActivity you're loading another different layout with setContentView() .

Generate your project again Build > Rebuild Project

    
answered by 27.05.2016 в 19:07