Activity Recognition Client removing Updates - activity-recognition

When i tried to call removeUpdates(PendingIntent) from ActivityRecognitionClient it throwed an exception(Client Not connected).So i checked ActivityRecognitionClient.isConnected() and then did removeUpdates .This Solved my problem.But then i saw something like isConnecting().What should be done if the isConnecting returns true.

Related

Invalid method when method is valid

I have just started a new version of my Crysis Wars Server Side Modification called InfinityX. For better management, I have put the functions inside tables as it looks neater and I can group functions together (like Core.PlayerHandle:GetIp(player)), but I have ran into a problem.
The problem is that the specified method to get the players' name, player:GetName() is being seen as an invalid method, when the method actually is completely valid.
I would like to know if using the below structure is causing a problem and if so, how to fix it. This is the first time I've used this structure for functions, but it is already proving easier than the old method I was using.
The Code:
Event =
{
PlayerConnect = function(player)
Msg.All:CenteredConsole("$4Event$8 (Connect)$9: $3"..player:GetName().." on channel "..player.actor:GetChannel());
System.LogAlways(Default.Tag.."Incoming Connect on Channel "..player.actor:GetChannel());
Event:Log("Connect", player);
end;
};
The below code works when I bypass the function and put the code directly where it's needed:
Msg.All:CenteredConsole("$4Event$8 (Connect)$9: $3"..player:GetName().." on channel "..player.actor:GetChannel());
System.LogAlways(Default.Tag.."Incoming Connect on Channel "..player.actor:GetChannel());
The Error:
[Warning] [Lua Error] infinityx/main/core.events.lua:23: attempt to call method 'GetName' (a nil value)
PlayerConnect, (infinityx/main/core.events.lua: 23)
ConnectScript, (infinityx/main/core.main.lua: 52)
OnClientEnteredGame, (scripts/gamerules/instantaction.lua: 511)
(null) (scripts/gamerules/teaminstantaction.lua: 520)
Any clarification would be appreciated.
Thanks :)
Well, as PlayerConnect is inside the table Event, and you are calling with a ":", add self as first arg in the function, like:
PlayerConnect = function(self, player)
Clearly, player in the first block of code is not the same as player in the second block of code. The problem must be that the caller of Event.PlayerConnect is not passing the same value.
To test that your Event.PlayerConnect function works, try this in the same place as your second block of code:
Event.PlayerConnect(player)
That should work as you expect.
So, the problem comes down to how Event.PlayerConnect is called without the second block of code. I'm not familiar with that game engine so I don't know how it is done. Perhaps reviewing the documentation and/or debugging that area would help. If you print(player) or call the equivalent log function in both cases, you should see they are different. If you can't run in a debugger, you can still get a stack trace with print(debug.traceback("Accessing player, who's value is: "..player)). If there is indeed some kind of table-based player object in both cases, you can try comparing their fields to see how they are different. You might need to write a simple dumping function to help with that.

Why does $my_item->save fail with Rose::DB::Object?

I am trying to do a simple addition of data to a database table (PostgreSQL). At first, I couldn't even get a simple
$my_item = $_item_class->new(...);
to work. I discovered I had spelled a field differently in my code from what I had in my "model" code.
But, now, this is working, but when I try:
$my_item->save;
it seems an exception is thrown. All this is occurring in an eval {...} structure and I would like to catch the exception and see what is going wrong, but I don't know how to do that.
Why would something like the "save" be failing here? I have checked everything, and all seems right (of course!).
And, how do I catch the exception that seems to be being thrown?
Thank you!
I figured all this out myself. It was simple. I had duplicated a field in my class somehow when I had done an edit to it. That was all. The class just had two identically named fields specified in the hash table in the class, both with identical characteristics. When I removed one of these, the code worked.
With regard to my second question about how to catch the exception, I had to learn how to have an
if ($#) {
.
.
.
}
right after my "eval {...}" structure. Because I am new to Perl, I didn't understand that. But, it was actually pretty easy to figure out. My problem was that I was working from some code as a model for me that didn't do that but named specific exceptions that were thrown in its "eval {...}" code. So, I thought that I had to have the names of exceptions that could be thrown by Rose::DB::Object calls, but I couldn't find any such exceptions in the documentation. When I learned about "if ($#) {...}", I was able to print out the reported exception in $# and from that I was able to see the problem with the duplicate field I mentioned above.
That was all there was to it. Everything is working just fine now.

LUA - How to call a function from a string using the _G[x]() method

