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

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

Related

(R.layout.activity_main)? R is in red color

My error in Android Studio is that it give red R (R.layout.activity_main) in MainActivity.java file. I trid my best to solve error by cleaning and rebilding the projects but can't.
(Android Studio marks R in red with error message "cannot resolve symbol R", but build succeeds)
My Mainactivity.java code is here:
package com.example.zeeshan.myapplication;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
Timer timer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
timer =new Timer();
timer.schedule(new TimerTask() {
#Override
public void run() {
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
finish();
}
}, 5000);
}
}
Following is my AndroidManfifest.xml code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zeeshan.myapplication">
<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>
<activity android:name=".Main2Activity"></activity>
</application>
</manifest>
I was expecting that my app launch succesfuuly but it does not .. plz help me
Try restarting your android studio, if it doesn't fix your problem.
Look at your imports you might have called the same import twice if so remove one of the imports.

The activity must be exported or contain an intent-filter error

When I try to run the code I keep getting this error "The activity must be exported or contain an intent-filter".
I have set the small drop down beside the green run button to "app" and I have also put an intent-filter in my activity in the manifest. But this doesn't help. Hopefully someone can help me.
The code below is of my manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brian.project">
<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"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginSignupActivity.LoginActivity"
android:configChanges="orientation"
android:screenOrientation="portrait">
</activity>
<activity android:name=".HomeActivity"></activity>
<activity android:name=".LoginSignupActivity.SignupActivity"></activity>
<!--<activity android:name="WeightActivity"></activity>-->
</application>
</manifest>
My MainActivity code:
package com.example.brian.project;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.example.brian.project.LoginSignupActivity.LoginActivity;
import com.example.brian.project.LoginSignupActivity.SignupActivity;
public class MainActivity extends AppCompatActivity {
Button Login, Create_Account;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button Login=(Button) findViewById(R.id.btn_login);
Button Create_Account=(Button) findViewById(R.id.btn_create_account);
Login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
openLoginActivity();
}
});
Create_Account.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
openSignupActivity();
}
});
}
public void openLoginActivity() {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
}
public void openSignupActivity() {
Intent intent = new Intent(MainActivity.this, SignupActivity.class);
startActivity(intent);
}
}
Try to use android:exported="true" in the <activity> tag:
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Unexpected error while executing

I searched for this question already but there were no answers that worked for me. Every time I debug my app it gives me this error.
Unexpected error while executing: am start -n "com.example.maomei.passusersystem/com.example.maomei.passusersystem.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Error while Launching activity
Here is my MainActivity code:
public class MainActivity extends AppCompatActivity {
TextView textView1;
Button button1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView1 = (TextView) findViewById(R.id.textView1);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
Intent myIntent = new Intent(MainActivity.this, Main2Activity.class);
MainActivity.this.startActivity(myIntent);
}
}
});
}
}
and my Manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maomei.passusersystem">
<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="com.example.maomei.passusersystem.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main2Activity"
android:label="#string/title_activity_main2"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".Main4Activity"
android:label="#string/title_activity_main4"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".Main5Activity"
android:label="#string/title_activity_main5"
android:theme="#style/AppTheme.NoActionBar">
</activity>
</application>
</manifest>
I realize this question is a couple of years old, but I was having the same problem and I resolved it after reading another stack overflow thread. Try rebuilding the project after deleting the .gradle and .idea directories. Session 'app': Error Launching activity
Try changing the android:name attribute of MainActivity in your manifest file to just .MainActivity
Can you try this without passing the -a -c argument
adb shell am start -n com.package.name/com.package.name.ActivityName
Mira, I just created a new android app using empty activity template, added 1 more activity for checking and below are files that have same code as yours but doesn't have any error.
Only difference is my manifest file has manifest tag which is not present in yours.
Delete the project, recreate the project and copy paste your code safely to the newly generated project.
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maomei.passusersystem">
<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>
MainActivity class
package com.example.maomei.passusersystem;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView textView1;
Button button1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView1 = (TextView) findViewById(R.id.textView1);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
Intent myIntent = new Intent(MainActivity.this, Main2Activity.class);
MainActivity.this.startActivity(myIntent);
}
}
});
}
}

Application crashes upon new Activity

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>

Cannot link xml layout in android when click button

I'm very new in android and i am working on a app.
I meet problem in linking the 2nd page to the 3rd page while clicking the button. I had tried to solve the problem but it do not work. Below is my AndroidManifest.xml
`
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fyp"
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=".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>
<activity
android:name=".BelajarActivity"
android:label="#string/title_activity_main">
</activity>
<activity
android:name=".KnamaActivity"
android:label="#string/title_activity_main">
</activity>
</application>
</manifest>
below is BelajarActivity.java
package com.example.fyp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class BelajarActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.belajar);
Button bnama = (Button) findViewById(R.id.knama);
bnama.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
Intent namaIntent = new Intent(BelajarActivity.this,KnamaActivity.class);
startActivity(namaIntent);
}
});
}
}
This
bnama.setOnClickListener(new Button.OnClickListener() { //this is wrong
...
});
should be
bnama.setOnClickListener(new View.OnClickListener() {
..
});
OnClickListener should be of type View
Just change this line
bnama.setOnClickListener(new View.OnClickListener() {

Categories

Resources