Android app crashes on load - classNotFoundException - android

This has been driving me mad for a couple of days :)
IDEA is my weapon of choice. During an editing session of inconsequential changes (or so I thought) of adjusting layouts, nudging buttons a few pixels left to line up etc I compiled and ran the project. I got a ClassNotFoundException when my app starts. It is thrown by java.lang.Bootloader. I put a breakpoint on the call to the Bootloader and can see that the offending class is my main application class. Here's how it looks:
public class Rands extends Application{
public static SharedPreferences preferences;
private static ArrayList<Favourite> favourites;
private static Rands instance;
public Rands(){
instance = this;
}
and in the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="rands.mycompany.com"
android:installLocation="preferExternal"
android:versionCode="8"
android:versionName="0.8">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.VIBRATE" />
<application android:name="rands.mycompany.com.Rands"
android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name="rands.mycompany.com.RandsMainActivity"
android:theme="#android:style/Theme.Translucent.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="rands.mycompany.com.MainMenuActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="MainMenuActivity"/>
This is where things get funky. There is NOTHING of relevance in logcat. I see the app copying, installing and starting then I get the exception. The exception occurs before the constructor on my application class is called. If I load the project in Eclipse, it works fine. I load in back into IDEA and I get the exception. I have two phones, a Desire with 2.3 and a Tmobile Pulse (Huawei) with 2.2. It happens on both phones and in the emulator. If I run the app outside the IDE (i.e. from the launcher) it runs fine.
I make these assumptions:
As there is nothing in logcat, it smells like a platform bug
As the project works fine in Eclipse, I'm assuming that my manifest and application class are fine.
I've also tried
<application android:name=".Rands"
Any clues?
Cheers

I finished my project in Eclipse then came back for another go at this weird problem.
I have no idea why, but creating a new project from the existing sources worked right away.
I moved the project folder out of my workspace, deleted everything except my src and res folders (no assets) and the manifest then created a new project from existing sources.
Go figure...

you have already specify the package name in menifest tag so don't redeclare it in activity tag, below code will work for menifest.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="rands.mycompany.com"
android:installLocation="preferExternal"
android:versionCode="8"
android:versionName="0.8">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.VIBRATE" />
<application android:name="rands.mycompany.com.Rands"
android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name=".Rands"
android:theme="#android:style/Theme.Translucent.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=".MainMenuActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="MainMenuActivity"/>

Your Application and Activity objects are both named as "rands.mycompany.com.Rands" maybe that's the problem?

Related

"Could not identify launch activity: Default Activity not found" - Android Studio - no answers working

Whenever trying to run the app, getting the error:
"Could not identify launch activity: Default Activity not found".
I have seen a few other threads on the same issue, but the below solutions have not worked for me:
Invalidating gradle cache and re-running
Manually overriding in the edit configuration tab to select the default activity (it then says "The activity 'MainActivity' is not declared in AndroidManifest.xml" even though it is!)
Re-syncing the gradle files
Literally shuffling around the order of the activities in my manifest
Using the long name for my activities, but doesn't make any difference
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mywebname">
<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:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
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=".ListenScreen"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait">
</activity>
</application>
</manifest>
```
As you can see, I have clearly declared the activities (my app only has 2 so far), and I've put the intents around the ".MainActivity".
This answer worked for me after trying so many other tweaks, just adding the package name solved my problems
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.name">
https://stackoverflow.com/a/72300233/8720836
You can only have to add the package name inside the manifest tag you can find your package name inside app.gradle file and you are good to go

"Session 'app': Error launching activity" all of the sudden?

I am currently running into this issue without even knowing why.
It was working fine yesterday and I just added more code to each activity.
I have already perfomed "Invalidate Cache/Restart" and Restarted my computer.
Note that I did not change anything in the Manifest.xml nor have I added a new activity to the Project.
Here's the AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<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=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".RegisterActivity" />
<activity android:name=".MainScreenActivity" />
<activity android:name=".StatisticsActivity" />
<activity android:name=".UnlockablesActivity"></activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
Any help would be greatly appreciated.
Edit: I have already tried to Rebuild and Clean multiple times. Same error.
The error is a little pop-up on the left corner saying "Error running app: Default Activity not found".
When setting the Default Activity in the settings to Nothing, this error appears in logcat when accessing a different activity.
It is not the full log but you can see that it references Line 25 in LoginActivity (the supposed Default Activity) which leads to its onCreate() function.
I've had exactly the same error a week ago, here's the link to my question. I couldn't find the origin of the error, it is probably a bug with Android Studio (I've had the same thing with all my projects).
I've resolved it by deleting the .AndroidStudio hidden directory in your user folder. Keep in mind, it deletes all the settings you've set before and it will reset Android Studio from scratch.

Installed test APK does not appear on device's main screen

I installed an instrumentation test APK from Eclipse(Run->Run As Android application) on device as the log shows below.
[2013-08-08 22:14:13 - SettingsTests] /SettingsTests/bin/SettingsTests.apk installed on device
However, on the home screen of the device, somehow the test APK does not show. In Settings->Application Manager, the list shows the test apk correctly.
Any idea what's going on?
The android system info shows:
Source:/data/app/PACKAGE.test.test-1.apk
data:/data/app/PACKAGE.test.test
Here's the test apk's manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="PACKAGE.test.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="17" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="my.package" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
</manifest>
Only the activity defined in manifest like below will be shown. You must define at least one activty like that.
<activity
android:name="YourActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
What you are trying to install doesn't have an activity defined in the manifest.
As per the docs
An activity is that implements part of the application's visual user interface.
All activities must be represented by <activity> elements in the manifest file.
Any that are not declared there will not be seen by the system and will never be run.
You can refer the document so as to have an idea how activity works
It's quite normal behavior, as you don't have any activity in your instrumentation package. Didn't you mean to run it as Android JUnit Test?

Android app does not start (and is invisible!) on device

I have a strange problem with my Android app. When I start it from Netbeans, the app gets installed on my device (attached via USB). After that nothing happens. I also can't find the app anywhere on the device!! (no icon, no nothing).
Still I know the app has been installed, because under the android settings, where it says "Manage Applications" (or something) the app is now listed and I can uninstall it.
I've tried the whole procedure with a blank HelloWorld app, which worked fine. Here an icon got created o the device and the app was started correctly by NetBeans.
So I guess there is something wrong with my app causing it not to appear in the phone's launcher?
EDIT:
Here's the manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="4" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name" android:debuggable="true">
</application>
you need to add below line in your Main activity in androidmanifest file
<activity android:label="#string/app_name"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

application not installing on android emulator

I am running tab based application in android.When i try to install the application on the emulator it gives output in the console as
[2011-03-08 12:40:35 - TabBar] Application already deployed. No need to reinstall.
[2011-03-08 12:40:35 - TabBar] \TabBar\bin\TabBar.apk installed on device
[2011-03-08 12:40:35 - TabBar] Done!
Can anyone tell how should i pursue
Thanks in advance
Tushar
I'm also tackled with this same problem and finally I found the solution for it. When you creating a new android project using Eclipes and if you didn't create a activity for your first window, your project's Manifest also don't create proper codings for you to application launch up.
So, you should hardcode them yourself.
First check these codes are available or not in your Project's Manifest file, within your main activity tags.
**
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
**
These two code lines are very important. Because these two lines are calling to android OS to launch this app.
So, Make sure these codes are available in your project's Manifest file. If it's not this below Manifest file code will gets you rough idea to fix this problem.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mershanfernando.testingappz"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name">
<activity android:name=".Main"
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>

Categories

Resources