Application fails to bind service - android

I am trying to bind a service which is included in a Library project with the following lines:
Intent i = new Intent();
i.setClassName("de.ring0", "de.ring0.ToolkitService");
bindService(i, this, Context.BIND_AUTO_CREATE);
The binding process fails with the debug output below. According to the Android developer documentation the options in the two manifest files should be correct.
AndroidManifest.xml Library Project
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.ring0">
<uses-sdk android:minSdkVersion="8" />
<application android:debuggable="true">
<service android:name="de.ring0.ToolkitService" android:exported="true" android:enabled="true"/>
</application>
</manifest>
AndroidManifest.xml Main Project
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.ring0.example.tactilecompass"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true">
<activity android:name=".TactileCompassActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="de.ring0.ToolkitService" />
</application>
</manifest>
Debug Log from emulator
W/ActivityManager( 59): Permission denied: checkComponentPermission() reqUid=10036
W/ActivityManager( 59): Permission Denial: Accessing service ComponentInfo{de.ring0/de.ring0.ToolkitService} from pid=2994, uid=10037 requires null
W/dalvikvm( 2994): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 2994): FATAL EXCEPTION: main
E/AndroidRuntime( 2994): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.ring0.example.tactilecompass/de.ring0.example.tactilecompass.TactileCompassActivity}: java.lang.SecurityException: Not allowed to bind to service Intent { cmp=de.ring0/.ToolkitService }
E/AndroidRuntime( 2994): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime( 2994): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime( 2994): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime( 2994): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime( 2994): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2994): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2994): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 2994): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2994): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 2994): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 2994): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 2994): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2994): Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { cmp=de.ring0/.ToolkitService }
E/AndroidRuntime( 2994): at android.app.ContextImpl.bindService(ContextImpl.java:874)
E/AndroidRuntime( 2994): at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
E/AndroidRuntime( 2994): at de.ring0.example.tactilecompass.TactileCompassActivity.onCreate(TactileCompassActivity.java:28)
E/AndroidRuntime( 2994): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 2994): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime( 2994): ... 11 more
W/ActivityManager( 59): Process de.ring0.example.tactilecompass has crashed too many times: killing!
W/ActivityManager( 59): Force finishing activity de.ring0.example.tactilecompass/.TactileCompassActivity
I/Process ( 59): Sending signal. PID: 2994 SIG: 9

Use:
new Intent(this, de.ring0.ToolkitService.class);

Related

Error when adding widget : Unfortunately, "MyApp" has stopped

