1 Replies - 2665 Views - Last Post: 29 March 2012 - 05:22 PM

#1 DonalDuck  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 5
  • Joined: 28-March 12

Cannot open layout with button

Posted 28 March 2012 - 03:27 PM

So I'm starting to "develop" (more like learning in the internet and re-doing it, but ok). I have been following mybringback tutorials in Youtube.
My problem is that I can't open a layout when clicking a button programmed to do so - it says "The application Test_LowerICS (process com.me.test_lowerics) has stopped unexpectedly. Please try again." every time I try to open it. I tried both on the AVD and in a real Android device - both gave me the same result: error. Eclipse doesn't show any error in my code.
How can I solve this?

Thanks,
DD

Here is my code:

Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.me.test_lowerics"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Test_LowerICSActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <activity
            android:name=".Menu"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.me.test_lowerics.MENU" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Layout1"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.me.test_lowerics.LAYOUT1" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>



scr> com.me.test_lowerics>Test_LowerICS.java:
package com.me.test_lowerics;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class Test_LowerICSActivity extends Activity {
    /** Called when the activity is first created. */
    MediaPlayer logoMusic;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        
        MediaPlayer logoMusic = MediaPlayer.create(Test_LowerICSActivity.this, R.raw.brought_you);
        logoMusic.start();
        
        Thread logoTimer = new Thread(){
        	public void run(){
        		try{
        			sleep(5000);
        			Intent menuIntent = new Intent("com.me.test_lowerics.MENU");
        			startActivity(menuIntent);
        		} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
        		finally{
        			finish();
        		}
        		}
        	};
        	logoTimer.start();
        }


	}; 



scr> com.me.test_lowerics>Menu.java:

package com.me.test_lowerics;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Menu extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		// Button Sound
		final MediaPlayer buttonSound = MediaPlayer.create(Menu.this,
				R.raw.button_click);

		// Setting up the button references
		Button bear = (Button) findViewById(R.id.bear);
		Button wwt = (Button) findViewById(R.id.wwt);

		extracted(buttonSound, bear);

		bear.setonclickListener(new View.onclickListener() {

			public void onclick(View v) {
				// TODO Auto-generated method stub
				buttonSound.start();
				startActivity(new Intent("com.me.test_lowerics.LAYOUT1"));
			}
		});
		
		wwt.setonclickListener(new View.onclickListener() {

			public void onclick(View v) {
				// TODO Auto-generated method stub
				buttonSound.start();
				startActivity(new Intent("com.me.test_lowerics.LAYOUT1"));
			}
			
		});
	}

	private void extracted(final MediaPlayer buttonSound, Button bear) {}

	@Override
	protected void onpause() {
		// TODO Auto-generated method stub
		super.onpause();
	}

}



scr> com.me.test_lowerics>Layout1.java:
package com.me.test_lowerics;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public class Layout1 extends Activity implements OnCheckedChangeListener{

	TextView textOut;
	EditText textIn;
	RadioGroup gravityG, styleG;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout1);
		textOut = (TextView) findViewById(R.id.tvChange);
		textIn = (EditText) findViewById(R.id.tvStyle);
		gravityG = (RadioGroup) findViewById(R.id.rgGravity);
		styleG = (RadioGroup) findViewById(R.id.rgStlye);
		Button gen = (Button) findViewById(R.id.bGenerate);
			
		gen.setonclickListener(new View.onclickListener() {
			
			public void onclick(View v) {
				// TODO Auto-generated method stub
				
			}
	});
}
	

	public void onCheckedChanged(RadioGroup arg0, int arg1) {
		// TODO Auto-generated method stub
		textOut.setText(textIn.getText());
	}
}
 



Res>layout>main.xml:
<?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:background="@drawable/background_1"
    android:orientation="vertical" >


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

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="This is why I roll!" />

    <Button
        android:id="@+id/bear"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Bear Rocks!"
        android:textSize="25dp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/wwt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="WWT Rocks!"
        android:textSize="25dp"
        android:textStyle="bold" />
    
</LinearLayout> 



Res>layout>splash.xml:

<?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"
    android:background="@drawable/background_3" >
    
    </LinearLayout>



Res>layout>layout1.xml:

<?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" 
    android:background="@drawable/background_2"
    >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10" />

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="100" >

        <TextView
            android:id="@+id/tvStyle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:gravity="center"
            android:text="Style"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textStyle="bold"
             />
        <TextView
            android:id="@+id/tvStyle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:gravity="center"
            android:text="Gravity"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textStyle="bold"
             />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="100" >

        <RadioGroup
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:orientation="vertical"
            android:id="@+id/rgStlye" >"

            <RadioButton
                android:id="@+id/rbNormal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Normal" />

            <RadioButton
                android:id="@+id/rbItalic"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Italic" />

            <RadioButton
                android:id="@+id/rbBold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Bold" />
        </RadioGroup>

        <RadioGroup
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:orientation="vertical"
            android:id="@+id/rgGravity"  >

            <RadioButton
                android:id="@+id/rbLeft"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Left" />

            <RadioButton
                android:id="@+id/rbCenter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Center" />

            <RadioButton
                android:id="@+id/rbRight"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Right" />
        </RadioGroup>
    </LinearLayout>

    <TextView
        android:id="@+id/tvChange"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Type in Text and Press the Button Below"
        android:textSize="25dp"
         />

    <Button
        android:id="@+id/bGenerate"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Generate" />

</LinearLayout>



Is This A Good Question/Topic? 0
  • +

Replies To: Cannot open layout with button

#2 DonalDuck  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 5
  • Joined: 28-March 12

Re: Cannot open layout with button

Posted 29 March 2012 - 05:22 PM

Thanks for your help guys!
I've found my problem and solved it.
If anyone else has this problem:
Open your Layout1.java file;
In line 24 (check my code up there to be sure your line's the same)
Change
textIn = (EditText) findViewById(R.id.tvStyle);


For
textIn = (EditText) findViewById(R.id.editText1);                <------ Instead of editText 1 you can write whatever you have named it



Oh, and I've written a new post because I can't/don't know how to edit my post.

DD
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1