i'm fairly new to coding but decided i would take the huge plunge into the ocean without knowing how to swim, anyway my button keeps failling to open my new activity when i click on it, instead it just crashes. when I run it on my emulator i get a message saying that it has stopped. I'm using a genymotion emulator and the darcula android studio version.
My main activity.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="wrap_content" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#drawable/background_black">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/unpressed_button"
android:background="#drawable/unpressed"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
style="?android:attr/borderlessButtonStyle" />
</RelativeLayout>
My second Activity.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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#drawable/background_black"
tools:context="quirkykoders.flash_flash.Pressed_Button">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pressed_button"
android:background="#drawable/pressed"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
style="?android:attr/borderlessButtonStyle" />
</RelativeLayout>
My Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="quirkykoders.flash_flash" >
<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" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Pressed_Button"
android:label="#string/title_activity_pressed__button" >
<intent-filter>
<action android:name="android.intent.action.PRESSED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
My java
package quirkykoders.flash_flash;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private static Button button_sbm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnClickButtonListener();
}
public void OnClickButtonListener() {
button_sbm = (Button)findViewById(R.id.unpressed_button);
button_sbm.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent ("quirkykoders.flash_flash.Pressed_Button");
startActivity(intent);
}
}
);
}
}
Any help will be greatly appreciated
When you want to create A new Activity you have to send two parameters in the intent object First is currentActivity name and the second is CallingActivity name
Intent intent=new Intent(MainActivity.this,Pressed_Button.class);
startActivity(intent);
Related
We are having a resource error when we try to run our code.
package com.example.searchtest;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class GoogleSearchIntentActivity extends Activity {
private EditText editTextInput;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextInput = (EditText) findViewById(R.id.editTextInput);
}
public void onSearchClick(View v)
{
try {
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
String term = editTextInput.getText().toString();
intent.putExtra(SearchManager.QUERY, term);
startActivity(intent);
} catch (Exception e) {
// TODO: handle exception
}
}
}
<?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:padding="10dp">
<edittext
android:id="#+id/editTextInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter search text">
<requestfocus>
</requestfocus></edittext>
<button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:layout_gravity="center"
android:onclick="onSearchClick"
android:layout_margintop="10dp">
</button></linearlayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.searchtest">
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".GoogleSearchIntentActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
these are our mainActivity.java, activity_main.xml, and AndroidManifest.xml codes from our app.
The error is within our public class GoogleSearchIntentActivity extends Activity
We are high school students trying to create an image search app for our computer science capstone class, we have been trying to fix this error without success, and our teacher is completely clueless.
Components in your xml file must have a first capitalized letter.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10dp">
<EditText
android:id="#+id/editTextInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter search text">
<requestFocus>
</requestFocus></EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:layout_gravity="center"
android:onclick="onSearchClick"
android:layout_margintop="10dp">
</Button></LinearLayout>
I want to create a java page with a Button and a TextBox
So that when the user writes the number 1 in the TextBox and then presses the Button
It will redirect him to open a pdf file from
ex:
www.mywebsite / myfile1.pdf
When the user writes the number 2 in the TextBox and then presses the Button
It will redirect him to open pdf file from
www.mywebsite / myfile2.pdf
Thank you
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter file number"
android:inputType="number"
app:layout_constraintBottom_toTopOf="#+id/Open"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.507" />
<Button
android:id="#+id/Open"
android:layout_width="138dp"
android:layout_height="wrap_content"
android:layout_marginBottom="276dp"
android:text="Open"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
Main_activity.java
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button Open;
EditText Filenumber;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Open=(Button)findViewById(R.id.Open);
Filenumber=(EditText)findViewById(R.id.editText);
Open.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
public void open(){
if(Filenumber.equals("1234"))
Uri.parse("http://www.xmlpdf.com/manualfiles/hello-world.pdf");
if(Filenumber.equals("12345"))
Uri.parse("http://www.google.com");
{
}
}
}
If your pdf source is a link, you can either download the pdf first or open it using WebView. Here is some link that might be of help.
I am new to java coding and Android Studio, so please bear with me. However, I am trying to get a login screen to start after the splash screen and the app crashes after the splash screen. The splash screen works no problem. Anyways, here is the first set of code and this is the splash screen code in Main activity.
package com.example.xxxx.safetyxxxxxxx;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView tv;
ImageView iv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
tv = (TextView) findViewById(R.id.tv);
iv = (ImageView) findViewById(R.id.imageView);
Animation mine = AnimationUtils.loadAnimation(this, R.anim.transition);
final Intent go = new Intent(MainActivity.this, LoginPageActivity.class);
//set duration ... 1 second ... :p
mine.setDuration(1000);
tv.startAnimation(mine);
iv.startAnimation(mine);
//make a thread to go to second activity...
Thread t = new Thread() {
#Override
public void run() {
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
MainActivity.this.startActivity(go);
finish();
}
}
};
t.start();
}
}
this is the Login Page activity called "LoginPageActivity.java" that I would like to have the app go to after the splash screen.
package com.example.xxxx.safetyxxxxxxx;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import static com.example.xxxx.safetyxxxxxxx.R.layout.activity_login_page;
public class LoginPageActivity extends AppCompatActivity implements View.OnClickListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_login_page);
findViewById(R.id.textViewSignUp).setOnClickListener(this);
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.textViewSignUp:
startActivity(new Intent(this, SignUpActivity.class));
break;
}
}
}
This is the androidmanifest.xml code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xxxx.safetyxxxxxxx">
<application
android:name=".Database"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginPageActivity"
android:label="#string/app_name">
</activity>
<activity android:name=".Main2Activity" />
<activity android:name=".SignUpActivity" />
</application>
</manifest>
Here is the logcat error
1-28 12:55:33.490 7647-7670/com.example.xxxx.safetyxxxxxxx E/AndroidRuntime: FATAL EXCEPTION: Thread-5
Process: com.example.xxxx.safetyxxxxxxx, PID: 7647
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.xxxx.safetyxxxxxxx/com.example.xxxx.safetyxxxxxxx.LoginPageActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1932)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1615)
at android.app.Activity.startActivityForResult(Activity.java:4472)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at android.app.Activity.startActivityForResult(Activity.java:4430)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
at android.app.Activity.startActivity(Activity.java:4791)
at android.app.Activity.startActivity(Activity.java:4759)
at com.example.mike.safetychecker.MainActivity$1.run(MainActivity.java:39)
Also if needed the file activity_login_page.xml code is below
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginPageActivity">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="Hi, Welcome to Safety xxxxxx Please Login or Signup"
android:textAlignment="center"
android:textColor="#android:color/holo_green_dark"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.995"
tools:layout_editor_absoluteX="0dp"
tools:ignore="MissingConstraints" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="398dp"
tools:ignore="MissingConstraints" />
<EditText
android:id="#+id/editTextEmail"
android:layout_width="346dp"
android:layout_height="50dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:ems="10"
android:hint="email"
android:inputType="textEmailAddress"
android:text=" email"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="270dp"
tools:ignore="MissingConstraints" />
<EditText
android:id="#+id/Password"
android:layout_width="346dp"
android:layout_height="50dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:ems="10"
android:inputType="textVisiblePassword"
android:text=" Password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="336dp"
tools:ignore="MissingConstraints" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="219dp"
android:layout_height="229dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="#+id/editTextEmail"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/safetyxxxx" />
<TextView
android:id="#+id/textViewSignUp"
android:layout_width="351dp"
android:layout_height="34dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Do Not Have An Account? Click Here"
android:textAlignment="center"
android:textColor="#android:color/holo_green_dark"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.529"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="459dp"
tools:ignore="MissingConstraints" />
</android.support.constraint.ConstraintLayout>
Also there is this transition.xml file contained in a anim folder that might help
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha="1.0"
/>
you have to try to open your LoginPageActivity like this way
Paste this code
openActivity();
instead of this
Thread t = new Thread() {
#Override
public void run() {
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
MainActivity.this.startActivity(go);
finish();
}
}
};
t.start();
and put this method
public void openActivity()
{
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Intent go = new Intent(MainActivity.this,LoginPageActivity.class);
startActivity(go);
finish();
}
}, 5000);
}
import this packages
import android.os.Bundle;
import android.os.Handler;
and also mention in your manifest like this
<activity android:name=".LoginPageActivity"
android:label="#string/app_name"/>
You have to declare your Activity in your AndroidManifest.xml. Almost all of your system-related classes have to be declared in it, this includes Activities, Services, BroadCast Receivers. You can read up on how Manifest works over here
Back to your problem, you can fix it by add the following line inside the application tag in your Android Manifest. Remove any intent filters you have applied to it
<activity android:name=".LoginPageActivity" />
Remove :
<intent-filter>
<action android:name="com.example.xxxx.safetyxxxxxxx.LoginPageActivity" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Because there is always remains only one LAUNCHER activity in application. And also intent filter is wrong there.
change LAUNCHER TO DEFAULT in your mainfest, Two launcher is not possible at same time (Assuming MainActivity as LAUNCHER)
</activity android:name=".LoginPageActivity>
<intent-filter>
<action android:name="com.example.xxxx.safetyxxxxxxx.LoginPageActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
use this
<activity android:name=".LoginPageActivity"
android:label="#string/app_name"/>
instead of
<activity android:name=".LoginPageActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.example.xxxx.safetyxxxxxxx.LoginPageActivity" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(MainActivity.this,com.example.xxxx.safetyxxxxxxx.LoginPageActivity.class);
startActivity(intent);
finish();
}
}, 5000);
//where 5000 is the delayed time
I am a novice and I'm just creating a simple Android app in which there are 2 buttons that take you to different pages when clicked, which have different functions.
However, my app crashes on start-up, simply saying
Unfortunately [app name] has stopped
and I don't understand
As I have barely made any changes to my MainActivity.java, the code seems to be well written, and eclipse displays no errors... Any help, please? I have searched around Stack, but I can't find anything specific to this...
Here is my MainActivity.java:
package com.example.helper;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#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;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**Called upon when the user clicks the 'Abbreviations' button*/
public void listDefinitions (View view){
Intent intent = new Intent(this, ListDefinitions.class);
startActivity(intent);
}
/**Called upon when the user clicks the 'Assistant' button*/
public void openAssistant (View view){
Intent intent = new Intent(this, Assistant.class);
startActivity(intent);
}
}
Here is my 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="com.example.legittest.MainActivity" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="#string/intro_title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="21.5sp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="#string/module_selection"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/definitions_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginLeft="34dp"
android:layout_marginTop="111dp"
android:text="#string/definitions"
android:onClick="listDefinitions" />
<Button
android:id="#+id/assistant_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/definitions_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:text="#string/assistant"
android:onClick="openAssistant" />
<TextView
android:id="#+id/definitions_explainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/definitions_button"
android:layout_centerHorizontal="true"
android:text="#string/definitions_info"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/greycolor" />
<TextView
android:id="#+id/pa_explainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/definitions_explainer"
android:layout_below="#+id/assistant_button"
android:text="#string/assistant_info"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/greycolor" />
</RelativeLayout>
My ListDefinitions.java & Assistant.java are untouched at this point.
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.theocratichelper"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<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=".ListDefinitions"
android:label="#string/title_activity_list_definitions"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.theocratichelper.MainActivity" />
</activity>
<activity
android:name=".PreachAssistant"
android:label="#string/title_activity_preach_assistant"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.theocratichelper.MainActivity" />
</activity>
</application>
</manifest>
It's your manifest, replace the "last" activity in your manifest by this :
<activity
android:name=".Assistant"
android:label="#string/title_activity_preach_assistant"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.theocratichelper.MainActivity" />
</activity>
Your class name is Assistant and not PreachAssistant i presume.
Just replace the last activity in Android Manifest by this.
<activity
android:name=".Assistant"
android:label="#string/title_activity_preach_assistant"
</activity>
I thought I did everything right but when I click the button I get a blank page instead of a page with a text. I want that the creation.xml comes up after clicking the button on the main xml. What did I wrong ?
My main activity 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"
android:background="#drawable/creeper" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/hello"
android:textSize="20sp" />
<Button
android:id="#+id/button1"
android:layout_width="200dp"
android:layout_height="60dp"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:textSize="20sp"
android:text="#string/button1_text" />
</RelativeLayout>
My main activity java
package com.berkcoop.deneme;
import android.os.Bundle;
import android.app.Activity;
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 {
Button button1, button2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent1 = new Intent(MainActivity.this, Creation.class);
startActivity(intent1);
}
});
}
My creation 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="50dp"
android:text="Creations"
android:textSize="25sp"
android:gravity="center"/>
</LinearLayout>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.berkcoop.deneme"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.berkcoop.deneme.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.berkcoop.deneme.Creation"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
and my creation java
package com.berkcoop.deneme;
import android.app.Activity;
public class Creation extends Activity{
#Override
public void setContentView(int layoutResID) {
// TODO Auto-generated method stub
super.setContentView(R.layout.creation);
}
}
Thank you..
Why do you override the setContentView method in your Creation class? Since you don't call it, it won't set the correct view.
You should call setContentView from onCreate, and as far as I know, there is no need to override setContentView.
Try this in Creation:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.creation);
}