I made an app with a widget, and when I add or remove the widget on my phone, or restart my phone with the widget on my homescreen, it comes up with an error "Unfortunate, Clock has stopped." (Clock is the name of my app.) The widget works fine, but I need to get rid of the error message. Eclipse didn't say that there was any problem.
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tzemachzr.clock"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
<activity
android:name="com.tzemachzr.clock.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>
<receiver android:name="com.tzemachzr.clock.ClockWidgetProvider">
<intent-filter>
<action
android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/clock_appwidget" />
</receiver>
</application>
</manifest>
Widget Layout
<?xml version="1.0" encoding="utf-8"?>
<AnalogClock xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</AnalogClock>
App Widget Provider (res-xml-clock_appwidget.xml)
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="140dp"
android:minWidth="140dp"
android:initialLayout="#layout/clock_appwidget_layout" android:resizeMode="horizontal|vertical">
</appwidget-provider>
Logcat
E/AndroidRuntime( 5480): FATAL EXCEPTION: main
08-12 15:56:27.433 E/AndroidRuntime( 5480): java.lang.RuntimeException: Unable to instantiate receiver com.tzemachzr.clock.ClockWidgetProvider: java.lang.ClassNotFoundException: com.tzemachzr.clock.ClockWidgetProvider
08-12 15:56:27.433 E/AndroidRuntime( 5480): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2383)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at android.app.ActivityThread.access$1500(ActivityThread.java:139)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1322)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at android.os.Looper.loop(Looper.java:156)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at android.app.ActivityThread.main(ActivityThread.java:4977)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at java.lang.reflect.Method.invoke(Method.java:511)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at dalvik.system.NativeStart.main(Native Method)
08-12 15:56:27.433 E/AndroidRuntime( 5480): Caused by: java.lang.ClassNotFoundException: com.tzemachzr.clock.ClockWidgetProvider
08-12 15:56:27.433 E/AndroidRuntime( 5480): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-12 15:56:27.433 E/AndroidRuntime( 5480): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2378)
08-12 15:56:27.433 E/AndroidRuntime( 5480): ... 10 more
08-12 15:56:27.453 D/Launcher.Model( 1729): DbDebug Add item (null) to db, id: 66 (-100, 2, 0, 2)
08-12 15:56:27.453 E/EmbeddedLogger( 1598): App crashed! Process: com.tzemachzr.clock
08-12 15:56:27.453 E/EmbeddedLogger( 1598): App crashed! Package: com.tzemachzr.clock v1 (1.0)
08-12 15:56:27.463 E/EmbeddedLogger( 1598): Application Label: Clock
08-12 15:56:27.513
You got a ClassNotFoundException, that means that android doesnt find the class
com.tzemachzr.clock.ClockWidgetProvider
Edit:
Okay, it seems that the basics arent clear.
You need a class, named ClockidgetProvider.
This class extends AppWidgetProvider and uses the meta data, stored in your clock_appwidget.xml.
So, when you declare a receiver in your Android manifest, android creates a receiver, which consists of your AppWidgetProvider class and your meta data.
See example:
package com.tzemachzr.clock;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
public class ClockWidgetProvider extends AppWidgetProvider {
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
Your meta data xml file is correct.
Add this class and see ,whether is solves your problem or not.
PS: you can set flags, by simply call:
System.out.println("hello");
This will print "hello" in your Logcat!

My android app keeps crashing when I launch it

I recently got some app source code. So I imported to Eclipse and renamed application package. It all went well until I tried launch the app. When I do it instantly crashes. I was wondering why. This is the log:
E/ActivityManager( 215): heap conf. property name string trimmed: hs.com.shadycorp.MoonStoneMarbl
E/AndroidRuntime( 5644): FATAL EXCEPTION: main
E/AndroidRuntime( 5644): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.shadycorp.MoonStoneMarble/theHardestGame.pac.GameLogicController}: java.lang.ClassNotFoundException: theHardestGame.pac.GameLogicController in loader dalvik.system.PathClassLoader[/data/app/com.shadycorp.MoonStoneMarble-1.apk]
E/AndroidRuntime( 5644): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1580)
E/AndroidRuntime( 5644): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
E/AndroidRuntime( 5644): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 5644): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
E/AndroidRuntime( 5644): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 5644): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 5644): at android.app.ActivityThread.main(ActivityThread.java:3735)
E/AndroidRuntime( 5644): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 5644): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 5644): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
E/AndroidRuntime( 5644): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
E/AndroidRuntime( 5644): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 5644): Caused by: java.lang.ClassNotFoundException: theHardestGame.pac.GameLogicController in loader dalvik.system.PathClassLoader[/data/app/com.shadycorp.MoonStoneMarble-1.apk]
E/AndroidRuntime( 5644): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
E/AndroidRuntime( 5644): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
E/AndroidRuntime( 5644): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime( 5644): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 5644): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1572)
E/AndroidRuntime( 5644): ... 11 more
E/AndroidRuntime( 5644): [Blue Error Handler] Make Debugging Report file for main
E/AndroidRuntime( 5644): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.shadycorp.MoonStoneMarble/theHardestGame.pac.GameLogicController}: java.lang.ClassNotFoundException: theHardestGame.pac.GameLogicController in loader dalvik.system.PathClassLoader[/data/app/com.shadycorp.MoonStoneMarble-1.apk]
E/AndroidRuntime( 5644): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1580)
E/AndroidRuntime( 5644): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
E/AndroidRuntime( 5644): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 5644): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
E/AndroidRuntime( 5644): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 5644): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 5644): at android.app.ActivityThread.main(ActivityThread.java:3735)
E/AndroidRuntime( 5644): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 5644): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 5644): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
E/AndroidRuntime( 5644): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
E/AndroidRuntime( 5644): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 5644): Caused by: java.lang.ClassNotFoundException: theHardestGame.pac.GameLogicController in loader dalvik.system.PathClassLoader[/data/app/com.shadycorp.MoonStoneMarble-1.apk]
E/AndroidRuntime( 5644): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
E/AndroidRuntime( 5644): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
E/AndroidRuntime( 5644): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime( 5644): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 5644): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1572)
this is my android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="theHardestGame.pac"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".GameLogicController"
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>
Check the default action in AndroidManifest.xml. It's probably set to theHardestGame.pac.GameLogicController and should be something else.
Looks like you've not updated the package consistently. In your manifest it's "theHardestGame.pac", while the application package seems to be "com.shadycorp.MoonStoneMarble". I suggest you search for those strings and make sure you've updated everything. Also make sure you're doing a clean build.

Android Activity: ClassNotFoundException

