xml code:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Invia"
android:clickable="true"
android:onClick="onClick1"
android:id="@+id/invia" />
java code:
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class CreazioneSondaggio extends AppCompatActivity {
String URL;
private EditText titolo;
private EditText sceltaA;
private EditText sceltaB;
private EditText sceltaC;
private Button invio;
private EditText server;
@Override
protected void onCreate(Bundle savedInstanceState) {
titolo = (EditText) findViewById(R.id.titolo);
sceltaA = (EditText) findViewById(R.id.A);
sceltaB = (EditText) findViewById(R.id.B);
sceltaC = (EditText) findViewById(R.id.C);
server= (EditText) findViewById(R.id.server);
invio = (Button) findViewById(R.id.invia);
// invio.setOnClickListener(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_creazione_sondaggio);
}
private void inviodati() {
......
}
public void onClick1(View v) {
Toast.makeText(CreazioneSondaggio.this, "ok", Toast.LENGTH_LONG).show();
inviodati();
}
}
Error:
Process: com.example.rober.registrazione, PID: 21261 java.lang.IllegalStateException: Could not execute method for android:onClick at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:275) at android.view.View.performClick(View.java:5210) at android.view.View$PerformClick.run(View.java:21288) 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:5527) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270) at android.view.View.performClick(View.java:5210) at android.view.View$PerformClick.run(View.java:21288) 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:5527) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference at com.example.rober.registrazione.CreazioneSondaggio.inviodati(CreazioneSondaggio.java:48) at com.example.rober.registrazione.CreazioneSondaggio.onClick1(CreazioneSondaggio.java:87) at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270) at android.view.View.performClick(View.java:5210) at android.view.View$PerformClick.run(View.java:21288) 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:5527) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
How can I fix it?