I'm having a problem with my code and I don't know what's up, I've searched online and the _Gx method was suggested as the best way over ones like loadstring(x)... although I would be happy with either, can't get either one to work. What I want to do is, in ComputerCraft, send a function name and argument to a turtle, which I'm doing by saving both values to a table and sending across the table, and then on the turtle's program, have a big list of functions, and using a command, call them from the string sent and insert the arg as well. My error is "attempt to call nil", which I don't quite understand why it's saying that... Thanks in Advance!
EDIT
I've edited my code down, as asked, to show that even stripping all else away, this still fails. I could even strip it down even more by taking the variable completely out, and putting the string straight into the _G. This still fails even doing it like that. I've decided to keep it in because that's how I am actually going to be using it later. Calling the function normally works fine. I'm using version Luaj-jse 2.0.3
function foo ()
print ("HI!")
end
print (_VERSION)
I don't know what rednet is, but it seems like you passes name of function to another Lua VM, which doesn't know anything about this function (this function is absent in that VM's globals table).
So, passing function definition as string and executing it by receiver with loadstring is the only solution.

Catch Mathematica warnings/errors without displaying them

I have a problem involving NDSolve in Mathematica, which I run multiple times with different values of the parameters. For some of these values, the solution results in singularities and NDSolve warns with NDSolve::ndsz or other related warnings.
I would simply like to catch these warnings, suppress their display, and just keep track of the fact that a problem occurred for these particular values of the parameters. I thought of the following options (neither of which really do the trick):
I know I can determine whether a command has resulted in a warning or error by using Check. However, that will still display the warning. If I turn it off with Off the Check fails to report the warning too.
It is possible to stop NDSolve using the EventLocator method, so I could check for very large values of the function or its derivatives and stop evaluation in that case. However, in practice, this still produces warnings from time to time, presumably because the step size can sometimes be so large that the NDSolve warning triggers before my Event has taken place.
Any other suggestions?
If you wrap the Check with Quiet then I believe that everything should work as you want. For example, you can suppress the specific message Power::indet
In[1]:= Quiet[Check[0^0,err,Power::indet],Power::indet]
Out[1]= err
but other messages are still displayed
In[2]:= Quiet[Check[Sin[x,y],err,Power::indet],Power::indet]
During evaluation of In[2]:= Sin::argx: Sin called with 2 arguments; 1 argument is expected. >>
Out[2]= Sin[x,y]
Using Quiet and Check together works:
Quiet[Check[Table[1/Sin[x], {x, 0, \[Pi], \[Pi]}], $Failed]]
Perhaps you wish to redirect messages? This is copied almost verbatim from that page.
stream = OpenWrite["msgtemp.txt"];
$Messages = {stream};
1/0
FilePrint["msgtemp.txt"]

BeepBeep and ErlyDB integration issue

Further to my adventures with Erlang and ErlyDB. I am attempting to get ErlyDB working with BeepBeep
My ErlyDB setup works correctly when run outside of the BeepBeep environment (see Debugging ErlyDB and MySQL). I have basically take the working code and attempted to get it running inside BeepBeep.
I have the following code in my controller:
handle_request("index",[]) ->
erlydb:start(mysql,Database),
erlydb:code_gen(["thing.erl"],mysql),
NewThing = thing:new_with([{name, "name"},{value, "value"}]),
thing:save(NewThing),
{render,"home/index.html",[{data,"Hello World!"}]};
When I call the URL, the response outputs "Server Error".
There is no other error or exception information reported.
I have tried wrapping the call in try/catch to see if there is an underlying error - there is definitely an exception at the call to thing:new_with(), but no further information is available.
The stacktrace reports:
{thing,new,[["name","value"]]}
{home_controller,create,1}
{home_controller,handle_request,3}
{beepbeep,process_request,4}
{test_web,loop,1}
{mochiweb_http,headers,4}
{proc_lib,init_p_do_apply,3}
Use pattern matching to assert that things work up to the call to thing:new/1:
ok = erlydb:start(mysql,Database),
ok = erlydb:code_gen(["thing.erl"],mysql),
You include only the stack trace, look at the exception message as well. I suspect that the error is that you get an 'undef' exception. But check that it is so. The first line in the stack trace indicates that it is a problem with calling thing:new/1 with ["name", "value"] as argument.
It is slightly odd that you show one clause of handle_request that is not calling home_controller:create/1 as per {home_controller,create,1} in the stack-trace. What do the other clauses in your handle_request/2 function look like?