my android app was running fine until I added some classes and edited the manifest file.
Now, when I try to run or debug the app on my android emulator with android 2.2, the app crashes and I get a ClassNotFoundException as follows:
D/AndroidRuntime( 275): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
D/AndroidRuntime( 275): CheckJNI is ON
D/AndroidRuntime( 275): --- registering native functions ---
I/ActivityManager( 59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=de.bastian.gpstracker/.MainActivity }
I/ActivityManager( 59): Start proc de.bastian.gpstracker for activity de.bastian.gpstracker/.MainActivity: pid=281 uid=10036 gids={}
D/AndroidRuntime( 275): Shutting down VM
D/jdwp ( 275): adbd disconnected
D/AndroidRuntime( 281): Shutting down VM
W/dalvikvm( 281): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 281): FATAL EXCEPTION: main
E/AndroidRuntime( 281): java.lang.RuntimeException: Unable to instantiate application de.bastian.gpstracker: java.lang.ClassNotFoundException: de.bastian.gpstracker in loader dalvik.system.PathClassLoader[/data/app/de.bastian.gpstracker-1.apk]
E/AndroidRuntime( 281): at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:649)
E/AndroidRuntime( 281): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4232)
E/AndroidRuntime( 281): at android.app.ActivityThread.access$3000(ActivityThread.java:125)
E/AndroidRuntime( 281): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
E/AndroidRuntime( 281): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 281): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 281): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 281): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 281): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 281): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 281): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 281): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 281): Caused by: java.lang.ClassNotFoundException: de.bastian.gpstracker in loader dalvik.system.PathClassLoader[/data/app/de.bastian.gpstracker-1.apk]
E/AndroidRuntime( 281): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime( 281): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime( 281): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime( 281): at android.app.Instrumentation.newApplication(Instrumentation.java:942)
E/AndroidRuntime( 281): at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:644)
E/AndroidRuntime( 281): ... 11 more
W/ActivityManager( 59): Force finishing activity de.bastian.gpstracker/.MainActivity
D/dalvikvm( 149): GC_FOR_MALLOC freed 4092 objects / 248904 bytes in 134ms
W/ActivityManager( 59): Activity pause timeout for HistoryRecord{43fa91d0 de.bastian.gpstracker/.MainActivity}
I/ActivityManager( 59): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 12561 ms (total 12561 ms)
W/ActivityManager( 59): Activity destroy timeout for HistoryRecord{43fa91d0 de.bastian.gpstracker/.MainActivity}
D/KeyguardViewMediator( 59): pokeWakelock(5000)
D/KeyguardViewMediator( 59): pokeWakelock(5000)
I/ARMAssembler( 59): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x325a10:0x325bd8] in 590637 ns
I/ARMAssembler( 59): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x3261f0:0x3262ac] in 261841 ns
W/WindowManager( 59): No window to dispatch pointer action 1
I/Process ( 281): Sending signal. PID: 281 SIG: 9
I/ActivityManager( 59): Process de.bastian.gpstracker (pid 281) has died.
I guess it's something wrong with my project configuration. Here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.bastian.gpstracker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="de.bastian.gpstracker" >
<activity
android:name="de.bastian.gpstracker.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>
To be honest, I do not remember the last changes I made to this file, but, to me, everything seems to be fine here.
While searching for a sultion, I also came along the link Android Activity ClassNotFoundException - tried everything, which describes the same problem, but has a solution no applicable to my case as I am only working with a single project.
In the error log above, I noticed that the file name of the apk created ends on a '-1'. Maybe that's an error, maybe that's simply how eclipse/adt handles things. Also, I noticed that, when I try to run/debug the project, multiple class files with names MainActivity.class, MainActivity$1.class, MainActivity$2.class are created, although I only have a single MainActivity.java file (and no MainActivity$2.file or anything like that).
It would be great if someone had an idea of what's going wrong here.
You are setting the application node to reference a nonexistent class
de.bastian.gpstracker
Refers to the package name, no class whatsoever. Since gpstracker is the last thing in that string, the class loader assumes that gpstracker is a class, tries to load it and fails.
So write the name of the Application class (which extends Application).
Eg
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="de.bastian.gpstracker.MyApplicationClass" >
If you don't have a class that extends Application, then take out the android:name attribute for this node so it looks just like:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Change your application tag in manifest to this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="de.bastian.gpstracker.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>
Remove the name attribute from the application tag.
It, misleadingly, does not have anything to do with the name of your app and is actually the name of an extra class to load before loading your application. That's why you are getting the ClassNotFoundException. Remove it and it should work:

ActivityNotFoundException when include Android library

