Eclipse 不生成 MainActivity.java & activity_main.xml
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22278479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse doesn't generate MainActivity.java & activity_main.xml
提问by Vivek Warde
On creating a new Android Application Project, MainActivity.java
under its package name should be generated automatically in srcfolder & activity_main.xml
should be created inside layoutfolder. But it is not created.
在创建一个新的 Android 应用程序项目时,MainActivity.java
它的包名应该在src文件夹中自动生成,并且activity_main.xml
应该在layout文件夹中创建。但它不是创建的。
And also in manifest it doesn`t generate this POC
而且在清单中它不会生成这个 POC
<activity
android:name="info.androidhive.slidingmenu.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
However, I added all these things manually.
但是,我手动添加了所有这些东西。
activity_main.xml then shows this error
Eclipse is loading framework information and the layout library from the SDK folder. activity_main.xml will refresh automatically once the process is finished.
MainActivity.java doesn't recognize the layout field in
setContentView(R.layout.activity_main)
activity_main.xml 然后显示此错误
Eclipse is loading framework information and the layout library from the SDK folder. activity_main.xml will refresh automatically once the process is finished.
MainActivity.java 无法识别布局字段
setContentView(R.layout.activity_main)
And yesterday I downloalded the updates from SDK Managerthese tools are installed /updated
昨天我从SDK Manager下载了更新,这些工具已安装/更新
I tried cleaning the project,changing the workspace,restarting the eclipse & windows but it doesn't helps :(
我尝试清理项目,更改工作区,重新启动 eclipse 和 windows 但它没有帮助:(
采纳答案by Ajay S
As one guy said
正如一位男士所说
I had the same problem even though I downloaded the Android SDK and did a clean install, but I just resolved it. I tried to click "Help" -> "Check for updates", and then I got a pop-up message saying everything was up to date, but after further research it appeared to me it wasn't up to date. What you need to do is click "Help" -> "Install new software" and install (this will update it) from this url: https://dl-ssl.google.com/android/eclipse/
即使我下载了 Android SDK 并进行了全新安装,我也遇到了同样的问题,但我刚刚解决了它。我尝试单击“帮助”->“检查更新”,然后我收到一条弹出消息,说一切都是最新的,但经过进一步研究,我发现它不是最新的。您需要做的是单击“帮助”->“安装新软件”并从此网址安装(这将更新它):https: //dl-ssl.google.com/android/eclipse/
See here thread https://code.google.com/p/android/issues/detail?id=66647
请参阅此处的线程https://code.google.com/p/android/issues/detail?id=66647
回答by Little Child
There is an option to select whether to generate MainActivity
and activity_main.xml
. Are you sure that you have selected those ? Make sure to select that.
有一个选项可以选择是否生成MainActivity
和activity_main.xml
。你确定你选择了那些?确保选择那个。
Without that, my project looks the same as yours:
没有它,我的项目看起来和你的一样:
回答by Solution
Those solutions didn't work for me too, but what resolve the problem for me was deleting the appcompat projects that are auto-created when we create a new android application project.
这些解决方案对我也不起作用,但对我来说解决问题的是删除我们创建新的 android 应用程序项目时自动创建的 appcompat 项目。
回答by user3562859
Same thing happened to me couple days ago after updating SDK through android SDK Manager. When I rebooted eclipse, I got a pop-up saying my Android Development Tool (ADT) or a plugin for Eclipse needs update to version 22.6.2
在通过 android SDK Manager 更新 SDK 后,几天前我也发生了同样的事情。当我重新启动 eclipse 时,我收到一个弹出窗口,说我的 Android 开发工具 (ADT) 或 Eclipse 插件需要更新到版本 22.6.2
Here is the information http://developer.android.com/tools/sdk/eclipse-adt.html
这里是信息http://developer.android.com/tools/sdk/eclipse-adt.html
and click updating ADT, the download instructions are in there.
然后单击更新 ADT,下载说明在那里。
I copied it out here just in case,
为了以防万一,我把它复制到了这里
Download the ADT Plugin Start Eclipse, then select Help > Install New Software. Click Add, in the top-right corner. In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location: https://dl-ssl.google.com/android/eclipse/Note: The Android Developer Tools update site requires a secure connection. Make sure the update site URL you enter starts with HTTPS. Click OK. In the Available Software dialog, select the checkbox next to Developer Tools and click Next. In the next window, you'll see a list of the tools to be downloaded. Click Next. Read and accept the license agreements, then click Finish. If you get a security warning saying that the authenticity or validity of the software can't be established, click OK. When the installation completes, restart Eclipse.
下载 ADT 插件 启动 Eclipse,然后选择帮助 > 安装新软件。单击右上角的添加。在出现的 Add Repository 对话框中,为 Name 输入“ADT Plugin”,为 Location 输入以下 URL:https: //dl-ssl.google.com/android/eclipse/注意:Android Developer Tools 更新站点需要一个安全连接。确保您输入的更新站点 URL 以 HTTPS 开头。单击确定。在“可用软件”对话框中,选中“开发人员工具”旁边的复选框,然后单击“下一步”。在下一个窗口中,您将看到要下载的工具列表。点击下一步。阅读并接受许可协议,然后单击完成。如果您收到安全警告,提示无法确定软件的真实性或有效性,请单击“确定”。安装完成后,
Hope this helps.
希望这可以帮助。
回答by doohsam
I was having the same problem. I tried creating the project with a different Target SDK. I used API 16 Android 4.1 and that worked.
我遇到了同样的问题。我尝试使用不同的 Target SDK 创建项目。我使用了 API 16 Android 4.1 并且有效。
回答by Chinmayee
I was also facing the same problem, had the adt and sdk tool updated to v23 which was released on 6/24. Created a project with Target SDK - AP1 16 and compile with API 19 and activity was created.
我也面临同样的问题,将 adt 和 sdk 工具更新到 6/24 发布的 v23。使用 Target SDK - AP1 16 创建了一个项目,并使用 API 19 进行编译,并创建了活动。
回答by user3796197
I have solved this problem in the following way.
我已经通过以下方式解决了这个问题。
- Download Eclipse from official site ( current version 4.4.0 Luna).
- Install it.
- Run Eclipse Help->Install new software
- Enter in empty top field `https://dl-ssl.google.com/android/eclipse/click add and name it as you want , for instance AndroidPlugin
- Install all software( Developes tools)
- Restart Eclipse
- Eclipse should show error message that your sdk is not found
- Specify your SDK in Use existing sdk .
- Restart Eclipse.
- 从官方网站下载 Eclipse(当前版本 4.4.0 Luna)。
- 安装它。
- 运行 Eclipse Help->Install new software
- 在空的顶部字段中输入` https://dl-ssl.google.com/android/eclipse/点击添加并根据需要命名,例如 AndroidPlugin
- 安装所有软件(开发工具)
- 重启 Eclipse
- Eclipse 应显示未找到您的 sdk 的错误消息
- 在 Use existing sdk 中指定您的 SDK。
- 重新启动 Eclipse。
回答by SK16
I solved problem by changing method while creating new project... Don't know why but after updating ADT to latest version, when we create "blank activity", it generates empty src and res folders but if we create new "Empty activity", it generates default hello world program like in previous versions of ADT.... SO just click on create empty activity when new android project is to be added
我在创建新项目时通过更改方法解决了问题......不知道为什么但是在将 ADT 更新到最新版本后,当我们创建“空白活动”时,它会生成空的 src 和 res 文件夹,但是如果我们创建新的“空活动” ,它会像以前的 ADT 版本一样生成默认的 hello world 程序......所以当要添加新的 android 项目时,只需点击创建空活动
回答by naps73r
Since this query isn't solved, I would like to add from my experience;
由于这个查询没有解决,我想根据我的经验补充;
I agree with "SK17" 's advice.. The latest eclipse software somehow generates the MainActivity.xml file by choosing 'Empty Activity' instead of 'Blank Activity'.
我同意“SK17”的建议。最新的 eclipse 软件通过选择“空活动”而不是“空白活动”以某种方式生成 MainActivity.xml 文件。
Nevertheless, for some systems, you might also try changing the target SDK to Android 'JellyBean' or 'KitKat' rather than 'API21'.
不过,对于某些系统,您也可以尝试将目标 SDK 更改为 Android“JellyBean”或“KitKat”而不是“API21”。