android app one page to another page not working - android

Here I done code for 5 buttons like Aboutus,development,carriers,services,contactus.
Here I clicked about us button that shows errors as unfortunately app closed.
Here is my code :
MainActivity.java
public class MainActivity extends Activity {
Button aboutus,development,service,carriers,contactus;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button aboutus=(Button) findViewById(R.id.aboutus);
aboutus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(v.getContext(),aboutus.class);
startActivity(i);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/aboutus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="About us"
/>
<Button
android:id="#+id/services"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Services"
/>
<Button
android:id="#+id/development"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Development"
/>
<Button
android:id="#+id/carriers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Carriers"
/>
<Button
android:id="#+id/contactus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contact Us"
/>
</LinearLayout>
</RelativeLayout>
aboutus.java
public class aboutus extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aboutus);
}
}
aboutus.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" >
<TextView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Aboutus Page"/>
</LinearLayout>
AndroidManifest.xml is this correct ?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.globalinfosoft"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.globalinfosoft.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= "aboutus"/>
</application>
</manifest>

MainActivity.java
package com.example.a;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button aboutus, development, service, carriers, contactus;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button aboutus = (Button) findViewById(R.id.aboutus);
aboutus.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Starting a new Intent
Intent nextScreen = new Intent(getApplicationContext(),aboutus.class);
startActivity(nextScreen);
}
});
}
}
Here is Androidmanifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.a.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.a.aboutus"></activity>
</application>
</manifest>

Instead of v.getContext() use 'getApplicationContext()'.
Intent i = new Intent(getApplicationContext(),aboutus.class);
startActivity(i);

Try this ..
Button aboutus=(Button) findViewById(R.id.aboutus);
aboutus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),aboutus.class);
startActivity(i);
}
});

First, you should make sure that you have declared the aboutus acitivity in your AndroidManifest.xml file.
<Activity android:name= "aboutus"/>
Second, you can use
Intent i = new Intent(getApplicationContext(),aboutus.class);
or
Intent i = new Intent(MainActivity.this,aboutus.class);
instead of
Intent i = new Intent(v.getContext(),aboutus.class);

Intent i = new Intent(v.getContext(),aboutus.class);
startActivity(i);
instead of code use following code and instruction:
Intent i = new Intent(MainActivity.this,aboutus.class);
startActivity(i);
you have to declare the About us activity on AndroidManifest.xml like this
<Activity android:name= ".aboutus"/>

Related

Starting activity from fragment button click (intent) throws blank screen

I'm trying to start an activity from a button which is placed in a fragment, but when I run the app (in emulator and in a real device) and I press that button, the activity doesn't start and a blank screen whithout navigation bar appears. I've read a lot about this, and the most common error people had is that they didn't declare the Activity or they weren't inflating the correct layout. Any idea would be appreciated, because I don't now what to do right now.
Here is the code of the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.isa.example" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/Theme.CustomMaterial" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NewActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/Theme.CustomMaterial" >
<intent-filter>
<action android:name="com.isa.example.NewActivity" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is the code for the fragment layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start new activity"/>
</RelativeLayout>
Code for the fragment:
public class Fragment1 extends Fragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_fragment1, container, false);
Button button = (Button) view.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getActivity(), NewActivity.class);
startActivity(i);
}
});
return view;
}
}
Code for the new activity layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="This is new activity"
android:id="#+id/textView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
And code for the new activity:
public class NewActivity extends Activity{
#Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.newactivity_layout);
}
}
What is your minimum sdk version? Your version of onCreate is introduced in 21: stackoverflow.com/a/29871359/1541763 Remove the PersistableBundle persistentState from your parameters

unfortunately API demo has stopped while running

