I have a very simple application that works but when i add roboguice it throws
java.lang.RuntimeException: Unable to instantiate application
com.MyFirstApp.MyFirstApplication: java.lang.ClassNotFoundException:
com.MyFirstApp.MyFirstApplication
The application class:
public class MyFirstApplication extends RoboApplication {
#Override
protected void addApplicationModules(List<Module> modules) {
//modules.add(new DefaultModule());
}
}
The MainActivity:
public class MainActivity extends RoboActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
the manifest:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MyFirstApp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name="MyFirstApplication">
<activity
android:name="com.MyFirstApp.Activities.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>
I have put guice-2.0-no_aop.jar and roboguice-1.1.3.jar in the assets folder and added them to the buildpath.
when i remove the robo part it works fine. can anyone tell me what i did wrong.
Well i found out what the problem was. i was using SDK v17+ and in that version external library's need te be placed in a "libs" folder and only in the libs folder. so all the tutorial's i found where they just put it in the assets folder where wrong.
Link to where i got the answer i was looking for: http://groups.google.com/group/roboguice/browse_thread/thread/474116b052050ae2
First of all, extending from RoboApplication is a RoboGuice 1.x thing, you should really be using RoboGuice 2.0 (where you no longer need to do that). Now, for your exception, is your Application class really at com.MyFirstApp.MyApplication? If not, you would need to update the name attribute to match.
Related
So my problem is I'm getting Class not found error while running the app on my device.
"io.tutorial.app.App" class not found at the path io.tutorial.app
Actually the class App.java is present at that path and also my class is extending MultiDexApplication .
What I found so far is two dex files have generated in the built apk namely classes.dex and classes2.dex. The weird thing is the package "io.tutorial.app" is present at both dex files (I think this is the issue). There's no classes present at the "io.tutorial.app" package in the classes2.dex file but all my classes are present in classes.dex file under the same package "io.tutorial.app". Please help me to find a solution to this.
Manifest:
<application
android:theme="#style/AppTheme"
android:label="#string/app_name"
android:icon="#mipmap/ic_app"
android:name="io.tutorial.app.App"
android:allowBackup="true"
android:supportsRtl="true"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:theme="#style/AppTheme.NoActionBarFullScreen"
android:name=".ui.activity.SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Gradle:app
https://pastebin.com/JpkRZY1G
App Class:
public class App extends MultiDexApplication {
#Inject
Cache cache;
public void onCreate() {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
super.onCreate();
initRemoteConfig();
Injector.getInstance().init(this);
Injector.getInstance().appComponent().inject(this);
initFabric();
initRealm();
initPicasso();
initRemoteConfig();
initAds();
initOneSignal();
}
I'd have that #Inject annotation under suspicion - or the use of Injector.
try to use MultiDex.install() instead:
public class App extends Application {
...
#Override
protected void attachBaseContext(Context context) {
super.attachBaseContext(context);
MultiDex.install(this);
}
}
I have two Android projects. One is a library and compiles a jar the other an executable which includes this jar on the build path.
I'm subclassing an activity in the jar in my project but when I start it I'm getting a ClassNotFoundException.
Here's the manifest with the activity in question being MainActivity:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.package.MyProject"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:label="#string/app_name"
android:name=".MyApplication"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
<activity android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here is my MainActivity, where the QCARSamples package is found in my jar:
package com.my.package.MyProject;
import java.io.File;
import com.qualcomm.QCARSamples.ImageTargets.GraphicsEngineHook;
import com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity;
import com.my.package.MyProject.R;
public class MainActivity extends VuforiaTrackingActivity{
private File blenderFile;
#Override
protected synchronized void updateApplicationStatus(final int appStatus){
return;
}
#Override
protected GraphicsEngineHook getGraphicsEngineHook() {
return new MyGraphicsEngineHook();
}
#Override
protected int getSplashScreenImageResource() {
return R.drawable.splash_screen_image_targets;
}
}
I also tried including the activity I'm subclassing in my manifest like so, but I was still getting the same error:
<activity>
<android:name="com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity>
</activity>
Any ideas?
The problem is usually on the BuildPath.
Assuming you're using eclipse and ADT:
Right click on your project, select Build Path -> Configure Build Path -> Order and Export and make sure that your library is selected.
Remember to clean the project before trying again.
it could also be the class path as the guy suggested on the commented, on the manifest, instead of editing direct the XML, go to the Application tab, select the activity, click Browser, uncheck 'Display classes from sources of Project ...', and select the Activity from your library.
I downloaded actionbar sherlock library from the main site itself. and i tried to use it in my app.
import com.actionbarsherlock.app.SherlockActivity;
import android.os.Bundle;
public class Sherlockactivity extends SherlockActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
but when i started the app with the default main.xml layout, i get this exception.
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.sherlock/com.android.sherlock.SherlockActivity}: java.lang.ClassNotFoundException: com.android.sherlock.SherlockActivity in loader dalvik.system.PathClassLoader[/data/app/com.android.sherlock-1.apk]
my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.sherlock"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock" >
<activity
android:name=".SherlockActivity"
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>
i just started to use support libraries. have no idea how to solve this.
Thank you
Download sherlock action bar zip.
New->android project from existed source
choose library folder from sherlock bar folder
in the properties of your project, ->android->add library and set the folder that you copy.
See Using an ActionBar in your Android app with ActionBarSherlock.
I've done the setup as described for ActionBarSherlock. I've also added ABS as a library project and believe this is working as expected as Eclipse is finding references to class's within it's packages. I've also set the theme as required in the code and in the AndroidManifest.xml:
Code:
import com.actionbarsherlock.app.SherlockActivity;
public class TestClass extends SherlockActivity{
Context myContext;
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_Sherlock_NoActionBar);
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.danieljgmaclean.xxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/px_icon"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.Light" >
<activity
android:name="TestClass"
android:label="#string/app_name"
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
However apon execution i'm getting the following exception thrown:
Caused by: java.lang.RuntimeException: Couldn't find content container view
This is being called on:
com.danieljgmaclean.xxx.TestClass.onCreate(TestClass.java:23)
I'm running the code on a 2.3.3 emulator and i've set the target build to 4.0.3 and JDK version to 1.6.
Any ideas would be appreciated.
In my case the problem was a "raw" folder inside res which contained the db of the app. So I just removed the folder and the actionbar worked again. Now the problem is that I need the raw...
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?