gpt4 book ai didi

Error: Activity class {.MainActivity} does not exist(错误:活动类{.MainActivity}不存在)

转载 作者:bug小助手 更新时间:2023-10-25 22:55:24 32 4
gpt4 key购买 nike



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

我试图在我的Android设备上运行我的Android应用程序,但它一直显示我的主活动不存在,尽管我的主活动类在那里



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:

在5月份的Android清单中已经有了一个意图过滤器:



        <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.

我已经试着清理和重建项目了。但它仍然得到相同的错误。我的安卓设备版本是安卓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);
}


}
}


更多回答

It is happening because your package name is having conflicts go to you main activity class copy it's package name and paste it into your manifest activity tag in place of .MainActivity

之所以会发生这种情况,是因为您的包名称存在冲突。转到您的主活动类,复制它的包名并粘贴到您的清单活动标记中,而不是.MainActivity

This has a lot of answer, check it out stackoverflow.com/questions/20915266/…

这有很多答案,请查看Stackoverflow.com/Questions/20915266/…

@Mr.Patel the same error occurs :(

@Mr Patel也出现同样的错误:(

please post your activity code

请张贴您的活动代码

@AngelEsguerra how did you solve it?

@AngelEsguera你是怎么解决的?

优秀答案推荐

Can you try uninstalling app using following ADB command and re-run?

你可以尝试使用以下ADB命令卸载应用程序并重新运行吗?


adb uninstall <your-apps-package-name>


you can delete the folder of idea,then restart your project.

您可以删除IDEA文件夹,然后重新启动您的项目。



I have had this happen to me once when I enabled the Fingerprint / PIN lock on the AVD and ran the app afterwards.

我有一次遇到过这种情况,当时我启用了AVD上的指纹/PIN锁,然后运行了这款应用程序。


I found I needed to unlock the device before running the app.

我发现我需要在运行这款应用程序之前解锁设备。



Take the path:

走这条路:



tab Run / edit Configuration / tab general / Lunch Options / launch.

选项卡运行/编辑配置/选项卡常规/午餐选项/启动。



And select the default activity option.
If the problem does not resolve, select the Specified Activity option and select the MainActivity.

并选择默认活动选项。如果问题没有解决,请选择指定的活动选项,然后选择MainActivity。



If the problem is resolved, it is likely that the activity path is in the wrong androidManifest. You can write the path completely in androidmanifest.

如果问题得到解决,很可能是活动路径位于错误的androidManifest中。您可以将路径完整地写在android清单中。



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

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


In the code above write the path of the activity instead of the word path.
And also go back app configurations and choose the default activity one again.

在上面的代码中,写下活动的路径,而不是单词路径。还可以返回应用程序配置,再次选择默认活动。



Had this in react native, all the above solutions did not work for me
while in root, I did cd android
then ./gradlew uninstallAll
then after its done, cd out , run the project and the error was gone

在REACT本机中,以上所有解决方案都不适用于我在根目录下,然后我做了CD Android。/gradlew卸载完成后,CD出来,运行项目,错误消失了



Add the intent-filter to the AndroidManifest.xml:

将Intent-Filter添加到androidManifest.xml:



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

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


try this

尝尝这个



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

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


or



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

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


or



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

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


You can look at this response here Error type 3 Error: Activity class {} does not exist.

您可以在此处查看此响应错误类型3错误:活动类{}不存在。



Also, another common problem is if you are running your app on a physical device that has multiple user accounts. E.g. Main User and A Guest User. In this case there might be a conflict if one user does not update their application. Follow the following steps;

此外,另一个常见的问题是,如果你在有多个用户账户的物理设备上运行应用程序。例如,主用户和访客用户。在这种情况下,如果一个用户不更新其应用程序,则可能会发生冲突。遵循以下步骤;




  1. Go to Settings.

  2. Go to Apps.

  3. Select your app.

  4. Open the overflow menu on the top right and select Uninstall for all users.

  5. Done. Try to install then launch your app again.



The other alternative, which is longer, is to uninstall the app while in one account, then switch accounts and uninstall in the other.

另一种更长的选择是,在一个账户中卸载应用程序,然后在另一个账户中切换账户并卸载。



Hope it helps.

希望能有所帮助。



The same error occurred to me and I solved it by renaming the package and using "clean project and rebuild project" ... then I shut down android stodio and restarted it then it worked fine.

同样的错误也发生在我身上,我通过重命名包并使用“清理项目和重建项目”来解决它。然后,我关闭了安卓系统,然后重启了它,然后它运行得很好。



You can look at this response here Error type 3 Error: Activity class {} does not exist.

您可以在此处查看此响应错误类型3错误:活动类{}不存在。


Also, another common problem is if you are running your app on a physical device that has multiple user accounts. E.g. Main User and A Guest User. In this case there might be a conflict if one user does not update their application. Follow the following steps;

此外,另一个常见的问题是,如果你在有多个用户账户的物理设备上运行应用程序。例如,主用户和访客用户。在这种情况下,如果一个用户不更新其应用程序,则可能会发生冲突。遵循以下步骤;


Go to Settings.
Go to Apps.
Select your app.
Open the overflow menu on the top right and select Uninstall for all users.
Done. Try to install then launch your app again.
The other alternative, which is longer, is to uninstall the app while in one account, then switch accounts and uninstall in the other.

转到设置。转到应用程序。选择您的应用程序。打开右上角的溢出菜单,然后选择为所有用户卸载。好了。尝试安装,然后再次启动您的应用程序。另一种更长的选择是,在一个账户中卸载应用程序,然后在另一个账户中切换账户并卸载。


更多回答

Thankyou. You save my day. This is the simple answer.

谢谢。你救了我的命。这就是简单的答案。

Saved my day .. very helpful other solutions did not worked

拯救了我的一天。非常有帮助的其他解决方案没有奏效

Thanks a lot !!! That's the solution!!!

非常感谢!这就是解决方案!

Where is that folder? I couldnt find it

那个文件夹在哪里?我找不到了

The folder is hidden .idea in the root of your android project folder

该文件夹隐藏在Android项目文件夹的根目录中。

This was downvoted, but I upvoted it, because this was the case for me. My emulator was still locked at startup, and I got this error. Once I unlocked the emulator, the app ran fine without the misleading "MainActivity does not exist" error.

它被否决了,但我投了赞成票,因为这就是我的情况。我的模拟器在启动时仍然被锁定,我收到了这个错误。一旦我解锁了模拟器,应用程序运行得很好,没有出现误导性的“MainActivity不存在”的错误。

Same here, that was the problem.

这里也一样,这就是问题所在。

Works for me only with Specified Activity, with default the command am start is generated with a double path like com.xyz/com.xyz.activity. Any idea why?

我只对指定的活动起作用,默认情况下,am start命令是用com.xyz/com.xyz.active这样的双路径生成的。知道为什么吗?

@rwst, com.xyz/com.xyz.activity is not a double path, it represents the package and the class of that component, see ComponentName docs

@rwst,com.xyz/com.xyz.active不是双路径,它代表该组件的包和类,请参见ComponentName文档

Hi. Thank you for replying. There is already a intent-filter in my android manifest but it still gets the same error :(

嗨。感谢您的回复。我的Android清单中已经有一个意图过滤器,但它仍然收到相同的错误:(

try all of these

把这些都试试吧

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com