I have developed an app for page navigation . when a button is clicked the page should navigate to the second page. when i run the project and opened my app its showing unfortunately API demo has stopped. I have posted the entire code of my app . PLS HELP ME OUT...
//MAIN ACTIVITY
<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" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginLeft="73dp"
android:layout_marginTop="14dp"
android:text="Click" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_alignParentTop="true"
android:layout_marginLeft="14dp"
android:layout_marginTop="34dp"
android:text="Main Activity" />
</RelativeLayout>
//SECONDSCREEN ACTIVITY
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sceond Screen Activity"
tools:context=".SecondScreenActivity"/>
</LinearLayout>
//JAVA CODE FOR MAIN ACTIVITY
package com.example.navigate;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addButtonOnClickEventListener();
}
public void addButtonOnClickEventListener()
{
Button button = (Button)findViewById(R.id.button1);
final Context context = this;
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,SecondScreenActivity.class);
startActivity(intent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
// JAVA CODE FOR SECOND SCREEN ACTIVITY
package com.example.navigate;
import android.app.Activity;
public class SecondScreenActivity extends Activity {
}
// MANIFEST FILE
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.navigate"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.navigate.SecondScreenActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name = "android.intent.action.MAIN"/>
<category android:name = "android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
First problem MainActivity is your launcher page here but you define the secondactivity as luncher in manifest.change it first.
Add an oncreate() to secondactivity otherwise there is nothing to show when the button click.
Third change your MainActivity Context to activity which is MainActivity.this not local
Other things are fine , and hope you understand your small problems..
Change your manifest to something like this:
// MANIFEST FILE
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.navigate.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 = ".SecondScreenActivity" />
</application>
And in your SecondScreenActivity add an oncreate method with the contet view like:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondactivity_layout);
}
And also in your mainactivity change the context to MainActivity.this . Here you define the context inside onclicklistener which links to your local method not the class.

FragmentActivity Buttons to switch between Fragments

All I want to do is a simple Button page switcher between the MainActivity and ArticleGroups pages. I will be implementing a paging class afterwards but I want to get the buttons working first.
Once I run the Application the app will crash and force close so I am certainly doing something wrong.
MainActivity.java
public class MainActivity extends FragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button)findViewById(R.id.articlebtn);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick (View v) {
Intent i = new Intent(MainActivity.this, ArticleGroup.class);
startActivity(i);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?>
<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" tools:context=".MainActivity">
<fragment
android:id="#+id/activitymain_fragment"
android:name="com.dharris.mindfulemployer_v4.MainActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/articlebtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#color/aqua"
android:onClick="onClick" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/articlebtn"
android:layout_alignBottom="#+id/articlebtn"
android:layout_toRightOf="#+id/articlebtn"
android:text="#string/hello_world" />
</RelativeLayout>
ArticleGroup.java
public class ArticleGroup extends FragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.articlegroup);
Button b = (Button) findViewById(R.id.articlebtn);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(ArticleGroup.this, MainActivity.class);
startActivity(i);
}
});
}
}
articlegroup.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/articlegroupfragment"
android:name="com.dharris.mindfulemployer_v4.ArticleGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/articlebtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/aqua"
android:onClick="onClick" />
</RelativeLayout>
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dharris.mindfulemployer_v4"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- Activity Default -->
<activity
android:name="com.dharris.mindfulemployer_v4.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 ArticleGroup -->
<activity
android:name=".ArticleGroup"
android:label="#string/app_name"
></activity>
</application>
</manifest>
If anyone can make sense as to why this is not working then I will be very appreciative.
You have
android:onClick="onClick" />
You need to have a method by name onClick in Activity which takes view as a param
You can remove this
Button b = (Button)findViewById(R.id.articlebtn);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick (View v) {
Intent i = new Intent(MainActivity.this, ArticleGroup.class);
startActivity(i);
}
});
And have
public void onClick(View V)
{
// do something on button click
}
Delete this line from activity_main.xml and articlegroup.xml
android:onClick="onClick"

Unfortunately [app name] has stopped

