简体   繁体   English

如何在Android Studio中向现有项目添加新活动 - “Project not ready”

[英]How to add new activity to existing project in Android Studio - “Project not ready”

What needs to be done to add a new activity to existing project that works and compiles but has "Project not ready" in the menu. 需要做些什么才能将新活动添加到现有项目中,该项目可以正常工作和编译,但菜单中“项目未准备就绪”。 Please see the picture. 请看图片。

Other than that all works, so I don't know what IDE means by "Project not ready" 除此之外所有工作,所以我不知道IDE的意思是“项目未准备好”

项目没有准备菜单样本

This is a little bit over a year but i thought i would provide an answer for anyone (novice like me) who may encounter the same problem. 这是一年多一点,但我想我会为任何可能遇到同样问题的人(像我这样的新手)提供答案。 I had the exact same problem as depicted and denoted. 我有完全相同的问题描述和表示。 It was fixed by 它是固定的

  • Cleaning the project (Build --> Clean Project) 清理项目(Build - > Clean Project)
  • Sync with Gradle ( Tools --> Android --> Sync project with Gradle files) 与Gradle同步(工具 - > Android - >使用Gradle文件同步项目)

(Not an exact answer) Observation: (不是确切答案)观察:

I don't know exactly what happened, but it works now, all I could notice is that gradle had some error from unclean build likely I must have had some code changes resulting in invisible compilation errors. 我不确切知道发生了什么,但它现在正常工作,我所能注意到的是gradle有一些来自不洁构建的错误,我可能必须进行一些代码更改,从而导致无形的编译错误。 After good build menus available again. 经过良好的构建菜单再次可用。

Please post your "observation" if you don't know exact answer. 如果您不确切答案,请发布您的“观察”。

Thanks 谢谢

If you want to add a Activity to an android application, you have to Extend Activity from one of your classes like this: 如果你想将一个Activity添加到一个Android应用程序,你必须从你的一个类扩展活动,如下所示:

public class SecondActivity extends Activity

And add that activity to your manifest. 并将该活动添加到清单中。

       <activity
            android:name=".ActivitySecondClass"
            android:label="@string/app_name2" >

        </activity>

You have to give the project time to build first. 您必须先给项目时间进行构建。 Wait a minute or two before jumping in. 在跳入之前等一两分钟。

I had the same issue. 我遇到过同样的问题。 I fixed it by clearing the cache. 我通过清除缓存来修复它。 (File > Invalidate caches & Restart). (文件>无效缓存和重新启动)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM