Android: onBackPressed() causes application to crash - android

I am attempting to use the onBackPressed() method provided by android in order to
The class that I am using the onBackPressed() method:
import com.interviewme.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class Preparing extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preparation);
}
#Override
public void onBackPressed() {
Intent t = new Intent(this, Menu.class);
startActivity(t);
}
}
The part of the manifest file where I am trying to go back to:
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The full manifest file of the app:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.interviewme"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.interviewme.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.interviewme.Play"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.PLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.interviewme.Result"
android:label="#string/title_activity_result" >
</activity>
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.interviewme.menu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.interviewme.About"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.interviewme.InterviewTips"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.interviewme.Preparing"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
The error log from logcat:
05-09 08:09:43.420: E/AndroidRuntime(1741): FATAL EXCEPTION: main
05-09 08:09:43.420: E/AndroidRuntime(1741): Process: com.interviewme, PID: 1741
05-09 08:09:43.420: E/AndroidRuntime(1741): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.interviewme/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
05-09 08:09:43.420: E/AndroidRuntime(1741): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
05-09 08:09:43.420: E/AndroidRuntime(1741): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
http://androidmanifest.xml/
androidmanifest.xml
I notice that It states ActivityNotFound, however this Activity is definitely within my app, is it named incorrectly in manifest?

its picking android default Menu
remove this line
import android.view.Menu;
and import your class or change your class name Menu to another name(eg. Menu1)

You imported android.view.Menu. Try writing out com.interviewme.Menu instead. Also use better names for your activities. Menu is kind of ambiguous.

Error showing because below:-
import android.view.Menu;
Intent t = new Intent(this, Menu.class);
startActivity(t);
Your code pick view.Menu.
you have to use :-
Intent t = new Intent(this, com.interviewme.Menu.class);// where menu class here
startActivity(t);

Related

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myapp/androidx.fragment.app.FragmentActivity}

I am using BottomNavigation Menu in my app which has 4 submenus: Address, Dashboard, Home, Notifications.
When I want to startActivity from HomeFragment to Dashboard Fragment it gives me error that I have depicted below.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.karatasyazilim.su, PID: 21216
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.karatasyazilim.su/androidx.fragment.app.FragmentActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2069)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1717)
at android.app.Activity.startActivityForResult(Activity.java:5252)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:675)
at androidx.core.app.ActivityCompat.startActivityForResult(ActivityCompat.java:234)
at androidx.fragment.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:790)
at androidx.fragment.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:932)
at androidx.fragment.app.Fragment.startActivity(Fragment.java:1257)
at androidx.fragment.app.Fragment.startActivity(Fragment.java:1245)
at com.karatasyazilim.su.ui.home.HomeFragment$5.onClick(HomeFragment.java:333)
at android.view.View.performClick(View.java:7869)
at android.widget.TextView.performClick(TextView.java:14958)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992)
at android.view.View.performClickInternal(View.java:7838)
at android.view.View.access$3600(View.java:886)
at android.view.View$PerformClick.run(View.java:29362)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8016)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1087)
My manifest is :
<?xml version="1.0" encoding="utf-8"?>
<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.Su">
<activity android:name=".CreateAddress"></activity>
<activity android:name=".PhoneActivation" />
<activity
android:name=".Genel"
android:label="#string/title_activity_genel" />
<activity android:name=".SignUp" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
</application>
And here is my activiy code.
Intent kalimera = new Intent(getActivity(), FragmentActivity.class);
startActivity(kalimera);
What am I doing wrong?
You're trying to start the androidx FragmentActivity class directly. This is a parent class that you should subclass to create your own Activity.
Instead, make sure that you're using the name of the Activity you want to launch instead:
Intent intent = new Intent(getActivity(), NameOfTheActivityThatYouWantToLaunch.class);
startActivity(intent);
Alternately, if you aren't trying to launch an Activity and just got this code from somewhere, simply remove those lines.
If you're trying to launch a Fragment instead, take a look at How to start Fragment from an Activity

Fatal Exception applicationId is null Parse

This is my second question in SO, I have a problem about Fatal Main error. Before I ask it, I found some other problem in SO, but what I found is about Facebook app
This is my error
java.lang.RuntimeException: applicationId is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
But, I have a class that declared it
package com.example.michael.eksperimen6chatting;
import android.app.Application;
import com.parse.Parse;
/**
* Created by Michael on 03/12/2015.
*/
public class ChattApp extends Application
{
#Override
public void onCreate()
{
super.onCreate();
Parse.initialize(this, "urkcFwvUmgSYvuOFTInJmkA3iWv0ArV3XT128TNb", "WvBC0cnGXHkVhTBbkFwLyxGDRgqR6qC8ft7DIleT");
}
}
and this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.michael.eksperimen6chatting" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<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" >
</activity>
<activity android:name=".UserList"></activity>
<activity android:name=".Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Chat">
</activity>
</application>
</manifest>
Did I miss something here, can anyone help me? Gratia
Specifying ChattApp Application class name in your AndroidManifest.xml's <application> tag.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:name="com.example.michael.eksperimen6chatting.ChattApp">
....
</application>
import com.parse.Parse;
import android.app.Application;
public class ChattApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(this);
Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
}
}
AndroidManifest.xml
<application
android:name="com.example.michael.eksperimen6chatting.ChattApp"
.
.
.
</application>

