1

I am trying to start new activity using an intent but it never works.

two activities

  1. MainActivity.java
  2. Play.java

two layouts

  1. activity_main.xml
  2. layoutplay.xml

it shows THE APPLICATION HAS STOPPED UNEXPECTEDLY where is the mistake?

MainActivity.java

package com.example.xxx; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.graphics.Typeface; import android.view.View; import android.view.View.OnClickListener; import android.widget.TextView; public class MainActivity extends Activity implements OnClickListener{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Typeface t= Typeface.createFromAsset(getAssets(), "font.ttf"); TextView tv1= (TextView) findViewById(R.id.textView1); tv1.setTypeface(t); tv1.setOnClickListener(this); } @Override public void onClick(View v) { if(v.getId()==R.id.textView1){ Intent i=new Intent(MainActivity.this,Play.class); MainActivity.this.startActivity(i); } } } 

Play.java

package com.example.xxx; import android.os.Bundle; import android.app.Activity; public class Play extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layoutplay); } } 

activity_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=".MainActivity" > <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:src="@drawable/bouncemenuback" android:contentDescription="@string/menuback" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="10dp" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" style="@style/my" android:text="@string/Play"/> </LinearLayout> </RelativeLayout> 

layoutplay.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=".Play" > </RelativeLayout> 

xxx.manifest

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.xxx" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="9" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.xxx.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> <activity android:name="com.example.xxx.Play" android:label="@string/title_activity_play" > /> </activity> </application> </manifest> 
0

2 Answers 2

1

try by removing unused /> inside <activity android:name="com.example.xxx.Play" ..... > /> </activity> in your AndroidManifest.xml

so your code should be :

<activity android:name="com.example.xxx.Play" android:label="@string/title_activity_play" > </activity> 
Sign up to request clarification or add additional context in comments.

Comments

0

Try replacing your manifest code with this:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.xxx" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="9" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.xxx.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> <activity android:name="com.example.xxx.Play" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.PLAY" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> </manifest> 

Hope this helps :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.