I have a test project which uses OI FileManager. I added that project to my test project as an Android library, then I call an Activitity in the library. It shows error:
E/AndroidRuntime( 1359): FATAL EXCEPTION: main
E/AndroidRuntime( 1359): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidcoretest/org.openintents.filemanager.FileManagerActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime( 1359): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
E/AndroidRuntime( 1359): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
E/AndroidRuntime( 1359): at android.app.Activity.startActivityForResult(Activity.java:2817)
E/AndroidRuntime( 1359): at android.app.Activity.startActivity(Activity.java:2923)
E/AndroidRuntime( 1359): at com.androidcoretest.FileExplorerTest$1.onClick(FileExplorerTest.java:24)
E/AndroidRuntime( 1359): at android.view.View.performClick(View.java:2408)
E/AndroidRuntime( 1359): at android.view.View$PerformClick.run(View.java:8816)
E/AndroidRuntime( 1359): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 1359): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 1359): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1359): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 1359): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1359): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 1359): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 1359): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 1359): at dalvik.system.NativeStart.main(Native Method)
When I add full path of that Activity in the Manifest, it generates another error.
<activity
android:label="#string/app_name"
android:name="org.openintents.filemanager.FileManagerActivity" >
</activity>
It shows:
E/AndroidRuntime( 1393): FATAL EXCEPTION: main
E/AndroidRuntime( 1393): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidcoretest/org.openintents.filemanager.FileManagerActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidcoretest/org.openintents.distribution.EulaActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime( 1393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime( 1393): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime( 1393): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime( 1393): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime( 1393): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1393): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1393): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 1393): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1393): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 1393): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 1393): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 1393): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1393): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidcoretest/org.openintents.distribution.EulaActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime( 1393): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
E/AndroidRuntime( 1393): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
E/AndroidRuntime( 1393): at android.app.Activity.startActivityForResult(Activity.java:2817)
E/AndroidRuntime( 1393): at android.app.Activity.startActivity(Activity.java:2923)
E/AndroidRuntime( 1393): at org.openintents.distribution.EulaOrNewVersion.startForwardActivity(EulaOrNewVersion.java:127)
E/AndroidRuntime( 1393): at org.openintents.distribution.EulaOrNewVersion.showEula(EulaOrNewVersion.java:69)
E/AndroidRuntime( 1393): at org.openintents.distribution.DistributionLibrary.showEulaOrNewVersion(DistributionLibrary.java:53)
E/AndroidRuntime( 1393): at org.openintents.filemanager.FileManagerActivity.onCreate(FileManagerActivity.java:312)
E/AndroidRuntime( 1393): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 1393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime( 1393): ... 11 more
W/ActivityManager( 59): Force finishing activity com.androidcoretest/org.openintents.filemanager.FileManagerActivity
I would say this is a bug of Eclipse. Eclipse and ADT recently have many bugs on building process: ClassNotFound and ActivityNotFound.
Update:
My code just use one line:
final Intent intent = new Intent(FileExplorerTest.this, FileManagerActivity.class);
startActivity(intent);
Actually I have 3 projects. 2 library projects and 1 test project. Library "OI File Manager" uses Library "OI Distribution", then the test project C uses library "IO File Manager".
Ensure you are linking the OI FileManager projects as a library rather than external jar. go to Project properties > Android > Library, then click add library.
Then as you are doing define the activity in your project manifest (however with ADT 20 i think this is automatic)
<activity
android:label="#string/app_name"
android:name="org.openintents.filemanager.FileManagerActivity" >
</activity>
I guess it can't find com.androidcoretest/org.openintents.distribution.EulaActivity not the FileManager activity. Do you have that EulaActivity in the manifest?
See in your log:
Caused by: android.content.ActivityNotFoundException: Unable to find
explicit activity class
{com.androidcoretest/org.openintents.distribution.EulaActivity}; have
you declared this activity in your AndroidManifest.xml?

getResource Error

every time I call getResources in my main activity it results in an error and the app is forced to quit. This also happens if I call getApplicationContext().getResources() and even in a totally new project in Eclips. Do I need to do anything before the call? Error on AVD with Android 2.1 and LG GW620 with OpenEtna (2.1)
MainActivity.java:
package com.robin.blatest;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
public class MainActivity extends Activity {
Resources res = this.getResources();
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.robin.blatest"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<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>
LogCat:
W/dalvikvm( 229): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime( 229): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 229): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.robin.blatest/com.robin.blatest.MainActivity}: java.lang.NullPointerException
E/AndroidRuntime( 229): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime( 229): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime( 229): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime( 229): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime( 229): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 229): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 229): at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 229): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 229): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 229): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 229): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 229): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 229): at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
E/AndroidRuntime( 229): at com.robin.blatest.MainActivity.<init>(MainActivity.java:9)
E/AndroidRuntime( 229): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 229): at java.lang.Class.newInstance(Class.java:1479)
E/AndroidRuntime( 229): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 229): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
E/AndroidRuntime( 229): ... 11 more
Cheers Robin
Edit: Added Code
You can't do
Resources res = this.getResources();
in the field declaration. It's null at that point!
Put it in onCreate instead.
You'd do something like:
private Resources res = null;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
res = this.getResources();
}
If you wanted a field containing that data.
But it's just as easy to do this.getResources() whenever you need it.
The getResources()-method is a method from the Context-class.
When in an Activity, you can use this to access it.
But you should show us some of your code.

Categories

Resources