2014년 12월 8일 월요일

New built in maths block to convert Decimal to Hexdecimal

I have been working on adding a few extra builtin maths blocks one of which calculates a new x y coordinate based on the angle and distance and this is working fine. 

I'm adding another block to convert decimal to hexdecimal which should be pretty straight forward in scheme but for some reason when I compile the companion app it crashes. Below is the scheme code I have added just to test the code conversion code works. The code is added to 
appinventor\buildserver\src\com\google\appinventor\buildserver\resources\runtime.scm

(define (math-dec-hex)
   (number->string 11 16)

When I compile and start the companion app with this code the companion app crashes straight away when it starts

I have tested the code on the following online sandbox here http://repl.it/examples/

here is a screen shot and the result is correct in green

Can anyone shed light on why the same code crashes the companion app?



Did you build your own Companion based on your updated code?



I also did the amendment on the latest version of AI code with no other changes.




here is the logcat report when I start the companion app

11-09 19:38:24.250: D/AndroidRuntime(20558): Shutting down VM
11-09 19:38:24.258: E/AndroidRuntime(20558): FATAL EXCEPTION: main
11-09 19:38:24.258: E/AndroidRuntime(20558): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{edu.mit.appinventor.aicompanion3/edu.mit.appinventor.aicompanion3.Screen1}: java.lang.ClassNotFoundException: Didn't find class "edu.mit.appinventor.aicompanion3.Screen1" on path: /data/app/edu.mit.appinventor.aicompanion3-1.apk
11-09 19:38:24.258: E/AndroidRuntime(20558):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at android.app.ActivityThread.access$700(ActivityThread.java:150)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at android.os.Looper.loop(Looper.java:175)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at android.app.ActivityThread.main(ActivityThread.java:5279)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at java.lang.reflect.Method.invokeNative(Native Method)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at java.lang.reflect.Method.invoke(Method.java:511)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at dalvik.system.NativeStart.main(Native Method)
11-09 19:38:24.258: E/AndroidRuntime(20558): Caused by: java.lang.ClassNotFoundException: Didn't find class "edu.mit.appinventor.aicompanion3.Screen1" on path: /data/app/edu.mit.appinventor.aicompanion3-1.apk
11-09 19:38:24.258: E/AndroidRuntime(20558):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
11-09 19:38:24.258: E/AndroidRuntime(20558):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
11-09 19:38:24.258: E/AndroidRuntime(20558):  ... 11 more


I have put the mod on git

Attached is the compiled companion app that crashes.




Yes, the Kawa we use supports number->string (I tested it). I'll looking into your changes now...



So I've checkout out your code and it fails to compile (The Kawa compilation fails).



I found the problem. We define our own version of number->string in runtime.scm that takes only one argument. Your test function is calling it with two (which is OK with the kawa builtin version, but not with the redefined version in runtime.scm)!



I have it working. I've attached a ZIP file to this message which contains the output of git format-patch. Use "git am" to read the enclosed file.

This patch renames number->string to appinventor-number->string (this needs more testing!). I also added a Dec To Hex Test block to exercise the code.




Thanks for looking at this Jeff. 
Will have a look at this tonight when I get home from work



You saw that Jeff figured it out.   My stupidity for shadowing number->string.
I'll fix that in a release,soon.  In the meantime, just patch runtime.scm to use another name, and change the block generator to use the new name.



There used to be some Scheme based unit tests that we encouraged developers to add to when they created or modified scheme code for new blocks. Does that still exist?  It might have caught something like this.



Those unit tests still exist.   They would not have caught Gereth's bug, since he wasn't making any changes to existing code, just using Kawa's number->string in a way that the code in runtime.scm was shadowing.   That shadowing's been there from the beginning (my fault).


댓글 없음:

댓글 쓰기