Problems with Android Development (ii)--Eclipse does not generate mainactivity and layout layouts when creating a new Android project

Source: Internet
Author: User

First, when the new Android project Eclipse does not generate mainactivity and layout layouts

Recently, due to work reasons, began to learn Android development, in the introduction of the time encountered a lot of pits, encountered the first pit is " new Android Project when Eclipse does not automatically generate mainactivity and layout layout ", The project creation process is as follows:

  

  

  

  

  

  

Expand the Helloandroid project to see the directory structure of the created project, as shown in:

  

My project was created using an officially integrated ADT Eclipse (adt-bundle-windows-x86_64-20140702), and the project was created with "Blank Activity" selected. The resulting project's directory structure becomes as shown, and under normal circumstances, Eclipse will create a package named Me.gacl.helloandroid in the SRC directory, then there will be a Mainactivity.java file in it, and then the Layout folder will have a activity_ Main.xml file, but neither of these are now generated. Because there is no operational activity in the Helloandroid project, it is not possible to run the Helloandroid project directly, as shown in:

Run the Android project in Eclipse, as shown in the following steps:

  

The run will print "No Launcher activity found!" in the console and the emulator will not run as shown in:

  

Let's say "No Launcher activity found! "Error, there will be a androidmanifest.xml configuration file in the project called Android, as shown in:

    

Let's take a look at the code inside the Androidmanifest.xml as follows:

<Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Me.gacl.helloandroid"Android:versioncode= "1"Android:versionname= "1.0" >    <USES-SDKandroid:minsdkversion= "8"android:targetsdkversion= "+" />    <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >    </Application></Manifest>

As you can see, the startup item is not configured because eclipse did not automatically generate the Mainactivity.java and Activity_main.xml files for us when creating the project, which should be the eclipse creating the "Blank Activity" Bug, this code is missing in <application></application>

<ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name">            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter></Activity>

which. Mainactivity is the main activity of your project, so you usually encounter "No Launcher activity found! "Error, then it is absolutely not configured to start the main activity in the Androidmanifest.xml file

Second, when the new Android project Eclipse does not generate mainactivity and layout layouts solution

Workaround: When creating a project, replace "Blank activity" with "Empty activity" to solve the above mentioned problem!

Delete the Helloandroid project, re-create it, the previous steps are the same, that is, to "create activity" when you select "Empty activity" as shown in:

  

Many video tutorials have chosen "blank activity" for the "Create activity" step, but as I have proven, "Create activity" is selected as "blank activity" when this step is Then the created Android project will appear " Eclipse does not automatically generate mainactivity and layout layouts when creating new Android projects " problem , that is not generating Mainactivity.java and activity_ Main.xml file, the lack of mainactivity Android project is not able to run, the runtime will appear above said "No Launcher activity found! Error So in this step it is important to note that the "Create activity" step is chosen as "Empty activity" instead of "Blank activity". This may have something to do with the version of Eclipse I'm using, I'm using an officially integrated ADT Eclipse (adt-bundle-windows-x86_64-20140702), and some versions of Eclipse are in the "Create Activity "Blank activity" is the normal generation of mainactivity and layout layouts, but when you create the project to the "Create Activity" step, if you use the version of Eclipse in the " Create activity "When you select" Blank activity "can normally generate mainactivity and layout layout, then" Create activity "can choose" blank activity "as a template , if not, then "create activity" chooses "create activity" as the template, anyway, our goal is to want eclipse to automatically help us generate mainactivity and layout layouts, Which template can be done to choose which one.

  

Click "Finish" button to complete the creation, so that the creation of the Android project will automatically generate Mainactivity.java and Activity_main.xml files, as shown in:

  

Let's look at the code in Androidmanifest.xml:

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Me.gacl.helloandroid"Android:versioncode= "1"Android:versionname= "1.0" >    <USES-SDKandroid:minsdkversion= "8"android:targetsdkversion= "+" />    <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >        <ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>    </Application></Manifest>

This code is more in <application></application>

<ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter></Activity>

We run the created Android project directly, as shown in:
  

When running an Android app, it needs to run on the emulator, which is the first to create an emulator, but it takes a long time to start creating the emulator in Eclipse, just as I have a tablet computer on hand that can be used for testing, so I'm going to use the real machine test. As shown in the following:

  

The results of the operation on your tablet are as follows:

  

The desktop of the tablet also shows the icon for the Helloandriod app that we installed on our deployment, as shown in:

  

Problems with Android Development (ii)--Eclipse does not generate mainactivity and layout layouts when creating a new Android project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.