My app crashes with NullPointerException, since the android calendar does not return a Collection of calendar names from the dc.getCalendars(); function from the CN1 Calendar Lib, even though it is working to this point on the iOS iphone version.
Device Calendar dc = DeviceCalendar.getInstance();
Collection<String> calNames = dc.getCalendars();
String [] nameArray = calName.toArray(new String[calName.size()]);
Its throwing me an NullPointerException for the 3rd line because calName is a null object and I cant use size() on it. Again, the code IS working on iPhone, so it seems there is a problem with android.
Thanks in advance.
The javadocs for that method say that getCalendars() will return null if you don't have permission
https://github.com/sidiabale/codenameone-calendar/blob/master/CN1Calendar/src/com/codename1/calendar/DeviceCalendar.java#L91
You'll need to add the permissions using the android.xpermissions build hint.
codename1.arg.android.xpermissions=<uses-permission android:name="android.permission.READ_CALENDAR"/> <uses-permission android:name="android.permission.WRITE_CALENDAR"/>
And it looks like you also need to set android.targetSDKVersion=21
See this SO thread for a related issue.
Related
Windows 10 Pro
Latest Simulator
Java Swing Project
I would like to execute "Vector a1 = (Vector) Storage.getInstance().readObject(filePath);"
In a Java Swing Application running on Windows 10 platform, I tried import CodenameOne.jar in Swing package, however when executing above code, get null pointer exception in Storage.getInstance()
Is there a way to execute this in Swing?
Thoughts?
Best Regards.
Thanks, I did not init the Display, however "Display.init(Object m)" requires an Object Argument and the Init method is deprecated.
Can you please provide me the codenameone Display dependencies?
And perhaps a java Swing snippet of code to initialize Display in order to execute Storage.getInstance().readObject(filePath)
Thoughts?
Best Regards
Thanks, Passing init(working directory) solved the Exception thrown.
Here is the Code snippet used to allow me to execute:
Storage.getInstance().readObject(filePath).
String filePath = incSrv.Pwd();// gets working directory
try {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
Display.init(filePath);
String fileName = "A1-MMA.properties";
Vector a1 = (Vector) Storage.getInstance().readObject(filePath);
}
});
} catch (Exception e) {
}
And it does appear to work,
However I am left with a blacked out form that appears modal.
How can I avoid this or dispose it?.
FYI: What I am creating here is a work around for serializing Vector in Codenameone. I Save Vector to file using "Storage.getInstance().writeObject(Path, Vector)"
I convert the file to bytes and write it to the Swing Server VIA socket.
Using Storage.getInstance().readObject(file) on the Swing Server I have deserialize the object into the Vector from my app.
This appears to work well and is more efficient than the current method I use to deliver complex Vectors from the app to the Swing Server.
Can you please let me know if you see a red flag with this workaround?
Like The ability to Storage.getInstance().readObject(file) on the Swing Server may go away?
This method will save a lot of time in movind Vector data to and from the App/Server.
Thoughts Best Regards
Storage.getInstance().readObject(file) // (A1ServiceSrv.java:571)
Caused this Exception:
java.lang.NullPointerException
at com.codename1.io.Storage.init(Storage.java:89)
at com.codename1.io.Storage.getInstance(Storage.java:112)
at Main.A1ServiceSrv.loadVectorFromFile(A1ServiceSrv.java:571)
Regards
12/11/2021:
Thanks Shai,
I am including in my classpath CodenameOne.jar with update date of 12/11/2021 after CN1 refresh.
Getting Same null pointer exception.
Passing in Path "C:\Src1\A1-Arms\A1-Server\A1-MMA.properties" (Absolute Path)
Also Tried "A1-MMA.properties", however I don't think Codenameone knows where my home path is since we are not initializing it as we did with
Display.init("Current Working Directory where files reside");
This is the Fresh Stack Trace w/o calling Display.init (12-20-2021)
java.lang.NullPointerException at
com.codename1.ui.Display.getResourceAsStream(Display.java:3086)
at com.codename1.io.Log.print(Log.java:327)
at com.codename1.io.Log.logThrowable(Log.java:299)
at com.codename1.io.Log.e(Log.java:285)
at com.codename1.io.Storage.readObject(Storage.java:271)
at Main.A1ServiceSrv.loadVectorFromFile(A1ServiceSrv.java:596)
vector = (Vector) Storage.getInstance().readObject(filePath); // (A1ServiceSrv.java:596)
This is hopefully fixed by this commit: https://github.com/codenameone/CodenameOne/commit/72bf283bdaaefe5207bb9fd6787578e3ef61522c if not let me know with a fresh stack
I'm trying the default code in the Readme of the CameraKit CN1Lib on a new bare bones project:
https://github.com/codenameone/CameraKitCodenameOne
It works in the simulator with the webcam, but on a real Android device the line hi.add(ck.getView()); throws an exception because of a null object reference.
I suspect that the problem is that the camera permissions are not asked.
However, in the codenameone_settings.properties, there is the line:
codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.CAMERA" required\="true"/><uses-permission android\:name\="android.permission.RECORD_AUDIO" required\="true"/>
so I don't know how to solve this issue.
This don't seem related to the new Android API, because the issue exists also with:
codename1.arg.android.targetSDKVersion=28
codename1.arg.android.buildToolsVersion=28
The solution is the use of ck.start(); and ck.stop();, as in this example:
https://github.com/codenameone/CameraKitCodenameOne/blob/master/CameraKitDemo/src/com/codename1/camerakit/demo/CameraKitDemo.java
Without ck.start();, ck.getView() returns null.
So the example in the ReadMe is not usable as it is, because it doesn't invoke ck.start(); neither ck.stop();
I am trying to develop an application using SiriKit to get the car door lock status and set the same from Siri. I followed this blog https://www.appcoda.com/sirikit-introduction/ and did all the setup replacing the INStartWorkoutIntent with INGetCarLockStatusIntent.
But when i try to set the vocabulary for carName, the application is getting crashed with following exception,
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Illegal attempt to provide vocabulary of type INVocabularyStringTypeCarName by an app that does not handle any intents that could use that type of vocabulary'
The source code that i am using to set the vocabulary is,
INPreferences.requestSiriAuthorization { (status) in
}
INVocabulary.shared().setVocabularyStrings(["benz", "bmw", "audi"], of: .carName)
In AppDelegate, i have added the following method,
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
guard let intent = userActivity.interaction?.intent as? INGetCarLockStatusIntent else {
print("AppDelegate: Start Workout Intent - FALSE")
return false
}
print("AppDelegate: Start Workout Intent - TRUE")
print(intent)
return true
}
Also created the extension for intent handler and implemented INSetCarLockStatusIntentHandling, INGetCarLockStatusIntentHandling protocols. I am getting this issue when i try to run it in iPhone 10.
Check, if in TARGETS of your project in Build Phases->Embed App Extensions added your Siri Extension. Maybe if you replace the INStartWorkoutIntent with INGetCarLockStatusIntent, old INStartWorkoutIntent remained there.
My crash fix this.
I was facing a similar issue. Make sure your extension's Deployment Target is set to appropriate iOS version. Creating an extension with the latest Xcode (at the moment 10.1) will set the Deployment Target to 12.1 and thus cause crash when run on iOS 10. So you should change it to your desired minimum.
Just updated my XCode from 4.6 to 5, and along with it the iOS7 SDK.
I noticed that all operations (e.g. Predicate filters etc) I attempt to perform on empty NSArray or NSMutableArray cause an exception (NSInvalidArgumentException) when running my app in the simulator for either iOS 5.1 or iOS 7 (still struggling to download iOS 6.1)
My arrays are instantiated (so they are not Nil), but they have 0 entries.
So code that used to work fine in XCode 4.6 now crashes, and I have to add an extra IF to check if the array.count == 0 before running that line of code all over my app. (Monumental task)
When I download my app (version I published with XCode 4.6) from the AppStore to an iOS7 device, it works just fine.
Anyone else also experiencing this?
based on this code, I think the value stored in [defaults objectForKey:#"Wards"] is not an array, please double check the value
NSArray *SelectedWards = [[NSArray alloc]initWithArray:[defaults objectForKey:#"Wards"]];
you may use following code to check
if(![[defaults objectForKey:#"Wards"] isKindOfClass:[NSArray class]])
{
NSLog("OOPs! Wards is not an array");
}
I have just started using Agile Toolkit 4.2.0 for a simple CRUD web application, and so far I'm very impressed with the framework, except that I can't get column sorting to function properly.
Updating the dvdrental page/video.php example with an added line at the end for setting makeSortable() does not seem to work as intended. In all the browsers I have tested the code on so far (Firefox 12, Chrome 18, Opera 11.62 and IE 9), it only outputs a malformed line of HTML before the 'Year' column header.
class page_video extends Page {
function init(){
parent::init();
$this->api->auth->check();
$grid = $this->add('MVCGrid');
$grid->setModel('Movie');
$grid->getColumn('year')->makeSortable();
}
}
Any help would be greatly appreciated, and hopefully it's not a simple error caused by my own ineptitude with this new tool.
There is already an issue opened for this, https://github.com/atk4/atk4/issues/46