Adding Shared Library Project Android

I'm struggling with adding a library to my project. I've been following a few other SOs as well as the tictactoemain/lib sample Android provides, but I'm still getting a "unable to find explicit activity class" error. The library package I included showing up under Android Dependencies is com.example.surveymetest. I suspect the issue is how I'm calling/defining the activity in the manifest but I can't seem to get it right. Any ideas where I'm going wrong?
Here's my manifest:
<uses-permission android:name="android.permission.INTERNET" />
<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.surveymedemo.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.surveymetest.SurveyActivity"
android:label="#string/app_name" >
</activity>
<activity android:name="com.example.surveymetest.TakeSurveyActivity" >
</activity>
<provider
android:name="com.example.surveymetest.SurveyMeContentProvider"
android:authorities="io.surveyme.ContentProviders.SurveyMeContentProvider"
android:exported="true" >
</provider>
</application>
</manifest>
Calling the Activity:
package com.example.surveymedemo;
import com.example.surveymetest.StartSurveyActivity;
import com.example.surveymetest.SurveyMe;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = new Intent(this, StartSurveyActivity.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;
}
}
Add:
<activity
android:name="com.example.surveymetest.StartSurveyActivity"
android:label="#string/app_name" >
</activity>
to your manifest and you should be good.
(you only defined com.example.surveymetest.SurveyActivity)

Android : Fatal Exception Main toast

Hi i always have this error: Android : Fatal Exception Main!! It's my first app and so i have several problems..i can't understand how android works :( :
package com.mkyong.android;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.example.toast.R;
public class MainActivity extends Activity {
private Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), "Button is clicked", Toast.LENGTH_LONG).show();
}
});
}
}
This is the main.xml:
<?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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/show_toast"
tools:ignore="HardcodedText" />
</LinearLayout>
This is the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.toast"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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>
</application>
</manifest>
Here's the logcat output:
First of all I think You had copied the Code Form Mykong
It's shown that you MainActivity.java is in package com.mkyong.android
But in your manifest file your main package name is com.example.toast .You haven't mention any about files in com.mkyong.android in your manifest file
Are you sure you are using tow package names ?? if so
So there are two options
OPTION 1
In your log it clearly says com.example.toast.MainActivity is not found
You must change the package of MainActivity.java to com.example.toast
<activity
android:name="com.example.toast.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>
This will remove the RuntimeException
OPTION 2
The second option is to change in manifest file
<activity
android:name="com.mkyong.android.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>
Note That if you application contains more than one package names you must specify the package name along with along with activity names in manifest file
eg : android:name="com.mkyong.android.MainActivity" where com.mkyong.android is package name and MainActivity is file name
I Prefer you to choose OPTION 1
To display you toast you can use
Toast.makeText(MainActivity.this, "Button is clicked", Toast.LENGTH_LONG).show();
Here MainActivity.this is the parameter for context
You can also use this
Toast.makeText(getApplicationContext(), "Button is clicked",Toast.LENGTH_LONG).show();
If you are beginner This Android Boot Camp Series Tutorial might help you
Change Application context to your context and try
Toast.makeText(MainActivity.this, "Button is clicked", Toast.LENGTH_LONG).show();

Google Maps NoClassDefFoundError

I'm working on an android project in which one of the activities includes a Maps view. I'm only after doing the code for displaying a simple Google Map but I bumped into this NoClassDefFoundError. I have checked some similar questions and tried the suggested solutions but still won't work. I have activated the Internet permision in the manifest file and the user library for the application. Does anyone have any suggestions on what might be the problem? Here's the activity code:
package com.mad.mylit;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class LocationsActivity extends MapActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
And here's my manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mad.mylit"
android:versionCode="1"
android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<uses-library android:name="com.google.android.maps"/>
<activity
android:name=".MyLitActivity"
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=".MapsActivity"></activity>
<activity android:name=".MyProfileActivity"></activity>
<activity android:name=".BusActivity"></activity>
<activity android:name=".EventsActivity"></activity>
<activity android:name=".LocationsActivity"></activity>
<activity android:name=".NotesActivity"></activity>
<activity android:name=".TimetableActivity"></activity>
<activity android:name=".MondayActivity"></activity>
<activity android:name=".TuesdayActivity"></activity>
<activity android:name=".WednesdayActivity"></activity>
<activity android:name=".ThursdayActivity"></activity>
<activity android:name=".FridayActivity"></activity>
<activity android:name=".CaherdavinActivity"></activity>
<activity android:name=".RaheenActivity"></activity>
<activity android:name=".UniversityActivity"></activity>
<activity android:name=".SplashScreen"
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>
All of the activities are in the same package.
Try to get new maps API key with your personal keystore.
Have you recently updated your ADT plugin?
Here and here are some talks about same prblem..

Categories

Resources