java.lang.RuntimeException : Unable to start activity, 传递给另一个 Activity

标签 java android compiler-errors

我一直在尝试做所有事情,但没有任何效果,我想通过单击按钮从 LogInActivity 传递到 RegisterUserActivity,但它不起作用.

我得到一个 java.lang.RuntimeException,请帮忙,这是我的代码:

登录 Activity :

public class LoginActivity extends Activity implements View.OnClickListener{
    private static final String LOGIN_URL = "http://ucwm.co.nf/UsuarioLogin_app.php";


    // Email, password edittext
    EditText txtUsername;
    EditText txtPassword;

    Button btnReg;

    // login button
    Button btnLogin;

    // Alert Dialog Manager
    AlertDialogManager alert = new AlertDialogManager();

    // Session Manager Class
    SessionManager session;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_layout);

        // Session Manager
        session = new SessionManager(getApplicationContext());

        // Email, Password input text
        txtUsername = (EditText) findViewById(R.id.userName);
        txtPassword = (EditText) findViewById(R.id.passwordUser);

        Toast.makeText(getApplicationContext(), "User Login Status: " + session.isLoggedIn(), Toast.LENGTH_LONG).show();

        if(session.isLoggedIn()){
            Intent i = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(i);
            finish();
        }

        // Login button
        btnLogin = (Button) findViewById(R.id.loginButton);

        btnLogin.setOnClickListener(this);

        btnReg=(Button)findViewById(R.id.btnReg);

        btnReg.setOnClickListener(this);

    }

    private void login(){
        String username = txtUsername.getText().toString().trim();
        String password = txtPassword.getText().toString().trim();
        userLogin(username, password);
    }

    private void userLogin(final String username, final String password){
        class UserLoginClass extends AsyncTask<String,Void,String> {

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                if (username.trim().length() > 0 && password.trim().length() > 0){
                    if (s.equalsIgnoreCase("exito")) {

                        // Creating user login session
                        // For testing i am stroing name, email as follow
                        // Use user real data
                        session.createLoginSession(username);

                        // set
                        ((Usuario) getApplication()).setSomeVariable(username);

                        // Staring MainActivity
                        Intent i = new Intent(getApplicationContext(), MainActivity.class);
                        startActivity(i);
                        finish();


                    } else {
                        //Error en username o password
                        alert.showAlertDialog(LoginActivity.this, "Fallo inicio de sesión..", "Usuario o Contraseña incorrecto", false);
                    }
            }
                else{
                    // user didn't entered username or password
                    // Show alert asking him to enter the details
                    alert.showAlertDialog(LoginActivity.this, "Fallo inicio de sesión..", "Porfavor ingrese usuario y contraseña", false);
                }
            }

            @Override
            protected String doInBackground(String... params) {
                HashMap<String,String> data = new HashMap<>();
                data.put("username",params[0]);
                data.put("contrasenia",params[1]);

                RegisterUserClass ruc = new RegisterUserClass();

                String result = ruc.sendPostRequest(LOGIN_URL,data);

                return result;
            }
        }
        UserLoginClass ulc = new UserLoginClass();
        ulc.execute(username, password);
    }

    @Override
    public void onClick(View v) {
        if(v == btnLogin){
            SharedPreferences preferences = this.getSharedPreferences("PREFERENCE", 0);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putBoolean("PREFERENCE",true);
            login();
        }
        if(v==btnReg){
            Intent i = new Intent(getApplicationContext(), RegisterUserAcivity.class);
            startActivity(i);
            finish();
        }
    }
}

注册用户 Activity :

public class RegisterUserAcivity extends AppCompatActivity implements View.OnClickListener{

private RadioGroup radioPrefijo;
private RadioButton radioPre;
private EditText editTextName;
private EditText editTextUsername;
private EditText editTextPassword;
private EditText editTextEmail;
private EditText editTextDate;
private EditText editTextLastName;
private EditText editTextTelefone;

Calendar myCalendar = Calendar.getInstance();

String prefijo;

private Button buttonRegister;

private static final String REGISTER_URL = "http://ucwm.co.nf/UsuarioRegister_app.php";

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

