I'm experiencing a run time error while trying to run this code.It says InstantiationException. please find a solution to this

21 views Asked by At

I'm having this error while trying to perform a code. Please find a solution for this.

E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.csepro/com.example.csepro.MainActivity}: java.lang.InstantiationException: java.lang.Class<com.example.csepro.MainActivity> cannot be instantiated

This is my MainActivity.java

package com.example.csepro;
import static com.example.csepro.R.*;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.*;
public abstract class MainActivity extends AppCompatActivity {
    //public static final String MSG = "com.codewithteju.csepro.MSG";
    EditText us,pd;
    Button login,tlogin,signin;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layout.activity_main);
        us=findViewById(R.id.ed);
        pd = findViewById(R.id.ep);
        login = findViewById(R.id.b1);
        tlogin = findViewById(R.id.b2);
        signin = findViewById(R.id.b3);
        String password;
        password=pd.getText().toString();
        String username;
        username = us.getText().toString();
        ArrayList<String> students = new ArrayList<>();
        HashMap<String,String> studentmap = new HashMap<>();
        signin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                students.add(username);
                studentmap.put(username, password);
            }
        });
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (password.equals(studentmap.get(username)))
                {
                    Intent intent = new Intent(MainActivity.this,main2.class);

                    //intent.putExtra(MSG,students);
                    String message = "Succesfully logged in as "+username;
                    intent.putExtra("mymsg",message);
                    MainActivity.this.startActivity(intent);
                }
                else {
                    Intent intent = new Intent(MainActivity.this,main2.class);
                    String message = "wrong password";
                    intent.putExtra("mymsg",message);
                    MainActivity.this.startActivity(intent);
                }
            }
        });
    }
}`
0

There are 0 answers