New Android Project not creating Layout or Java file

后端 未结 2 2021
既然无缘
既然无缘 2021-01-28 22:25

I have been trying, for 2 days now, to simply get past the first few pages of the first chapter of Big Nerd Ranch\'s Android Programming Book.

The gist of my problem is

相关标签:
2条回答
  • 2021-01-28 23:20

    I had this kind of "bug" the first time I used Eclipse ADT too. In my case uninstall and reinstalling fixed the problem.

    However as the comments told you, it's no big deal to have the files created automatically for you, except in the case you're totally new to Android and doesn't know what you may miss if you create the file from scratch.. which was also my case.

    But in case you are still bugged by the problem then this might help. Usually these 3 files are created automatically for you, but in case they would not, then make them on your own by copy-pasting these:

    AppNameHere\res\layout\activity_main.xml

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.anything.appnamehere.MainActivity"
        tools:ignore="MergeRootFrame" />
    

    AppNameHere\res\layout\fragment_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.anything.appnamehere.MainActivity$PlaceholderFragment" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
    
    </RelativeLayout>
    

    AppNameHere\src\com.anything.appnamehere\MainActivity.java

    package com.anything.appnamehere;
    public class MainActivity extends Activity{
    
    }
    

    These codes are for my app which is named com.anything.appnamehere, please modify to suit your need.

    0 讨论(0)
  • 2021-01-28 23:28

    OK, So after several hours of experimentation and research, there is currently no way to create a default Android project with the Rev 23.0 version of the ADT Tools.

    Here is what I did form scratch to get things working on my computer. I'm running OS X 10.9.3:

    1. Downloaded the Java JDK 7u60 from here: Java JDK for Mac
    2. Downloaded Eclipse Luna 64-bit from here: Eclipse Luna 64-Bit Mac
    3. Downloaded the Android SDK version 22.6.3 here: Android SDK 22.6.2 Mac
    4. Downloaded the ADT tools version 22.6.3 from here: ADT 22.6.3 Mac

      • I first put the Android SDK folder, unzipped, in my Applications directory and renamed it to "Android SDK" (You can use whatever you want or put it elsewhere.
      • Afterwards, I went into Eclipse > Help > Install New Software...
      • Then I clicked on Add > Archive > .Zip file for ADT 22.6.3
      • Launched Eclipse and was promoted to select the SDK location, so in Eclipse's preferences I selected the folder I put inside my Applications directory.
      • Updated the Android SDK built tools and downloaded the SDKs for the API levels I wanted. Note that I did NOT update the Android SDK Tools to the Rev 23 update available. This is what's broken and has things like ProGuard, SQLite, and other items missing (it's because it was released earlier this week for the L Preview).

    And that's it, I am now able to create an application and the .java and activity files are there.

    As mentioned by Mr. Kro, there are differences between the book and the SDK, but this is to be expected after ~1 year since its release. In any case this is going to help you if you are having the same trouble as I am. And with this you can use the latest Eclipse and the latest stable Android SDK/ADT, until Google patches Rev 23.

    0 讨论(0)
提交回复
热议问题