    editTextName = (EditText) findViewById(R.id.editTextNombre);
    editTextUsername = (EditText) findViewById(R.id.editTextUsername);
    editTextPassword = (EditText) findViewById(R.id.editTextContrasenia);
    editTextTelefone = (EditText) findViewById(R.id.editTextTelefono);
    editTextEmail = (EditText) findViewById(R.id.editTextEmail);
    editTextDate = (EditText) findViewById(R.id.editTextFechaNac);
    editTextLastName = (EditText) findViewById(R.id.editTextApellido);

    buttonRegister = (Button) findViewById(R.id.btnRegistro);

    addListenerOnButton();

    buttonRegister.setOnClickListener(this);

    editTextDate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            new DatePickerDialog(RegisterUserAcivity.this, date, myCalendar
                    .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                    myCalendar.get(Calendar.DAY_OF_MONTH)).show();
        }
    });

}

@Override
public void onClick(View v) {
    if(v == buttonRegister){
        registerUser();
        finish();
    }
}

private void registerUser() {
    String name = editTextName.getText().toString();
    String lastName = editTextLastName.getText().toString().trim();
    String username = editTextUsername.getText().toString().trim();
    String password = editTextPassword.getText().toString().trim();
    String telefono = editTextTelefone.getText().toString().trim();
    String email = editTextEmail.getText().toString().trim().toLowerCase();
    String date = editTextDate.getText().toString().trim().toLowerCase();
    String pref= prefijo;

    register(username,password,name,lastName,date,email,telefono,pref);
}

private void register(String username,String password,String name,String lastName,String date,String email,String telefono,String pref) {
    class RegisterUser extends AsyncTask<String, Void, String>{
        ProgressDialog loading;
        RegisterUserClass ruc = new RegisterUserClass();

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            loading.dismiss();
            Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
        }

        @Override
        protected String doInBackground(String... params) {

            HashMap<String, String> data = new HashMap<String,String>();
            data.put("username",params[0]);
            data.put("password",params[1]);
            data.put("name",params[2]);
            data.put("lastname",params[3]);
            data.put("date",params[4]);
            data.put("email",params[5]);
            data.put("telefono",params[6]);
            data.put("prefijo",params[7]);

            String result = ruc.sendPostRequest(REGISTER_URL,data);

            return  result;
        }
    }

    RegisterUser ru = new RegisterUser();
    ru.execute(username,password,name,lastName,date,email,telefono,pref);
}

public void addListenerOnButton() {

    radioPrefijo = (RadioGroup) findViewById(R.id.radioPref);

    int p = radioPrefijo.getCheckedRadioButtonId();

    radioPre = (RadioButton) findViewById(p);
    prefijo = radioPre.getText().toString();

}

DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear,
                          int dayOfMonth) {
        // TODO Auto-generated method stub
        myCalendar.set(Calendar.YEAR, year);
        myCalendar.set(Calendar.MONTH, monthOfYear);
        myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
        updateLabel();
    }

};


private void updateLabel() {
    String myFormat = "yy-MM-dd"; //In which you need put here
    SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
    editTextDate.setText(sdf.format(myCalendar.getTime()));
}

}

登录 Activity xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<EditText
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:id="@+id/userName"
    android:hint="Usuario"
    android:layout_above="@+id/textView14"
    android:layout_alignLeft="@+id/textView14"
    android:layout_alignStart="@+id/textView14"
    android:layout_marginBottom="41dp" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:id="@+id/passwordUser"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:hint="Contraseña"
    android:editable="false"
    android:enabled="true"
    android:inputType="textPassword" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Iniciar Sesión"
    android:id="@+id/loginButton"
    android:layout_marginTop="40dp"
    android:layout_below="@+id/passwordUser"
    android:layout_centerHorizontal="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Ingrese Usuario"
    android:id="@+id/textView12"
    android:layout_above="@+id/userName"
    android:layout_alignLeft="@+id/userName"
    android:layout_alignStart="@+id/userName" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Ingrese Contresña"
    android:id="@+id/textView14"
    android:layout_above="@+id/passwordUser"
    android:layout_alignLeft="@+id/passwordUser"
    android:layout_alignStart="@+id/passwordUser" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Registrarse"
    android:id="@+id/btnReg"
    android:layout_below="@+id/loginButton"
    android:layout_alignLeft="@+id/loginButton"
    android:layout_alignStart="@+id/loginButton" />

