Layout main.xml not loaded?

Put your problem here if it does not fit any of the other categories.

Layout main.xml not loaded?

Postby alfredlok » Sat Mar 03, 2012 8:15 am

I am new to Android development and is still in the learning phase, using the Eclipse. The AVD is using the Android 2.3.3 - API Level 10.

I have created a package, and made a first project - AndroidTest (to familiar with the UI and basic stuff).

The test is completed and then I created another project (AndroidTest2) under the same package. It is to test orientation.

Step 1: The code is very simple.
Code: Select all

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class AndroidTest2Activity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
   
    public void onStart() {Log.d("StateInfo", "onStart");   }
   
    public void onResume() {Log.d("StateInfo", "onResume");}
   
    public void onStop() {Log.d("StateInfo", "onStop");   }
   
   
    public void onPause() {     Log.d("StateInfo", "onPause");}
   
    public void onDestroy() {Log.d("StateInfo", "onDestroy");   }
   
    public void onRestart() {   Log.d("StateInfo", "onRestart");   }
}



The layout is very simple - main.xml

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <EditText
        android:id="@+id/txt1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>


Then I test it. The layout loads successfully.

Step 2: Then I create a folder - "layout-land" for the landscape under the layout, and another "layout-land/main.xml".

The code is the same except I insert one more EditText.
Code: Select all
<EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />



Strange things happened here. When I debug, only the Application Title appears and nothing else.

Step 3: Then I remove the "layout-land" and the "layout-land/main.xml" and then debug again. But the Application still shows the Title only.

I cleaned the package and then debug again, same problem.

I tried to uninstall the AndroidTest2 from the emulator and debug again, same problem.

Step 4: I really have no idea why and so I created another project "AndroidTest3" under the same package and insert the same code from Step 2. It worked successfully.

I do not have any idea why. The codes are the same for AndroidTest2 and AndroidTest3 now. But the behaviors are different.

May anybody helps?

Thanks.
Alfred
alfredlok
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Mar 03, 2012 7:51 am

Top

Re: Layout main.xml not loaded?

Postby Phyll » Sat Mar 03, 2012 12:10 pm

Hi Alfred,

Yeah, if you make a lot of changes in a project and compile it under different names but with the same package identifier, sometimes the emulator gets confused. It might even really have two copies of the app installed.

The package name is the key to loading and managing Android apps in memory so it is a good practice to make the package unique for every project to avoid these kind of problems. You can make them anything you want of course but you may experience such unexplained behaviors.

It's really more of a development problem and goes away in the final installations.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 13 guests