Good night, I created an AlertDialog that asks for the player's name and puts it in the editText ... when the user clicks on confirm it saves it in the database ... I made the code and it seems that I am not able to relate id or something of the sort.
Could someone help me in this part please?
Dialog code:
package com.allsport.miyonic.allsport;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import Base.Esporte;
public class DialogGol extends DialogFragment{
private EditText caixa;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
caixa = (EditText) caixa.findViewById(R.id.caixa_dialog_1);
AlertDialog.Builder bir = new AlertDialog.Builder(getActivity());
bir.setMessage("Gol de ").setPositiveButton("Confirmar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Esporte inseri = new Esporte();
inseri.setjogadores(caixa.getText().toString());
}
}).setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//nulo
}
});
bir.setTitle("Gooolll!!!");
View view = LayoutInflater.from(getContext()).inflate(R.layout.caixa_jogador_dialog, null);
bir.setView(view);
AlertDialog dialog = bir.create();
return dialog;
}
}
editText XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/caixa_dialog_1"
android:hint="Nome do jogador que fez o gol"
android:layout_weight="1"
android:gravity="center_vertical|center"
android:shadowColor="@color/preto"
android:textColor="@color/preto"/>
</LinearLayout>
</LinearLayout>
LogCat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.allsport.miyonic.allsport, PID: 2788
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.EditText.findViewById(int)' on a null object reference
at com.allsport.miyonic.allsport.DialogGol.onCreateDialog(DialogGol.java:24)
at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:308)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Thank you ...