-1

I was making an app with the help of a tutorial on youtube and i got an error.I have only made the UI till now. This is the complete error:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.covidtracker/com.example.covidtracker.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.covidtracker.MainActivity"

This is my code :

public class MainActivity extends AppCompatActivity {

private TextView totalconfirm,totalactive,totalrecoverd,totaldeath,test;
private TextView todayconfirm,todayrecovered,todaydeath;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    init();
}

private void init(){

    totalconfirm = findViewById(R.id.totalconfirm);
    totalrecoverd = findViewById(R.id.totalrecovered);
    todaydeath = findViewById(R.id.totaldeath);
    totalactive = findViewById(R.id.totalactive);
    todaydeath = findViewById(R.id.todaydeath);
    todayconfirm = findViewById(R.id.todayconfirm);
    todayrecovered = findViewById(R.id.todayrecovered);
    test = findViewById(R.id.test);

}

}

narcis dpr
  • 939
  • 2
  • 12
  • 32

2 Answers2

0

Add your Activity in AndroidManifest.xml file. When you create a new activity it should be register it in your AndroidManifest.xml. same as in below code.

<activity android:name=".MainActivity">
<intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Dharmender Manral
  • 1,504
  • 1
  • 6
  • 7
0

I had a similar problem, here's my solution:

  1. Right click on your project and select Properties.
  2. Select Java Build Path from the menu on the left.
  3. Select the Order and Export tab.
  4. From the list make sure the libraries or external jars you added to your project are checked.
  5. Finally, clean your project & run.

You may also check this answer

.

Manan jain
  • 111
  • 1
  • 1
  • 6