Application crashes upon new Activity - android

I know and I do understand that this question has been asked, but I can't seem to interpret it for my application. I am creating an application - using Android Studio - that opens a Activity (called 'About'). When a user clicks on the 'about button' on my MainActivity, it should launch the 'About' activity. However, when I test this out on my device, it says the app has stopped. And on my output panel, it says something about an error with my Manifest.xml file?
MainActivity:
package com.msp.supercarsounds;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void clickedAbout(View view) {
final int result = 1;
Intent AboutButtonClicked = new Intent (this, About.class);
AboutButtonClicked.putExtra("About", "MainActivity");
startActivityForResult(AboutButtonClicked, result);
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.msp.supercarsounds">
<uses-sdk android:minSdkVersion="17"
android:targetSdkVersion="22"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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>
Thank you for your help and time!

You have to declare About activity
<activity android:name=".About">
</activity>
Add this below the </activity> tag of MainActivity

your second activity "about" is not added to manifest.xml add this under the mainactivity
<activity android:name=".about">/activity>

Related

".MainActivity" in <activity android:name=".MainActivity"> is not a concrete class

When inspecting my code, I get an error in the AndroindManifest.xml saying that
".MainActivity" in <activity android:name=".MainActivity"> is not a concrete class.
The App is, therefore, crashing in the Emulator of Android Studio.
Here is the Java Code of the Application:
package de.thi.donotpressthebutton;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
final MediaPlayer audio = MediaPlayer.create(this, R.raw.niggaz_audio );
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
audio.start();
}
});
}
}
And here is the XML Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.thi.donotpressthebutton">
<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"> **//error**
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
If your mainactivity.java is not in the package root directory, you should add the folder name. For example, mainactivity.java in the com.balbala.holleworld/View/folder should be <activity android:name=".view.MainActivity"> instead of <activity android:name=".view.MainActivity">. Hope to solve your problem.
The other Reason For this Type Of Error Might Be That You Have Accidentally Used "Abstract"
Keyword Before the Activity Name That Might Have Caused The Problem In The Project

Unable to find explicit activity class exception even if the class is declared in the projects manifest

I transformed my project into a library. This project just displays a blank activity. I imported this library into another project where I want to call it thru the projects main activity but I keep on getting the error below even if I already declared the activity inside the projects manifest.
Unable to find explicit activity class {com.package.name/com.package.name.BatibotActivity}; have you declared this activity in your AndroidManifest.xml?
This is my project manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pak.paks.pocket" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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="com.package.name.BatibotActivity"
android:screenOrientation="portrait" >
</activity>
</application>
</manifest>
What am I doing wrong?
edit:
this is my BatibotActivity
package com.package.name;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class BatibotActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_batibot);
}
}
EDIT2
This is the class that is calling the BatibotActivity
package pak.paks.pocket;
import android.content.ComponentName;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void submitBtn(View view) {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("com.package.name",
"com.package.name.BatibotActivity"));
startActivity(intent);
}
}
By the log message, you are trying to open com.package.name/com.package.name.BatibotActivity, but the Activity registered on AndroidManifest.xml is pak.paks.pocket/com.package.name.BatibotActivity.
The first parameter for ComponentName is the package name. This is the correct code:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("pak.paks.pocket", "com.package.name.BatibotActivity"));
startActivity(intent);
Please check your manifest tag's package attr.
<manifest package="com.package.name">
<application>
...
</application>
</manifest>

Unfortunately [yourapp], has stopped

