I know similar questions have been asked but none have been helpful to me. If I were pointed to a link that has a solution I would be more than pleased. Anyway, I am getting an error every time I install a widget I am developing on my Android Emulator.
The error states
ERROR/AndroidRuntime(866): java.lang.RuntimeException: Unable to instantiate receiver com.ifractal.firstwidget.FirstWidget: java.lang.NullPointerException
Here is the relevant code
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ifractal.firstwidget"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:name=".FirstWidget" android:label="#string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.appwidget.action.APPWIGET_ENABLE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/provider"
/>
</receiver>
</application>
and here is my project layout in eclipse (to show that files are there)
I have tried recreating the project with a different name, cleaning/building, and a few other things but nothing has worked. I appreciate any help that you can give me and am willing to provide additional info if needed. Thanks.
The manifest looks fine to me. You get a NPE in FirstWidget, so you need to look into that class. Check the stack trace and see where exactly the exception is thrown. Could it be the constructor?
Check that your app widget class is not abstract.
Below is a typical app widget class declaration:
public class AppWidget extends AppWidgetProvider{
// ...
}
Related
I've read up on forum posts about similar errors, but nothing I read works. It looks like my formatting is fine, but I keep getting the indicated error. I've tried refreshing the project and cleaning the project as well as restarting Eclipse entirely.
<manifest
... >
<application
... >
<activity
android:name="com.myNamespace.myPackage.MainActivity"
android:label="#string/app_name">
</activity>
</application>
</manifest>
In your manifest you must have forget to close one of the attribute. Check out your manifest file closely and make sure you have closed all the tags.
I also faced the same isssue but I found that it was coming because of copying and pasting the code in xml file.
Please try to type the code manually and see. Hope the error will not come.
try like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myNamespace.myPackage"
android:versionCode="12" android:versionName="2.2.0">
<uses-sdk android:minSdkVersion="3" />
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="false">
<activity android:name="com.myNamespace.myPackage.MainActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:label="#string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I had the same error until I figured out that the activity tag needs to open and close on the same line. It's not a written syntax but my error was gone when I wrote the whole tag in one line instead of on separate lines. You should try it like this:
<application>
<activity android:name=".MainActivity" android:label="#string/app_name"> </activity>
</application>
</manifest>
I develop in Eclipse on a Mac. When I copy items (both from within Code and/or from a webpage (like Stackoverflow or so) I often get this error. I believe that the copy/paste mechanism is not functioning completely well.
What I do to solve this error, is just typing the complete line (no copy/paste!), all over again.
When I have copied a block I see that the error moves to the next line, which you have to retype also.
Very time consuming and frustrating, but this really works!
One of my Android applications needs some features that are "dangerous" when it comes to permissions. They require some permissions such as "Internet access" which are critical in combination with private data.
This is why I want to create a separate "Add-on", i.e. a second app that provides these permission-critical features. So if users want them, they can install the add-on, but the main app will still work without those permissions.
Using a sharedUserId would obviously be the easiest solution, but adding this afterwards, when lots of users use the app already, could cause serious problems. Wouldn't this mean that the app can't access its own data any longer?
So I have to choose another approach. ContentProviders are something that I try to avoid, because they're too complex for this simple need in my opinion.
I thought custom permissions could solve the issue. Can they? I've added the following permission declaration to both the main app as well as the add-on as a child to the manifest tag in AndroidManifest.xml:
<permission
android:name="com.my.package.ADDON"
android:label="#string/permission_title"
android:description="#string/permission_description"
android:permissionGroup="android.permission-group.PERSONAL_INFO"
android:protectionLevel="signature" />
Furthermore, both manifest files have got this part now:
<uses-permission android:name="com.my.package.ADDON"></uses-permission>
The add-on app includes an IntentService that has the following attribute now:
android:permission="com.my.package.ADDON"
Shouldn't this do the job so that I can call the add-on's IntentService from my main app via this code?
Intent addonIntent = new Intent();
addonIntent.setClassName("com.my.package", "com.my.package.MyService");
startService(addonIntent);
Unfortunately, this call always fails with the following exception:
E/AndroidRuntime(16721): java.lang.SecurityException: Not allowed to start service Intent { cmp=com.mypackage.addon/.MyService } without permission com.mypackage.permission.ADDON
What did I do wrong? Thank you very much in advance!
Addition #1 - Add-on manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.mypackage.addon">
<uses-sdk android:minSdkVersion="8" />
<permission
android:name="com.mypackage.permission.ADDON"
android:label="#string/permission_title"
android:description="#string/permission_description"
android:permissionGroup="android.permission-group.PERSONAL_INFO"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:permission="com.mypackage.permission.ADDON"
android:exported="true">
<service
android:enabled="true"
android:name=".MyService" />
</application>
</manifest>
Addition #2 - main app manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.mypackage.mainapp">
<uses-sdk android:minSdkVersion="8" />
<permission
android:name="com.mypackage.permission.ADDON"
android:label="#string/permission_title"
android:description="#string/permission_description"
android:permissionGroup="android.permission-group.PERSONAL_INFO"
android:protectionLevel="signature" />
<uses-permission android:name="com.mypackage.permission.ADDON"></uses-permission>
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:name="MyApp">
<activity android:name=".MainActivity" android:launchMode="singleTask" 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>
Wouldn't this mean that the app can't access its own data any longer?
Correct.
I've added the following permission
I would dump the permission-group, as that should not be necessary.
Furthermore, both manifest files have got this part now
Only the one calling your IntentService might need that.
Shouldn't this do the job so that I can call the add-on's IntentService from my main app via this code?
Not if that IntentService is not exported. Make sure that your IntentService either has an <intent-filter> or android:exported="true". I would recommend going the <intent-filter> route, so you can declare and use a custom action string, so you get away from hard-coding package and class names in the client app.
Here is a directory with two sample projects using this basic approach, though in my case the communications are based on a secured ContentProvider rather than a secured IntentService. The concept is the same, though, and so with these minor tweaks, I would expect what you are doing to work just fine.
I have a basic clock widget here, it works just fine on versions of android below 4.0, you can long press, select widgets and its right there. But when i try to run it on 4.0 or later emulator or real device, it does not show up in widgets section only in Settings>Storage>Apps. I have tried adding a simple activity that just gives users directions on how to install the widget , that suggestion was given as an answer here: Android 4.0: widgets not appearing? . Unless i did it wrong the widget still does not show up in widget drawer.
Here is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.widgetexample1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<application
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>
<receiver android:name=".ExampleAppWidgetProvider"
android:label="8-bit cloud widget 1">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/widget1_info" />
</receiver>
</application>
</manifest>
add below in your manifest.xml.
"android:exported="true".
it might help.
try it.
In your widget metadata xml file check tag <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:xmlns attribute should start with http://.
It looks like you are being hit by a security upgrade which I think happened in HoneyComb.
Basically, in newer versions of Android, you cannot have your widget working, without first launching an Activity.
So add an activity to the project, run it first, and I think your widgets will update.
A good example would be to use a Settings style activity, or perhaps and About box type of thing, to tell the user a bit about your widget. (I use settings in my widgets).
For more info:
Android 4.0: widgets not appearing?
I'm having an issue starting activities in order, and I don't know if it is an issue in the manifest or in the code. I tested this code a while ago when it was working, but now it's not.
The first activity links to the second, which links to the third. I listed the first activity first in the manifest. However, when I start my emulator, it's the second activity that runs first. I am very confused. Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hmdywifinal.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".Activity1"
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=".Activity2"
android:label="Startpage">
</activity>
<activity android:name=".Activity3"
android:label="Activity3"></activity>
</application>
Do you think something is wrong with it?
Make sure you are running your program from Activity1 and not from Activity2.
If you run it from Activity2 it will skip Activity1 even though you have your manifest set like you described above.
Order in which Manifest file declares Activities has nothing to do with the runtime order.
First Activity gets launched from a Launcher ( which is Activity1 in your case )
I am assuming you are launching Activity2 and 3 using Intents in your code. So you are in control on the way these activities get launched.
Refer to the api Demos, Which has got a similar application Proof Of Concept. It will give you a better idea on mving from one application to other.
I've been trying to implement the tab UI described in this tutorial: https://developer.android.com/resources/tutorials/views/hello-tabwidget.html
I follow all the steps described in the process but I keep getting a runtime exception which I believe has something to do with the fact that nowhere in the tutorial I added the extra activities (songs, artists and albums) related to the content of each tab into the android manifest file.
Am I correct? is this tutorial (like many others) faulty or incomplete?
Since they seem to update these tutorials occasionally, I wouldn't doubt they forgot to mention this part back when this question was asked. They appear to have added a mention to this requirement in the tutorial now (as of 12/20/2010) in step 2:
Duplicate this for each of the three activities, and add the corresponding tags to the Android Manifest file.
Unfortunately, since these are beginner tutorials, they should probably include what the XML tags should look like. Prior to this tutorial, they don't mention how to add activities to the manifest (though you add an activity at the end for hiding the title bar). The markup I used was identical to that on the other question mentioned in the OPs own answer:
<activity android:name=".ArtistsActivity"></activity>
<activity android:name=".AlbumsActivity"></activity>
<activity android:name=".SongsActivity"></activity>
There is a full reference on manifest activities on the Android developer site.
Well thanks for the advice, but I didn't really had to use LogCat. The tutorial is indeed faulty and incomplete, the corrections are very well explained in this related post.
Issues with Android TabHost Example
I'm just amazed by the amount of mistakes in these tutorials, and by the fact that nobody has fixed them yet.
Nelson
I was having the same problem, even after making all the corrections said above and on the following post link
the problem was the AndroidManifest, the following manifest file worked for me.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tabview.android" android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloTabWidget" 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=".AlbumsActivity" android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
<activity android:name=".ArtistsActivity" android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
<activity android:name=".SongsActivity" android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
</application>
</manifest>