thread exiting with uncaught exception (group=0x40a3b1f8) - android

Ever since I included AdMob into my app everytime I run it and click on a button that goes to a page with Ads on it all I get its "thread exiting with uncaught exception (group=0x40a3b1f8)"
Main java:
package com.co500.gdsg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class GameDevStoryGuideActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button co = (Button) findViewById(R.id.combinations);
co.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.COMBINATIONS"));
}
});
Button jb = (Button) findViewById(R.id.jobs);
jb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.JOBS"));
}
});
Button ty = (Button) findViewById(R.id.type);
ty.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.TYPE"));
}
});
Button con = (Button) findViewById(R.id.consoles);
con.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.CONSOLES"));
}
});
Button gen = (Button) findViewById(R.id.genre);
gen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.GENRE"));
}
});
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="preferExternal"
package="com.co500.gdsg"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|uiMode|screenSize|smallestScreenSize"
></activity>
<activity
android:name=".GameDevStoryGuideActivity"
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=".Genre"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.GENRE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Combinations"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.COMBINATIONS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Consoles"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.CONSOLES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Notgood"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.NOTGOOD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Hmm"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.HMM" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Notbad"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.NOTBAD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Creative"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.CREATIVE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Amazing"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.AMAZING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Jobs"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.JOBS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Type"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.TYPE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
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"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/genre"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Game Genre Unlocks" />
<Button
android:id="#+id/consoles"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Consoles" />
<Button
android:id="#+id/combinations"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Combinations" />
<Button
android:id="#+id/type"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Game Type Unlocks" />
<Button
android:id="#+id/jobs"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Jobs" />
</LinearLayout>
consoles.xml (similar to the other xmls)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/consoleavail" />
</LinearLayout>
</ScrollView>
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adUnitId="empty for a reason"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
logcat:
07-13 15:16:13.770: D/dalvikvm(4567): GC_FOR_ALLOC freed 17K, 2% free 7848K/8007K, paused 14ms
07-13 15:16:13.780: I/dalvikvm-heap(4567): Grow heap (frag case) to 9.377MB for 1769056-byte allocation
07-13 15:16:13.810: D/dalvikvm(4567): GC_CONCURRENT freed 2K, 2% free 9573K/9735K, paused 2ms+2ms
07-13 15:16:13.830: D/AndroidRuntime(4567): Shutting down VM
07-13 15:16:13.830: W/dalvikvm(4567): threadid=1: thread exiting with uncaught exception (group=0x40a3b1f8)
07-13 15:16:13.830: E/AndroidRuntime(4567): FATAL EXCEPTION: main
07-13 15:16:13.830: E/AndroidRuntime(4567): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.co500.gdsg/com.co500.gdsg.Consoles}: android.view.InflateException: Binary XML file line #23: Error inflating class com.google.ads.AdView
07-13 15:16:13.830: E/AndroidRuntime(4567): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-13 15:16:13.830: E/AndroidRuntime(4567): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)

