Why am I getting this Objective-C error message: invalid conversion from 'objc_object*' - objective-c

This error message had me stumped for a while:
invalid conversion from 'objc_object* to 'int'
The line in question was something like this:
int iResult = [MyUtils utilsMemberFunc:param1,param2];

It doesn't matter what the "to" type is, what is important is that you recognize that this message, in this context, is reporting that the utilsMemberFunc declaration was not found and due to Objective-C's dynamic binding it is assuming it returns an objc_object* rather than the type that utilsMemberFunc was declared to return.
So why isn't it finding the declaration? Because ',' is being used rather than ':' to separate the parameters.

Related

What is wrong with this ST_CONTAINS statement PostGIS - Find point in polygon

I'm trying the following:
Event.where('ST_Contains(?,ST_SetSRID(location, 4326)::geography)', search_polygon::geography)
add getting the error
*** NoMethodError Exception: undefined method `geography' for
but without that (::geography) I get a message telling me to cast, what do I do?
HINT: No function matches the given name and argument types. You
might need to add explicit type casts.
It looks like you are trying to use ST_Contains on geography types, but that function only works on geometry types.
If you are OK with the intersects spatial relation (see DE-9IM), then use ST_Intersects(geography, geography).

Sudden incompatible type compiler errors

I'm trying to integrate CocoaLumberjack into a project that I inherited. I've seen it work fine in the past with other projects, but for some reason, I'm getting several errors in CocoaLumberjack's code. Examples include:
Suddenly I'm getting "Assigning to 'void *' from incompatible type 'const char [1]'" compile errors on struct properties when passing in a C string.
I'm getting warnings on C arrays of C strings saying "Conversion from string literal to 'char *' is depreciated.
"class" has suddenly become a keyword (the lowercase version)
Has anyone ever seen anything similar to this? The build settings on the project have definitely been changed a bit, but I'm not sure what was done.
Any chance you're accidentally compiling the code as C++/Obj-C++? The third point there with class becoming a keyword makes that sound plausible.
i have had this happen in vs, where the errors show up from newest to oldest as the compiler runs through the source code.Try to if your doing something like this always remember to trace to the first error and go from there. I have had some pretty crazy results by putting a semicolon (;) after an include statment
ie
<string>;
<vector>;
will throw a crazy set of errors if it is in the wrong place.

Migrating Gecko 1.9 to 2.0 - Lot of errors

OK, after migrated to Gecko 2.0 for my XPCOM Component,
I fixed a couple of thg like below:
1. Replacing #include "nsIGenericFactory.h" to #include "mozilla/ModuleUtils.h"
2. Replacing xpcomglue_s.lib to xpcomglue_s_nomozalloc.lib
3. Adding #include "mozilla-config.h" to xpcom-config.h header file
4. And as well as remove a couple of unused header file eg: nsReadableUtils.h, nsEventQueueUtils.h, nsIExtensionManager.h
5. Replacing NS_DEFINE_STATIC_IID_ACCESSOR(IMYPROGRAM_IID) to NS_DEFINE_STATIC_IID_ACCESSOR(IMyProgram, IMYPROGRAM_IID)
Reduced from 200+ errors to 20+ now, below are a few more errors which i have no idea what is that, any expert here encounter problem like below?
error C3254: 'IMyProgram' : class contains explicit override 'kIID' but does not derive from an interface that contains the function declaration
error C2838: 'kIID' : illegal qualified name in member declaration
error C3857: 'IMyProgram::kIID': multiple template parameter lists are not allowed
error C2084: function 'void nsTraceRefcnt::LogAddRef(void *,nsrefcnt,const char *,PRUint32)' already has a body
error C2084: function 'void nsTraceRefcnt::LogRelease(void *,nsrefcnt,const char *)' already has a body
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ',' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ',' before '*'
error C2146: syntax error : missing ';' before identifier 'components'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2440: 'initializing' : cannot convert from 'const char [13]' to 'int'
error C2078: too many initializers
error C2448: 'NS_IMPL_NSGETMODULE' : function-style initializer appears to be a function definition
error C2143: syntax error : missing ';' before '__stdcall'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ',' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2556: 'int MyProgramRegistration(nsIComponentManager *,nsIFile *,const char *,const char *,const int)' : overloaded function differs only by return type from 'nsresult MyProgramRegistration(nsIComponentManager *,nsIFile *,const char *,const char *,const int)'
error C2371: 'MyProgramRegistration' : redefinition; different basic types
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ',' before '*'
error C3254: 'IMyProgram' : class contains explicit override 'kIID' but does not derive from an interface that contains the function declaration
error C2838: 'kIID' : illegal qualified name in member declaration
error C3857: 'IMyProgram::kIID': multiple template parameter lists are not allowed
At the very least it looks as if you are missing an NS_DECLARE_STATIC_IID_ACCESSOR(IMYPROGRAM_IID) in your interface (xpidl would have generated that for you automatically.) Some of the other errors are a bit harder to figure out without source code, but the chances are that you haven't quite managed to update your module registration code correctly.

Syntax error : identifier 'String'

We received this piece of code for an assignment, and after spending a lot of time fixing the problems within, I ended up with a syntax error : identifier 'String'. Everywhere I look on the web, people are using std::string, but this is not what the code is referring to since the function is called from a C# project using a String object.
Here is the declaration :
int findWindow(String ^CaptionText,IntPtr ^%phWnd,
int %left,int %top,int %right,int %bottom);
And I have no idea how to fix that one. There are other errors such as
error C2062: type 'int' unexpected
...
error C2065: 'IntPtr' : undeclared identifier
error C2065: 'String' : undeclared identifier
...
etc.
Any help appreciated.
Should I mention that those errors have nothing to do with the assignment?
use System::String and System::IntPtr or write using namespace System;

Problem returning field in ms sql 2005 - System.InvalidCastException:

Using the code below, I am returning an nvarchar field from MS SQL 2005 and keep getting a System.InvalidCastException.
vo.PlacementID = dr.IsDBNull(0) ? null : dr.GetString(0);
The vo.PlacementID variable is of type String so there shouldn't be a problem.
The values I am trying to return are like this (number, number, letter): 00F, 02A, 01F, etc
System.InvalidCastException: Unable to cast object of type 'System.Int32' to
type 'System.String'.
at System.Data.SqlClient.SqlBuffer.get_String()
at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)
Any help much appreciated.
If you read the exception again it gives you a clue as to the problem:
System.InvalidCastException:
Unable to cast object of type 'System.Int32' to type
'System.String'. at
System.Data.SqlClient.SqlBuffer.get_String()
at
System.Data.SqlClient.SqlDataReader.GetString(Int32
i)
Basically the underlying data type being returned in column 0 of your SqlDataReader isn't a string compatible type, hence the cast exception.
I'd suggest setting a breakpoint on the offending line and then execute the following line in the immediate window:
? dr.GetValue(0).GetType()
This will tell what type being returned.
the cast exception is not raised in the assignment, but in the datareader's GetString().
try dr.GetValue(0).ToString()
The InvalidCastException isn't raised because of the type incompatibility between the PlacementID property and string. If that was the case, you'd get a compile-time error. The problem is the first field in the result set is not a string, it's something else.