RegisterActivity xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginRight="20dp"
    android:layout_marginLeft="20dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nombre (s)"
        android:id="@+id/textView15"
        android:layout_marginTop="20dp"
        android:layout_alignParentTop="true"
        android:layout_alignLeft="@+id/textView18"
        android:layout_alignStart="@+id/textView18" />

    <EditText
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:id="@+id/editTextNombre"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Apellido (s)"
        android:id="@+id/textView16"
        android:layout_below="@+id/editTextNombre"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:id="@+id/editTextApellido"
        android:layout_below="@+id/textView16"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nombre de Usuario"
        android:id="@+id/textView17"
        android:layout_below="@+id/editTextApellido"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:id="@+id/editTextUsername"
        android:layout_below="@+id/textView17"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Contraseña"
        android:id="@+id/textView21" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/editTextContrasenia" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Teléfono"
        android:id="@+id/textView18"
        android:layout_below="@+id/editTextTelefono"
        android:layout_alignRight="@+id/textView20"
        android:layout_alignEnd="@+id/textView20" />

    <EditText
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:id="@+id/editTextTelefono"
        android:layout_below="@+id/textView20"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Fecha de Nacimiento"
        android:id="@+id/textView19"
        android:layout_below="@+id/editTextFechaNac"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="date"
        android:ems="10"
        android:id="@+id/editTextFechaNac" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Correo"
        android:id="@+id/textView20"
        android:layout_below="@+id/editTextUsername"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:ems="10"
        android:id="@+id/editTextEmail" />

    <RadioGroup
        android:id="@+id/radioPref"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Usuario"
            android:id="@+id/radioButtonUser"
            android:layout_alignTop="@+id/radioButtonMedic"
            android:layout_toRightOf="@+id/editTextNombre"
            android:layout_toEndOf="@+id/editTextNombre"
            android:checked="false" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:text="Médico"
            android:id="@+id/radioButtonMedic"
            android:layout_alignParentBottom="true"
            android:layout_toLeftOf="@+id/editTextNombre"
            android:layout_toStartOf="@+id/editTextNombre"
            android:checked="false" />

    </RadioGroup>



    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Registrarse"
        android:id="@+id/btnRegistro"
        android:layout_below="@+id/radioButtonUser"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="35dp" />

</LinearLayout>

list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.juanisaac.unidascontigoac">

<!--PERMISOS-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!--ICONO DE LA APP-->
<application
    android:name="Usuario"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:largeHeap="true">

        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!-- DashBoard / MainActivity -->
    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait">
    </activity>
    <activity
        android:name=".SettingsActivity"
        android:label="@string/title_activity_settings">
    </activity>
    <activity
        android:name=".TestimoniosDetallados"
        android:label="Testimonios Detallados">
    </activity>
    <activity
        android:name=".AniadirForo"
        android:label="Añadir Foro">
    </activity>
    <activity
        android:name=".ForoDetallado"
        android:label="Foro Detallado">
    </activity>
    <activity
    android:name=".EventoDetallado"
    android:label="Evento Detallado">
</activity>
    <activity
        android:name=".RegisterUserAcivity"
        android:label="Register Activity">
    </activity>
    <!--
    <activity
        android:name=".SettingsActivity"
        android:label="@string/title_activity_settings" >
    </activity>
    -->
</application>

这是它显示的 LOGCAT:

