I tried to run my android application in my android device but it keeps saying that my Main Activity does not exist although my Main Activity class is there
I tried to create a new project then copied my previous codes and it worked for a while. But then it produced the same error again.
Error while executing: am start -n "com.example.sms/com.example.sms.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.sms/.MainActivity }
Error type 3
Error: Activity class {com.example.sms/com.example.sms.MainActivity} does not exist.
Error while Launching activity
There is already a intent-filter in may android manifest:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I already tried to clean and rebuild project. But it still gets the same error. My android device's version is android 9.
Here is my main activity:
package com.example.sms;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
EditText etNumber, etMessage;
Button btnSend;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etNumber = (EditText)findViewById(R.id.etNumber);
btnSend = (Button)findViewById(R.id.btnSend);
btnSend.setOnClickListener(this);
}
public void MyMessage() {
String phoneNum = etNumber.getText().toString().trim();
String spamMessage = "Hi";
if (etNumber.getText().toString().equals("09152006203")) {
if (!etNumber.getText().toString().equals("")) {
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> sms = smsManager.divideMessage(spamMessage);
smsManager.sendMultipartTextMessage(phoneNum, null,sms,null, null);
Toast.makeText(this, "Message has been sent", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Please enter number or message", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Number is incorrect!", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch(requestCode){
case 0:
if(grantResults.length>=0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
MyMessage();
} else {
Toast.makeText(this, "You do not have required permission", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onClick(View v) {
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS);
if(permissionCheck == PackageManager.PERMISSION_GRANTED){
MyMessage();
}
else{
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, 0);
}
}
}
Can you try uninstalling app using following ADB command and re-run?
adb uninstall <your-apps-package-name>
you can delete the folder of idea,then restart your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With