为什么在Android Studio中无法解析活动名称。

huangapple go评论89阅读模式
英文:

Why activity name is not getting resolved in Android Studio

问题

我在我的包下的布局文件夹(layouts)下创建了一个活动的XML文件,但仍然出现以下问题:

    package com.alen.cybercpm;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.os.Bundle;
    
    public class comrade_login extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_comrade_login);
        }
    }

activity_comrade_login在代码中显示为红色/错误,但我在我的包中确实有该文件。

我将一个闪屏界面设置为我的主活动(Main Activity),然后调用了这个活动。
英文:

I've an activity XML file created under layouts under my package but still it's complains

package com.alen.cybercpm;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class comrade_login extends AppCompatActivity {

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

activity_comrade_login comes in RED/ERROR but I've that file in my package.

I've a splash screen as my Main Activity. then this activity is called.

答案1

得分: 1

将你的类名从 comrade_login 改为 ComradeLoginActivity

然后执行 clean code
之后进行 Rebuild code
现在执行 clean cache and restart

希望这能帮助你

谢谢!祝编码愉快

英文:

change your Class comrade_login to ComradeLoginActivity

Then clean code
After this Rebuild code
Now clean chache and restart

Hope it will help you

Thankew! Happy Coding

答案2

得分: 1

只需重新启动您的“Android Studio”。将来可能会出现意外和愚蠢的问题,所以最好的方法是通过重新启动您的“Android Studio”来清除缓存。

英文:

There is nothing seems to be wrong with your code, Just Restart you Android Studio. You will face such kinds of unexpected and silly problems in future so, the best way is to clear caches by Restarting Your Android Studio

huangapple
  • 本文由 发表于 2020年5月3日 23:11:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/61576766.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定