I'm using intent method to make a simple app that takes you from main screen [with an enter button] to another screen which has three options. Code sourced online and seems to be error free, though my app crashes saying "Unfortunately [yourapp], has stopped" immediately after i press the button which is meant to take to the the other screen.
This is my first activity code:
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.enterBtn);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, HomeActivity.class);
startActivity(intent);
}
});
}
}`
And this is my landing screen's activity code:
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class HomeActivity extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
}
}
I'm really stuck with this issue and any help would be much appreciated. Many thanks in advance.
Every activity needs to be added in your manifest file under application tag. This seems to be the problem in your case.
Try to post you LogCat so that we might get some more information and if you have not yet added your Activity in the manifest, this is the way of adding it (Activities go under application tag)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.southmp3"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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=".HomeActivity"
android:label="#string/app_name" >
</activity>
</application>
all the Activities should be going under the application tag
I had forgotten to register my new activity on the androidmanifest.xml file. That's what sorted my app crash issue.

Activity not found, no idea why

I'm trying to open a new activity using this code:
myListView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(Andro.this, Aktivity.class);
startActivity(intent);
}
});
The activity to be opened looks like this:
package com.andro;
import android.app.Activity;
import android.os.Bundle;
public class Aktivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
try
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
} catch(Exception e)
{
}
}
}
It is in the same package as the other activity, and in the same directory.
The manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andro"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="#string/app_name" >
<activity android:name="Andro"
android:theme="#android:style/Theme.NoTitleBar"
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=".Aktivity">
</activity>
</application>
</manifest>
I've tried with different names like '.Aktivity' '.com.andro.Aktivity' 'Aktivity' 'com.andro.Aktivity'
I delete the bin and gen directories before building.
But still I always get an Activity not found exception in logcat.
Any help is appreciated.
The logcat seems to be showing
com.andro.Andro$Aktivity not found
I think there is another class called Aktivity inside Andro class. So try using this
Intent in = new Intent();
ComponentName comp = new ComponentName("com.andro", "com.andro.Aktivity");
in.setComponent(comp);
startActivity(in);
Doesn't this work
<activity android:name="com.andro.Aktivity" ........ />
Can you try
<activity android:name=".Andro"
android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name">
instead:
<activity android:name="Andro"
android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name">
Edit:
It seems like a problem about your Andro Activity.
Unable to find explicit activity class {com.andro/com.andro.Andro$Aktivity};
If you are using a listview in your activity, make sure you extend "ListActivity" as:
public class Andro extends ListActivity
Try cleaning your project and restarting eclipse.

Cannot load new blank activity - android tutorial

I am a new android developer and encountered a problem while following the tutorial on Android's site - http://developer.android.com/training/basics/firstapp/starting-activity.html
My program loads on the emulator fine, but when you type something into the EditText and then hit the send button, a window pops up saying "App has stopped working". It seems as though my new activity isn't being created and I'm not sure as to why. I've scoured the web (and my code) to see if I could get a solution but did so to no avail. Any help would be appreciated.
The code for my first activity:
package com.example.appli;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myapp.MESSAGE";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testlayout);
//////Button myButton = (Button) findViewById(R.id.my_button); //Told in tutorial to put this in onCreate
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
/** Called when the user selects the Send button */
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
The code for my second activity (the one being called)
package com.example.appli;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class DisplayMessageActivity extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//get message from intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
}
}
The Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.appli"
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="com.example.myapp.DisplayMessageActivity" />
<activity
android:name=".MainActivity"
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>
</application>
</manifest>
In AndroidManifest File you have declared incorrect package
change
<activity android:name="com.example.myapp.DisplayMessageActivity" />
to
<activity android:name="com.example.appli.DisplayMessageActivity" />
or just
<activity android:name=".DisplayMessageActivity" />
you have declared only one Activity that's also wrong package name
already your manifest has the package name
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.appli"
so just declare like this
<activity android:name=".DisplayMessageActivity" />
and you need to add this in your manifest also
<activity android:name=".MainActivity />
remove the target SDK version that you mentioned
android:targetSdkVersion="15"
Try this
<activity android:name=".DisplayMessageActivity"/>
Instead of
<activity android:name="com.example.myapp.DisplayMessageActivity" />
in your Manifest.xml file.
You has defined the package package com.example.appli; in your activities.
Why have you defined you activity in manifest like <activity android:name="com.example.myapp.DisplayMessageActivity" />?
Replace this line with
<activity android:name=".DisplayMessageActivity" />.

Categories

Resources