简体   繁体   中英

Eclipse doesn't generate MainActivity.java & activity_main.xml

On creating a new Android Application Project, MainActivity.java under its package name should be generated automatically in src folder & activity_main.xml should be created inside layout folder. But it is not created.

在此输入图像描述

And also in manifest it doesn`t generate this 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)

And yesterday I downloalded the updates from SDK Manager these tools are installed /updated 在此输入图像描述在此输入图像描述

I tried cleaning the project,changing the workspace,restarting the eclipse & windows but it doesn't helps :(

我在创建新项目时通过更改方法解决了问题...不知道为什么但是在将ADT更新到最新版本之后,当我们创建“空白活动”时,它会生成空的src和res文件夹但是如果我们创建新的“空活动” ,它会像以前版本的ADT一样生成默认的hello world程序....所以只需要在添加新的android项目时单击创建空活动

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/

See here thread https://code.google.com/p/android/issues/detail?id=66647

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

Here is the information http://developer.android.com/tools/sdk/eclipse-adt.html

and click updating ADT, the download instructions are in there.

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.

Hope this helps.

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.

在此输入图像描述

Without that, my project looks the same as yours:

在此输入图像描述

这些解决方案对我来说也不起作用,但解决问题的方法是删除在创建新的Android应用程序项目时自动创建的appcompat项目。

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.

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.

I have solved this problem in the following way.

  1. Download Eclipse from official site ( current version 4.4.0 Luna).
  2. Install it.
  3. Run Eclipse Help->Install new software
  4. Enter in empty top field ` https://dl-ssl.google.com/android/eclipse/ click add and name it as you want , for instance AndroidPlugin
  5. Install all software( Developes tools)
  6. Restart Eclipse
  7. Eclipse should show error message that your sdk is not found
  8. Specify your SDK in Use existing sdk .
  9. Restart Eclipse.

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

Nevertheless, for some systems, you might also try changing the target SDK to Android 'JellyBean' or 'KitKat' rather than 'API21'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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