My Application name is timepass
The below file is MainActivity.java
package com.example.timepass;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity
{
int counter;
Button add, sub;
TextView Display;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter=0;
add= (Button) findViewById(R.id.badd);
sub=(Button) findViewById(R.id.bsub);
Display=(TextView) findViewById(R.id.tvdisplay);
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
Display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter--;
Display.setText("Your total is " + counter);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
The below file is activity_main.xml which is realted to the above file MainActivity.java
<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"
android:background="#drawable/pic_two">"
<Button
android:id="#+id/badd"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvdisplay"
android:layout_alignTop="#+id/bsub"
android:text="#string/but1"
android:textSize="20sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvdisplay"
android:layout_alignRight="#+id/tvdisplay"
android:text="#string/hello_world"
android:textSize="#dimen/asa" />
<TextView
android:id="#+id/tvdisplay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp"
android:gravity="center"
android:text="#string/str1"
android:textColor="#layout/activity_main"
android:textSize="30sp" />
<Button
android:id="#+id/bsub"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvdisplay"
android:layout_below="#+id/tvdisplay"
android:layout_marginRight="38dp"
android:layout_marginTop="23dp"
android:text="#string/but2"
android:textSize="20sp" />
</RelativeLayout>
Then I have created another activity which is below which is Splash.java
package com.example.timepass;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity
{
#Override
protected void onCreate(Bundle tpsavedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(tpsavedInstanceState);
setContentView(R.layout.splash);
Thread timer =new Thread()
{
public void run()
{
try
{
sleep(5000);
}
catch(InterruptedException e)
{ {
e.printStackTrace();
}
finally
{
Intent openMainActivity =new Intent("com.example.timepass.MAINACTIVITY");
startActivity(openMainActivity);
}
}
};
timer.start();
}
}
Then I have created Xml file related to Splash.java which is splash.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"
android:background="#drawable/pic_background">
</LinearLayout>
NOW I WANT TO RUN FIRST Splash.java file then MainActivity.java file so I have make some changes in Androidmanifest.xml file
here are the changes, and after running my program I get error "Unfortunately timepass has stopped" where timepass is my app name . please solve this issue
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.timepass"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.timepass.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="com.example.timepass.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.timepass.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
//just do it like this
Intent openMainActivity =new Intent(this,MainActivity.class);
startActivity(openMainActivity);
instead of
Intent openMainActivity =new Intent("com.example.timepass.MAINACTIVITY");
startActivity(openMainActivity);
MainActivity in your manifest is used in two places. In one place it is in fully capital letter. Change that and give a try
You have an extra { before e.printStackTrace(); in your Splash.java. Remove that and you'll be good to go.
Also post log for furthur errors in the future
I have edited your AndroidManifest.xml update your code after your application work properly.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.timepass"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.timepass.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="com.example.timepass.MainActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
change your code in splash.java
Intent i = new Intent(splash.this, MainActivity.class);
startActivity(i);

Android application crases when switching activity

I have a problem with an Android aplication. When I try to swich from main activity (PretvornikValut) to another one (Pretvornik) via buttun I get the "Unfortunately aplication stopped working" error. Can anyone help?
PretvornikValut.java
package pretvornik.valut;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class PretvornikValut extends Activity implements OnClickListener
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View gumbPretvori = findViewById(R.id.gumb_pretvornik);
gumbPretvori.setOnClickListener(this);
View gumbTecaji = findViewById(R.id.gumb_tecaji);
gumbTecaji.setOnClickListener(this);
}
public void sendMessage(View view) {
Intent intent = new Intent(this, Pretvornik.class);
startActivity(intent);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.gumb_pretvornik:
Intent i = new Intent(this, Pretvornik.class);
//i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
break;
case R.id.gumb_tecaji:
Intent tecaj = new Intent(this, Tecaji.class);
tecaj.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(tecaj);
break;
}
}
}
Pretvornik java
package pretvornik.valut;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
/**
*
* #author FAKS
*/
public class Pretvornik extends Activity {
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.pretvornik);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#99CCCC"
>
<Button
android:id="#+id/gumb_pretvornik"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:text="Pretvornik"
/>
<Button
android:id="#+id/gumb_tecaji"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_toRightOf="#+id/OK"
android:layout_alignParentBottom="true"
android:text="Izpis tecajev"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Izberi zeljeno opcijo"
/>
</LinearLayout>
pretvornik.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#99CCCC"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="glavni program"
/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pretvornik.valut"
android:versionCode="1"
android:versionName="1.0">
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher">
<activity android:name="PretvornikValut"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name="Pretvornik"
android:label="#string/Pretvornik_valut" >
<meta-data
android:name="PretvornikValut"
/>
</activity>
<activity
android:name="Tecaji"
android:label="#string/Izpis_tecajev" >
<meta-data
android:name="PretvornikValut"
/>
</activity>
</activity>
</application>
</manifest>
Change your manifest xml,
add action for your activities
action android:name="android.intent.action.ACTIVITY"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pretvornik.valut"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="PretvornikValut"
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="Pretvornik"
android:label="#string/hello_world" >
<action android:name="android.intent.action.ACTIVITY" />
</activity>
<activity
android:name="Tecaji"
android:label="#string/hello_world" >
<action android:name="android.intent.action.ACTIVITY" />
</activity>
</application>
</manifest>

Categories

Resources