you are using this below statement
startActivity(new Intent("com.co500.gdsg.CONSOLES"));
Which is causing problem.
use
startActivity(new Intent(ActivityName.this,CONSOLES.class);
first param of Intent should be a context and second should be the className.this is a target class
P.S :- it will show error as ActivityName not found, Please replace ActivityName with your Activity Name.

Related

Main activity not starting

I have two activities in my program one where you type something into a text field then click a button to send it to another where it is displayed. Though, the one where it is being displayed shows up first.
It may be that they start at the same time, I'm not sure.
My main activity
public class MainActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE = " com.mycompany.myfirstapp.MESSAGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startActivity(new Intent(getApplication(), second.class));
}
public void sendMessage(View view) {
Intent intent = new Intent(this, second.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
// Do something in response to button
}
The xml file that goes with
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:id="#+id/button"
android:singleLine="false"
android:focusableInTouchMode="true"
android:onClick="sendMessage" />
<EditText
android:layout_height="wrap_content"
android:id="#+id/edit_message"
android:hint="#string/edit_message"
android:layout_weight="1"
android:layout_width="0dp" />
</LinearLayout>
</RelativeLayout>
My android manifest
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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=".second"
android:label="#string/title_activity_second"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mycompany.myfirstapp.MainActivity" />
</activity>
</application>
My second .java file
public class second extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
Well if you're going to invoke the second.class with an intent, you're going to need an intent-filter marked inside the activity of the manifest. This is similar to that of the first class.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
So your android manifest should look something like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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=".second"
android:label="#string/title_activity_second"
android:parentActivityName=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mycompany.myfirstapp.MainActivity" />
</activity>
Learn more about the Intents here.
Your line:
startActivity(new Intent(getApplication(), second.class));
starts the second activity as soon as the first one starts.
Remove this line as you are already doing what you need to in your sendMessage().

Android Title Bar and Icon

When my app starts up i see the title bar and the application name with a white activity.
Even though my mainactivity is a splash screen, it does not start at first, but after 2 seconds of this Title bar and white activity. How do i disable this.
thanks for the help!
Splash.java
`public class Splash extends Activity {
#Override
protected void onCreate(Bundle parameter) {
// TODO Auto-generated method stub
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
super.onCreate(parameter);
Thread timer= new Thread()
{
#Override
public void run()
{
try
{
//Display for 3 seconds
sleep(3000);
}
catch (InterruptedException e)
{
// TODO: handle exception
e.printStackTrace();
}
finally
{
//Goes to Activity StartingPoint.java(STARTINGPOINT)
Intent openstartingpoint=new Intent("com.vault.beta.MAINACTIVITY");
startActivity(openstartingpoint);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
`
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vault.beta"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
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=".MainActivity"
android:label="Vault - Login" >
<intent-filter>
<action android:name="com.vault.beta.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Screen"
android:label="Calender" >
<intent-filter>
<action android:name="com.vault.beta.SCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MenuList"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.vault.beta.MENULIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Password"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.vault.beta.PASSWORD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".EditNote"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.vault.beta.EDITNOTE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Remove the theme of the main activity
android:theme="Theme.Holo.NoActionBar"

Application force closes when button is pressed

I've just began on a new application and I added a button which in the past I've had no problem with but for some reason Its not working now. I'm just simply trying to teacher that button to another page. What do you think the problem is? (just ignore the spinners I haven't set those up yet)
TextingprojectActivity
public class TextingprojectActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button tut1 = (Button) findViewById(R.id.tutorial1);
tut1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("practice.practice.TUTORIALONE "));
}
});
}
}
Tutorial1 Java
public class TutorialOne extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial1);
}
}
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:orientation="vertical" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/place_arrays"
android:prompt="#string/Place"/>
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/tutorial1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/save"
/>
</LinearLayout>
tutorial1 XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="practice.practice"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TextingprojectActivity"
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=".TutorialOne"
android:label="#string/app_name">
<intent-filter>
<action android:name="practice.practice.TUTORIALONE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
change your intent call like
Intent n = new Intent(TextingprojectActivity.this,TutorialOne.class);
startActivity(n);
Also remove the intent-filter from the delaration of the rest activity from maniefst.
<intent-filter>
<action android:name="practice.practice.TUTORIALONE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Change it to like...
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TextingprojectActivity"
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=".TutorialOne"
android:label="#string/app_name">
</activity>
</application>
Change your intent call to
Button tut1 = (Button) findViewById(R.id.tutorial1);
tut1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent n = new Intent(TextingprojectActivity.this,TutorialOne.class);
startActivity(n);
}
});
if simply need to redirect to second activity Change your code as
Button tut1 = (Button) findViewById(R.id.tutorial1);
tut1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(TextingprojectActivity.this,TutorialOne.class););
}
});
And Remove this Block From your manifest XML
<intent-filter>
<action android:name="practice.practice.TUTORIALONE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
What is this practice.practice.TUTORIALONE???

multiple button activities on same page - android eclipse

