Could someone help me? the moment I press on the FloatingActionButton the activity is closed and goes back. What am I doing wrong?
public class Regolamento extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_regolamento);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "English", Snackbar.LENGTH_LONG);
TextView tv = (TextView) findViewById(R.id.text);
tv.setText("ciao");
}
});
}}
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Regolamento"
tools:showIn="@layout/activity_regolamento">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:text="wow"/>
</androidx.core.widget.NestedScrollView>
How should i do? Can someone help me? until just before everything worked then suddenly it stopped working
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.example.bbmarinablu.Regolamento$1.onClick(Regolamento.java:29) at android.view.View.performClick(Unknown Source:17) at android.view.View.performClickInternal(Unknown Source:3) at android.view.View.access$3500(Unknown Source:0) at android.view.View$PerformClick.run(Unknown Source:8) at android.os.Handler.handleCallback(Unknown Source:2) at android.os.Handler.dispatchMessage(Unknown Source:4) at android.os.Looper.loop(Unknown Source:242) at android.app.ActivityThread.main(Unknown Source:98) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:11) at com.android.internal.os.ZygoteInit.main(Unknown Source:275)
onClick
that could lead to an error, the problem is somewhere elseandroid:id="@+id/text"
in your xml I'm assuming you get a null pointer exception causing a crash. Posting some helpful code would help us locate the issue if this isn't the causeRun
tab in Android Studio.