Subclass activity from a jar getting ClassNotFoundException - android

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.

Related

Parse Error: There was a problem parsing the package

I try to resolve this error from various methods in my Hello World App.These are;
-Go to Security-->Unknown sources.
-Go to About phone-->Build number.
-Update my manifest file whose picture is given below.
-Test app both on phone Y625 Huawei and on tablet T1-701u tab.
-Reboot android phone and android studio (version 3.4.1).
-Transfer apk file via data cable or airmove software.
But none of them works to solve the issue.
I develop my Hello World. Firstly i faced insufficient heap size error issue which has solved on the temporary basis. After build up my app, Parsing the package issue has emerged.
Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hw04">
<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.java
package com.example.hw04;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Parse Error
There was a problem parsing the package enter code here

Eclipse - new android activity showing in manifest but missing under src

I created a new blank activity from Eclipse's 'New' menu.
I didn't get any errors, and the activity looks to have been correctly populated in the manifest, however, no java class file has been created.
I get the impression that within Eclipse, the class should have been auto-created and auto-populated with the onCreate and onOptionsItemSelected method templates.
Why didn't Eclipse automatically create the class for me?
Manifest code as requested:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstandroidapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.myfirstandroidapp.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.myfirstandroidapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstandroidapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstandroidapp.MainActivity" />
</activity>
</application>
The fastest solution: keep the Activity in your manifest, but create the java class by right-clicking your package -> new -> class -> DisplayMessageActivity and then extend the Activity class and add the missing methods. Note that the class name have to match the one declared in the manifest
EDIT
After you've done it, clean the project by selecting project -> clean and check if there are any error messages left
I needed to uninstall Eclipse and install the sdk (adt bundle) from http://developer.android.com/ which comes bundled with eclipse to resolve this issue.
I found that my original set-up not only failed to create source files, but was also unable to create new android projects, even though it managed to create the first project successfully. Something must have happened to ruin the set up, no doubt, something I did but cannot trace.
What worked for me...
In eclipse, go to Help >
Install new software... > Work with: https://dl-ssl.google.com/android/eclipse/
Hit enter, checkmark "Developer Tools" and "NDK Plugins".
Let it download and install. I had to delete "myfirstapp" and remake it.
Restart Eclipse once it has downloaded and installed.
Having that issue and actually doing it over again helped me understand more about the syntax used in the lessons that I've already been through before.

ActionBarSherlock - SherlockActivity issue - Couldn't find content container view

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...

Simple android application with roboguice throwing exceptions

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.

Android app crashes on load - classNotFoundException

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?

Categories

Resources