I've tried searching for many methods of utilizing multiple buttons on the same page. I can get the first button to work but the second and third buttons force-close. Does anyone have any idea why this may be? I think that it might be the syntax - but I could be wrong since I'm new to this. Thanks in advance.
Main Java:
package com.pangolin.rollin.ts;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class TeamSupport extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_team_support);
Button wireless=(Button)findViewById(R.id.button_wireless);
Button tools=(Button)findViewById(R.id.button_tools);
Button about=(Button)findViewById(R.id.button_about);
wireless.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myintent1 = new Intent(TeamSupport.this,Wireless.class);
startActivity(myintent1);
}
});
tools.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myintent2 = new Intent(TeamSupport.this,Tools.class);
startActivity(myintent2);
}
});
about.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myintent3 = new Intent(TeamSupport.this,About.class);
startActivity(myintent3);
}
});
}
}
Main XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/make_selection"
android:textColor="#3F9BBF" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView3"
android:layout_centerHorizontal="true"
android:text="#string/beta_notice"
android:textColor="#3F9BBF" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/credits"
android:textColor="#3F9BBF" />
<Button
android:id="#+id/button_wireless"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:text="#string/button_wireless"
android:textColor="#3F9BBF" />
<Button
android:id="#+id/button_tools"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/button_wireless"
android:text="#string/button_tools"
android:textColor="#3F9BBF" />
<Button
android:id="#+id/button_about"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/button_tools"
android:text="#string/button_about"
android:textColor="#3F9BBF" />
</RelativeLayout>
Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pangolin.rollin.ts"
android:installLocation="auto"
android:versionCode="1"
android:versionName="Beta 0.1" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".TeamSupport"
android:label="#string/title_activity_team_support" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Wireless"
android:label="#string/title_activity_wireless"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".About"
android:label="#string/title_activity_about"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".Tools"
android:label="#string/title_activity_tools"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
You just implement OnClickListener.
now tools.setOnClickListener(this);
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.R.id.button_wireless:
Intent myintent1 = new Intent(TeamSupport.this,Wireless.class);
startActivity(myintent1);
break;
}
please try this is work better and occupy memory less.
Remove the following code
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
from manifest.xml
Wireless ,About and Tool Activity Tags

android button click not working in program

Hello everybody i have a problem that when i click a button it remains as it is instead of starting new activity. I searched he problem in this site and found some solutions but none of them worked for me so i am writing my problem here.
the xml layout is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/profile_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/profile" />
<Button
android:id="#+id/create_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="#string/create_profile" />
<Button
android:id="#+id/edit_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/create_profile"
android:text="#string/edit_profile" />
<Button
android:id="#+id/delete_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/edit_profile"
android:text="#string/delete_profile" />
<Button
android:id="#+id/activate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/delete_profile"
android:text="#string/activate" />
<ListView
android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/create_profile"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#id/profile_title" />
<TextView
android:id="#id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/create_profile"
android:layout_below="#id/profile_title"
android:gravity="center_vertical|center_horizontal"
android:text="#string/no_profiles" />
</RelativeLayout>
and the activity is
package com.android.SmartSwitch;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Profile_Manager extends Activity {
private Button createButton;
private Button editButton;
private Button deleteButton;
private Button activateButton;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);
setUpViews();
}
private void setUpViews() {
createButton = (Button)findViewById(R.id.create_profile);
editButton = (Button)findViewById(R.id.edit_profile);
deleteButton = (Button)findViewById(R.id.delete_profile);
activateButton = (Button)findViewById(R.id.activate);
createButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(Profile_Manager.this, Add_Profile.class);
startActivity(intent);
}
});
editButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
deleteButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
activateButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
}
}
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.SmartSwitch"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".SmartSwitchActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Location_Manager" android:label="#string/app_name"/>
<activity android:name=".Profile_Manager" android:label="#string/app_name"/>
<activity android:name=".Schedule_Manager" android:label="#string/app_name"/>
<activity android:name=".Location_In_Map" android:label="#string/app_name"/>
<activity android:name=".Add_Profile" android:label="#string/app_name"/>
<uses-library android:name="com.google.android.maps" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>
When i click createButton, it doesn't respond
As your Main Activity i.e., Profile_Manager consists of the following Code:
<activity
android:label="#string/app_name"
android:name=".SmartSwitchActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You have to note if the Profile Manager class is the class which will be launched i.e., if Profile_Manager Class is the First Screen then, you should create the above code in AndroidManifest.xml with the only change as android:name=".Profile_Manager" instead of "SmartSwitchActivity" with the code additionally added for Add_Profile class as follows
<activity
android:label="#string/app_name"
android:name=".Add_Profile" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I suppose by doing this changes,things will work fine.
If you are not able to understand the above working then,Here is the Link with Perfect Working Example and with available Source Code-Correct Working of Button Click

Categories

Resources