11-27 00:36:01.540  24273-24273/com.example.juanisaac.unidascontigoac D/dalvikvm﹕ Late-enabling CheckJNI
11-27 00:36:02.540  24273-24273/com.example.juanisaac.unidascontigoac D/libEGL﹕ loaded /system/lib/egl/libEGL_genymotion.so
11-27 00:36:02.576  24273-24273/com.example.juanisaac.unidascontigoac D/﹕ HostConnection::get() New Host Connection established 0xb80bc298, tid 24273
11-27 00:36:02.604  24273-24273/com.example.juanisaac.unidascontigoac D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_genymotion.so
11-27 00:36:02.608  24273-24273/com.example.juanisaac.unidascontigoac D/libEGL﹕ loaded /system/lib/egl/libGLESv2_genymotion.so
11-27 00:36:03.036  24273-24273/com.example.juanisaac.unidascontigoac W/EGL_genymotion﹕ eglSurfaceAttrib not implemented
11-27 00:36:03.060  24273-24273/com.example.juanisaac.unidascontigoac D/OpenGLRenderer﹕ Enabling debug mode 0
11-27 00:37:54.167  24273-24273/com.example.juanisaac.unidascontigoac I/Choreographer﹕ Skipped 36 frames!  The application may be doing too much work on its main thread.
11-27 00:37:54.307  24273-24273/com.example.juanisaac.unidascontigoac W/dalvikvm﹕ VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
11-27 00:37:54.323  24273-24273/com.example.juanisaac.unidascontigoac I/dalvikvm﹕ Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
11-27 00:37:54.323  24273-24273/com.example.juanisaac.unidascontigoac W/dalvikvm﹕ VFY: unable to resolve interface method 15466: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
11-27 00:37:54.327  24273-24273/com.example.juanisaac.unidascontigoac D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
11-27 00:37:54.335  24273-24273/com.example.juanisaac.unidascontigoac I/dalvikvm﹕ Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
11-27 00:37:54.339  24273-24273/com.example.juanisaac.unidascontigoac W/dalvikvm﹕ VFY: unable to resolve interface method 15470: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
11-27 00:37:54.339  24273-24273/com.example.juanisaac.unidascontigoac D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
11-27 00:37:54.407  24273-24273/com.example.juanisaac.unidascontigoac I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable
11-27 00:37:54.407  24273-24273/com.example.juanisaac.unidascontigoac W/dalvikvm﹕ VFY: unable to resolve virtual method 405: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
11-27 00:37:54.411  24273-24273/com.example.juanisaac.unidascontigoac D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
11-27 00:37:54.415  24273-24273/com.example.juanisaac.unidascontigoac I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity
11-27 00:37:54.419  24273-24273/com.example.juanisaac.unidascontigoac W/dalvikvm﹕ VFY: unable to resolve virtual method 407: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
11-27 00:37:54.423  24273-24273/com.example.juanisaac.unidascontigoac D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
11-27 00:37:54.463  24273-24276/com.example.juanisaac.unidascontigoac D/dalvikvm﹕ GC_CONCURRENT freed 221K, 3% free 8787K/9036K, paused 6ms+6ms, total 25ms
11-27 00:37:54.479  24273-24273/com.example.juanisaac.unidascontigoac D/AndroidRuntime﹕ Shutting down VM
11-27 00:37:54.483  24273-24273/com.example.juanisaac.unidascontigoac W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa6195908)
11-27 00:37:54.487  24273-24273/com.example.juanisaac.unidascontigoac E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.juanisaac.unidascontigoac/com.example.juanisaac.unidascontigoac.RegisterUserAcivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5041)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.example.juanisaac.unidascontigoac.RegisterUserAcivity.addListenerOnButton(RegisterUserAcivity.java:143)
            at com.example.juanisaac.unidascontigoac.RegisterUserAcivity.onCreate(RegisterUserAcivity.java:58)
            at android.app.Activity.performCreate(Activity.java:5104)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5041)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
11-27 00:37:57.967  24273-24273/com.example.juanisaac.unidascontigoac I/Process﹕ Sending signal. PID: 24273 SIG: 9

最佳答案

这里:

prefijo = radioPre.getText().toString();

导致问题的行,因为 radioPrenull

getCheckedRadioButtonId()方法返回 -1 如果未选中 RadioGroup 中的 RadioButton

因此在当前的 RadioGroup xml 中,所有 RadioButton android:checked 属性都设置为 android:checked="false" 因此 RadioGroup 和 getCheckedRadioButtonId 中没有可用的选中 RadioButton () 将返回 -1

要解决当前问题,请在访问 RadioButton 之前添加 if 条件:

if(p !=-1){
    radioPre = (RadioButton) findViewById(p);
    prefijo = radioPre.getText().toString();
}

关于java.lang.RuntimeException : Unable to start activity, 传递给另一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33951676/

相关文章:

java - 如何在android中安全地存储API_ACCESS_TOKEN?

java - hibernate 创建表时如何排列列?

java - 在 Maven 中无法识别 CMD

android - 新的 ActionBar API 会包含在 Fragment backport 中吗?

Android Web 服务连接错误

c++ - 过载 - 不在范围内

c++ - 编译错误: undefined reference to

java - 使用 JPA/Hibernate 注释映射字符串列表

android - 抽屉导航 (menudrawer) Android 5 (lollipop) 样式

c++ - 尝试通过引用传递指针时出现此错误