I can not understand what is wrong. There is no transition to other activations when pressing buttons.

public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button fBtn,sBtn,tBtn; fBtn = (Button) findViewById(R.id.fBtn); fBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplication(), "Send your homework to BUTTON BOSS",Toast.LENGTH_SHORT).show(); Intent intent2 = new Intent(getApplication(),HWPage.class); startActivity(intent2); } }); sBtn = (Button) findViewById(R.id.sBtn); sBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent3 = new Intent(getApplication(),Alert.class); startActivity(intent3); } }); tBtn = (Button) findViewById(R.id.tBtn); tBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent4 = new Intent(getApplication(),Alerts.class); startActivity(intent4); } }); } 

Stack trace:

  FATAL EXCEPTION: main Process: com.example.annah.third, PID: 3873 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.annah.third/com.example.annah.third.Alert}: java.lang.InstantiationException: java.lang.Class<com.example.annah.third.Alert> has no zero argument constructor at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2548) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.InstantiationException: java.lang.Class<com.example.annah.third.Alert> has no zero argument constructor at java.lang.Class.newInstance(Native Method) at android.app.Instrumentation.newActivity(Instrumentation.java:1078) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2538) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

Second activation

 public class Alert { public String alert_head; public String alert_date; public Alert(String alert_head, String alert_date){ this.alert_head = alert_head; this.alert_date = alert_date; } } 

Adapter

 public class AlertAdapter extends RecyclerView.Adapter<AlertAdapter.Holder>{ private List<Alert> alertList; public AlertAdapter(List<Alert> alertList){ this.alertList = alertList; } @Override public Holder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.notiflist,parent,false); return new Holder(itemView); } @Override public void onBindViewHolder(Holder holder, int position) { Alert alert = alertList.get(position); holder.alert_head.setText(alert.alert_head); holder.alert_date.setText(alert.alert_date); } @Override public int getItemCount() { return alertList.size(); } class Holder extends RecyclerView.ViewHolder { public TextView alert_head; public TextView alert_date; public Holder(View itemView) { super(itemView); alert_head = (TextView) itemView.findViewById(R.id.alert_head); alert_date = (TextView) itemView.findViewById(R.id.alert_date); } } } 
  • I think there is still an error here tBtn = (Button) findViewById(R.id.fBtn); you need tBtn = (Button) findViewById(R.id.tBtn); - Saidolim
  • @Saidolim, yes, thank you, inattention - A.Whole
  • And your activity in AndroidManifest.xml registered? - post_zeew
  • @post_zeew yes, now only the second button is not moving. Could this be a bug in the next activation? - A.Whole
  • Yes maybe. Show the stack trace. - post_zeew

1 answer 1

The problem is that the class:

 public class Alert { public String alert_head; public String alert_date; public Alert(String alert_head, String alert_date) { this.alert_head = alert_head; this.alert_date = alert_date; } 

is in no way activity .

In order for it to become an activity , it must be inherited from the appropriate class, for example, from AppCompatActivity and implement appropriate methods, such as onCreate(...) .

Perhaps in the line:

 Intent intent3 = new Intent(getApplication(), Alert.class); 

You wanted to write something else instead of Alert.class .