I have created an android application with a simple login page, when i try run the app though i keep getting the same error. Can someone please tell me what I am missing here? Below are my android manifest and my two activities java classes.
Main Activity (Login) -
package com.example.squashsademo;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText mTextUsername;
EditText mTextPassword;
Button mButtonLogin;
TextView mTextViewRegister;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
mTextUsername = (EditText)findViewById(R.id.edittext_username);
mTextPassword = (EditText)findViewById(R.id.edittext_password);
mButtonLogin = (Button)findViewById(R.id.button_login);
mTextViewRegister.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
Intent RegisterIntent = new Intent(MainActivity.this,Register_Activity.class);
startActivity(RegisterIntent);
}
});
mButtonLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, PlayerInfo.class));
}
});
}
}
Register Activity -
package com.example.squashsademo;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Register_Activity extends AppCompatActivity {
EditText mTextEmail;
EditText mTextUsername;
EditText mTextPassword;
EditText mTextCnfPassword;
Button mButtonRegister;
TextView mTextViewLogin;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register_);
mTextUsername = (EditText)findViewById(R.id.edittext_username);
mTextPassword = (EditText)findViewById(R.id.edittext_password);
mTextCnfPassword = (EditText) findViewById(R.id.edittext_cnf_password);
mButtonRegister = (Button)findViewById(R.id.button_register);
mTextViewLogin = (TextView)findViewById(R.id.txtViewLogin);
mTextViewLogin.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
Intent LoginIntent = new Intent(Register_Activity.this,MainActivity.class);
startActivity(LoginIntent);
}
});
}
}
Android Manifest -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.squashsademo">
<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/Theme.SquashSADemo">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".Register_Activity" />
<activity android:name=".PlayerInfo" />
</application>
</manifest>
You have to replace
<action android:name="android.intent.category.LAUNCHER" />
with
<category android:name="android.intent.category.LAUNCHER" />
in your AndroidManifest.xml file.
Related
From first activity to second activity navigation is working but second activity to third activity navigation is not working in android can any1 please help me.
This is my MainActivity.java
package com.exampl.test;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.app.Activity;
import android.view.View;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void activity2(View view){
Intent intent = new Intent(this,com.exampl.test.MainActivity2.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;
}
}
This is my MainActivity2.java
package com.exampl.test;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity2 extends Activity {
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity2);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
public void activity3(View view){
Intent intent = new Intent(this,com.exampl.test.MainActivity3.class);
startActivity(intent);
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
}
This is my MainActivity3.java
package com.exampl.test;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity3 extends Activity {
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity3);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
}
This is my appmanifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exampl.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
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="com.exampl.test.MainActivity2"
android:label="#string/title_activity_main_activity2"
android:parentActivityName="com.exampl.test.MainActivity" >
</activity>
<activity
android:name="com.exampl.test.MainActivity3"
android:label="#string/title_activity_main_activity3"
android:parentActivityName="com.exampl.test.MainActivity2" >
</activity>
</application>
</manifest>
please help me wt to modify in above coding
Thanks in advance
Try This!
MainActivity
package com.example.acct;
import com.example.acct.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button =(Button) findViewById(R.id.button1);
Toast.makeText(this, "Activity1", Toast.LENGTH_SHORT).show();
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
activity2();
}
});
}
public void activity2() {
Intent intent = new Intent(this, com.example.acct.MainActivity2.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;
}
}
MainActivity2
package com.example.acct;
import com.example.acct.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity2 extends Activity {
Button button;
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActionBar().setDisplayHomeAsUpEnabled(true);
button = (Button) findViewById(R.id.button1);
Toast.makeText(this, "Activity2", Toast.LENGTH_SHORT).show();
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
activity3();
}
});
}
public void activity3() {
Intent intent = new Intent(this, com.example.acct.MainActivity3.class);
startActivity(intent);
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
}
MainActivity3
package com.example.acct;
import com.example.acct.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity3 extends Activity {
Button button;
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
Toast.makeText(this, "Activity3", Toast.LENGTH_SHORT).show();
getActionBar().setDisplayHomeAsUpEnabled(true);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
activity3();
}
});
}
public void activity3() {
Intent intent = new Intent(this, com.example.acct.MainActivity3.class);
startActivity(intent);
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.acct"
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.example.acct.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=".MainActivity2"
android:parentActivityName=".MainActivity" >
</activity>
<activity
android:name=".MainActivity3"
android:parentActivityName=".MainActivity2" >
</activity>
</application>
</manifest>
My Main Activity class is as follows
package com.example.barnight2;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView date;
private Button taxiButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
dateAndTime();
}
public void addListenerOnButton() {
taxiButton = (Button) findViewById(R.id.btnTaxi);
taxiButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent taxiIntent = new Intent(MainActivity.this, TaxiActivity.class);
startActivity(taxiIntent);
}
});
}
public void dateAndTime() {
date = (TextView) findViewById(R.id.lblDate);
SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
Date day = new Date();
String dayOfTheWeek = sdf.format(day);
date.setText(dayOfTheWeek);
}
}
then i have my second activity called the Taxi Activity
package com.example.barnight2;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class TaxiActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_taxi);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.taxi, menu);
return true;
}
}
Here is my Manifest.xml i thought i had done everything perfectly but it seems to always crash upon start up of the app
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.barnight2"
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.example.barnight2.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.barnight2.TaxiActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
![image]http://i62.tinypic.com/16rma8.png
ClassCastException
you're casting an object that it's not the same type you're trying to cast, so that's why it throw a RunTimeException with ClassCastException.
It should be:
taxiButton = (ImageButton) findViewById(R.id.btnTaxi);
Since you declared it as ImageButton in xml.
Please remove :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
from your activity com.example.barnight2.TaxiActivity in the AndroidManifest.xml
I am currently working on a fahrenheit to celsius converter android app. I tried runing the app on the emulator and every time it gives "your app has stopped suddenly" error. tried many things like increasing ram of emulator, rebooting . I also added the activity to manifest.xml.
The mainactivity.java code
package com.example.yoyo;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.Menu;
public class MainActivity extends Activity {
EditText input;
EditText answer;
TextView celsius;
TextView fahrenheit;
Button convert;
#Override
protected void onCreate(Bundle savedInstanceState)
{
this.findAllViewsById();
convert.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
String query = input.getText().toString();
answer.setText(query);
}
});
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;
}
public void findAllViewsById()
{
input = (EditText) findViewById(R.id.Input);
answer= (EditText) findViewById(R.id.Answer);
convert= (Button) findViewById(R.id.ConvertButton);
celsius= (TextView) findViewById(R.id.celsius);
fahrenheit= (TextView) findViewById(R.id.fahrenheit);
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yoyo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.yoyo.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>
</application>
</manifest>
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.findAllViewsById();
convert.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
String query = input.getText().toString();
answer.setText(query);
}
});
}
first of all the super.onCreate has to been your onCreate does. Second thing you can not do all related findViewById operations if you has not called setContentView
so here is another basic problem i'm having...my application crashes as i try to pass a string to another activity. i have tried a few ways but in vain. here's the code
Main Activity named Main.java
package com.ammad.test;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Main extends Activity {
TextView tv;
Button b1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tvShow);
b1 = (Button) findViewById(R.id.bt1);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Bundle basket = new Bundle();
String myScore = "testing";
basket.putString("key", myScore);
Intent intent = new Intent(Main.this, Second.class);
intent.putExtras(basket);
startActivity(intent);
}
});
}
}
Second class to which the data is passes named Second.java
package com.ammad.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Second extends Activity{
TextView tv;
String getScore;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
tv= (TextView) findViewById(R.id.tvRes);
Bundle gotBasket = getIntent().getExtras();
getScore = gotBasket.getString("key");
tv.setText(getScore);
}
}
and finally the manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ammad.test"
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=".Main"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Sec"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="com.ammad.test.SECS" />
</intent-filter>
</activity>
</application>
</manifest>
Seems to me your second activity is declared wrong in the manifest, as .Sec not .Second as would be expected - the log is probably showing a exception because the intent was invalid.
I'm trying to make a list view in a page that is liked form a button,
but when I debug the application it shows only a black page with the name.
I have 2 java
one xml to de main page
and one mainfest.xml
page 1:
package tm.andrioid.com;
import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.Button;
public class indexActivity extends Activity
{
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
Button bprodukter = (Button) findViewById(R.id.bprodukter);
bprodukter.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(indexActivity.this, produkter.class);
startActivity(i);
}
});
}``
}
page 2 java:
tm.andrioid.com;
import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class produkter extends ListActivity {
String classes[] = { "indexActivity", "Data", "Intim", "Hörlurar", "Prylar",
"Mat", "Sex", "Sju"};
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(produkter.this,
android.R.layout.simple_list_item_1));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String saker = classes[position];
try{
Class ourClass = Class.forName("tm.android.com." + saker);
Intent ourIntent = new Intent(produkter.this, ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
main xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tm.andrioid.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/tmm"
android:label="#string/app_name" >
<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=".indexActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="tm.android.com.INDEXACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".produkter"
android:label="#string/app_name" >
<intent-filter>
<action android:name="tm.android.com.PRODUKTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Replace
setListAdapter(new ArrayAdapter<String>(produkter.this,
android.R.layout.simple_list_item_1));
with this:
setListAdapter(new ArrayAdapter<String>(produkter.this,
android.R.layout.simple_list_item_1, classes));
let me know if this works.