0

I have problem. I need button pause. In activity I press pause then App save actual activity name in database. This works fine. But naw I need implement button, wich can get back saved activity name. And with this open this activity.

But I try loot of code but all time thet work only frst time. On secnd try and more my app drop. Whay?

holder.TPauzaBtn.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {

        TextView textView = findViewById(R.id.Tpauza); // Nahraďte ID vaším ID TextViewu
        String activityName = textView.getText().toString(); // Získání názvu aktivity z textu TextViewu

        Intent intent = new Intent();
        intent.setClassName(getPackageName(), getPackageName() + "." + activityName);

        try {
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void startActivity(Intent intent) {
    }

    private String getPackageName() {
        return null;
    }

    private TextView findViewById(int tpauza) {
        return null;
    }
});
}

Error. FATAL EXCEPTION: main Process: cz.example.troubleshooting, PID: 3798 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.widget.TextView.getText()' on a null object reference at cz.example.troubleshooting.RecyclerViewAdapter$6.onClick(RecyclerViewAdapter.java:130) at android.view.View.performClick(View.java:5198) at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1202) at android.view.View$PerformClick.run(View.java:21147) 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)

Lukas
  • 1
  • 1

0 Answers0