f



Error - "`+': can't convert nil into String"

Why does the code below give me this error? What can I do to fix it?

/people3.rb:4:in `+': can't convert nil into String (TypeError)
om C:/Ruby192/people3.rb:4:in `to_s'

class Person
attr_accessor :fname, :lname, :age
def to_s
"hi " + @fname + ", " + @lname
end

end



Thanks
PR
-- 
Posted via http://www.ruby-forum.com/.

0
9/29/2010 3:03:22 AM
comp.lang.ruby 48885 articles. 0 followers. Post Follow

1 Replies
1541 Views

Similar Articles

[PageSpeed] 26

On Sep 29, 12:03=A0am, Paul Roche <prpaulro...@gmail.com> wrote:
> Why does the code below give me this error? What can I do to fix it?
>
> /people3.rb:4:in `+': can't convert nil into String (TypeError)
> om C:/Ruby192/people3.rb:4:in `to_s'
>
> class Person
> attr_accessor :fname, :lname, :age
> def to_s
> "hi " + @fname + ", " + @lname
> end
>
> end
>

Either @fname or @lname are nil

You can't concatenate nil to an string.

--
Luis Lavena
0
Luis
9/29/2010 3:57:28 AM
Reply:

Similar Artilces:

[Info-Ingres] Error: Can't convert column 'remark_language' to tuple format
Dear friends I am very new to ingres I have unloaded the database using unloaddb -c dbname and i tranfered the backup file using ftp to another server in ASCII mode when i am trying to load the database in Linux pc i am getting the error E_CO0039 copy: error processing row1, can't convert column 'remark_language' to tuple format Any suggestion from you is help ful to me With regards __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ...

perlcc error
Hi, I'm a perl hack and want to distribute a windows executable of one of my scripts. When I invoke the perl compiler by using perlcc, I get the following error. perlcc.bat: Can't unlink error file pccrYVGS If I try multiple times, the error is the same but the filename changes. I googled and didn't see anything that would help me. One thing I did find out was that a recent installation of some development tools blew away portions of my 'path' environment variable, including the path to the perl bin directory (which also has perlcc.bat). I have restored this to th...

[Info-Ingres] Error: Can't convert column 'remark_language' to tuple format #2
Dear friends I am very new to ingres I have unloaded the database using unloaddb -c dbname and i tranfered the backup file using ftp to another server in ASCII mode when i am trying to load the database in Linux pc i am getting the error E_CO0039 copy: error processing row1, can't convert column 'remark_language' to tuple format Any suggestion from you is help ful to me With regards T.VIJAY KUMAR ENGINEER (IT DEPT) NTPC,RGCCPP, KAYAMKULAM - 602 502 ALLEPPY DIST. KERALA __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ...

bug in Ruby 1.9.1 or me? ERROR: While executing gem ... (TypeError) can't convert Pathname into String
[Note: parts of this message were removed to make it a legal post.] I installed ruby on Ubuntu 8.1 in the following manner removed all ruby files using locate sudo apt-get install readline5-dev build-essential autoconf wget libreadline5-dev libncurses5-dev zlib1g-dev libsqlite3-dev libssl-devsv libncurses5-dev libssl-dev checkinstall mkdir -p /usr/local/src && cd /usr/local/src wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.bz2 tar -xjvf ruby-1.9.1-p0.tar.bz2 cd ruby-1.9.1-p0 sudo ./configure --prefix=/usr --enable-pthread --enable-shared #perhaps i should have added ...

Wine-20050830: Can't find DLL 'x' needed by 'y', error=2
Obviously, Wine-20050830 is much, much different from earlier versions in that it does not even seem to consider a '.wine/config' file. And, it would seem, there's a problem or misunderstanding about locating DLLs. When I try to start 16-bit "Delphi.exe," I get an error: Could not load 'BIVBX11.DLL' required by 'DELPHI', error=2 A more detailed trace shows: [snip!] trace:module:LdrGetDllHandle 0 0 L"OLE32.DLL" -> 0x7f550000 trace:module:load_dll looking for L"ole32.dll" in L"C:\\delphi\\bin;.;c:\\windows\\syste...

What causes the 'can't map file' error?
I'm porting open source for Linux to Mac OS X. I think I generated every .a or .lib but the final link gives an error message. /usr/bin/ld: can't map file: /Users/smcho/Desktop/OpenAccess/lib/mac_osx_32/opt ((os/kern) invalid argument) What might be wrong? ...

Parse error: parse error, expecting `','' or `';''
I'm getting the following error Parse error: parse error, expecting `','' or `';'' in /home/notarywe/public_html/php/update2.php on line 108 Here is line 108 <input type="text" name="ud_first" value="<? echo "$first" size="20"?>"></td> Any help would be appreciated. On 3-Aug-2003, "entoone" <entoone@pacbell.net> wrote: > I'm getting the following error Parse error: parse error, expecting `','' > or > `';'' in /home/notarywe/public_html/php/update2.php on line 108 > > Here is line 108 > > <input type="text" name="ud_first" value="<? echo "$first" > size="20"?>"></td> Please cross post instead of posting the same message separately to multiple news groups. The problem is your php statement <? echo "$first" size="20"?> is incorrect. The correct syntax for it would be: <? echo "$first size=\"20\"" ?> but I doubt that's what you want. try: <input type="text" name="ud_first" value="<? echo "$first"; ?>" size="20"></td> -- Tom Thackrey www.creative-light.com Tom Thackrey wrote: > On 3-Aug-2003, "entoone" <entoone@pacbell.net> wrote: > > >>I'm getting the f...

Can't 'make install' ruby (cvs head)
I've gotten three different errors on four different runs, all of which involve generating the RI documentation (one of the errors has already scrolled past the end of my terminal buffer, so I can't copy-and-paste it): Generating RI... /home/pbrannan/download/ruby/ruby/lib/rdoc/ri/ri_writer.rb:59:in `path_to_dir': +cannot convert Object into Array (TypeError) from /home/pbrannan/download/ruby/ruby/lib/rdoc/ri/ri_writer.rb:42:in +`add_method' Generating RI... /home/pbrannan/download/ruby/ruby/lib/rdoc/markup/simple_markup/fragments.rb:146: +[BUG] Segmentation fault ruby 1.9.0 (2004-09-29) [i686-linux] Are these known problems? Are there any known workarounds, other than trying over and over until it succeeds? Paul ...

Error 2465
"The following unexpected error occurred in Sub CopyMySQLbttn_Click, line #250, CBF on frmVehicleChooserform. 2465: "Can't find the field 'forms' referred to in your expression. You may have misspelled the field name, or the field may have been renamed or deleted." The above error is returned when running the following click code. I don't understand what the error means. Private Sub CopyMySQLbttn_Click() On Error GoTo ErrorCopyMySQLbttn_Click Dim ThisForm As String ThisForm = Me.Name 100 Dim dtxt As Object 125 Set dtxt = Me!TextHolder 150 Me!TextHolder = MySQL 175 DoCmd.GoToControl "TextHolder" 200 dtxt.SelStart = 0 225 dtxt.SelLength = 13 250 DoCmd.RunCommand acCmdCopy 275 MsgBox "Done" ExitCopyMySQLbttn_Click: Exit Sub ErrorCopyMySQLbttn_Click: Dim r As String, k As String, Message3 As String r = "The following unexpected error occurred in Sub CopyMySQLbttn_Click, line #" & Trim$(CStr(Erl)) & ", CBF on " & ThisForm & "." k = CRLF & CRLF & str$(Err) & ": " & Quote & Error$ & Quote Message3 = r & k MsgBox Message3, 48, "Unexpected Error - " & MyApp$ & ", rev. " & MY_VERSION$ Resume ExitCopyMySQLbttn_Click End Sub BTW, the following works fine... 100 Dim dtxt As Object 125 Set dtxt = Me!TextHolder '150 Me!TextHolder = MySQL 150 Me!TextHo...

can't include 'http...foo.php', but can include 'http...foo.txt'
This seems weird, but when I use the following code, include 'http://www.foo.com/includes.php'; includedfunction(); I am told that it is a call to an undefined function, but 'includedfunction' is on the server. the following includes work fine, and the run the called function with no trouble: include 'http://www.foo.com/includes.phtml'; include 'http://www.foo.com/includes.txt'; all three include.php,.phtml & .txt are on the server and are exactly identical. I am running php version 4.1.1. Anyone have any ideas? In article <768682d0.0308190004.dd35f7c@posting.google.com>, googlegroups@paul13.com (paul13) wrote: > This seems weird, but when I use the following code, > > include 'http://www.foo.com/includes.php'; > > includedfunction(); > > I am told that it is a call to an undefined function, but > 'includedfunction' is on the server. The include statement is include()'ing the _output_ of http://www.foo.com/includes.php, not the contents of the file. To demonstrate thist point, load http://www.foo.com/includes.php in your browser and look for your function definitions. Then load http://www.foo.com/includes.txt. You'll see the difference. hth -- Bulworth : funha@fung.arg | My email address is ROT13 encoded, decode to mail --------------------------|-------------------------------------------------- <http://www.phplabs.com/> | PHP scripts and thousands of webmas...

error: expected '=', ',', ';', 'asm' or '__attrib
Hi I'm trying to compile an ADC Driver & come acrosss the following error. I've no experience writing drivers before, and hence have no clue how to fix it. Hope someone out there has encountered the problem & suggesst a fix for the same. The Error is I get is : qadc.c: At top level: qadc.c:97: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'qadc_read' make: *** [qadc.o] Error 1 [root@localhost qadc]# ########################################################################### ADC Driver Code ##...

error: expected '=', ',', ';', 'asm' or '__attrib
Hi I'm trying to compile an ADC Driver & come acrosss the following error. I've no experience writing drivers before, and hence have no clue how to fix it. Hope someone out there has encountered the problem & suggesst a fix for the same. The Error is I get is : qadc.c: At top level: qadc.c:97: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'qadc_read' make: *** [qadc.o] Error 1 [root@localhost qadc]# ########################################################################### ADC Driver Code ########################################################################### #define MODULE #define __KERNEL__ #include <linux/config.h> #include <linux/module.h> #include <linux/kernel.h> /* printk */ #include <linux/fs.h> / #include <linux/errno.h> /* error codes */ #include <linux/types.h> /* size_t */ #include <linux/proc_fs.h> /* proc file system */ #include <linux/fcntl.h> #include <asm/system.h> /* cli, flags */ #include <asm/uaccess.h> /* copy from/to user */ /*Registers to get qadc access*/ volatile unsigned short * qadcmcr = (unsigned short *)0x40190000; volatile unsigned short * qacr0 = (unsigned short *)0x4019000a; volatile unsigned short * qacr1 = (unsigned short *)0x4019000c; volatile unsigned short * qacr2 = (unsigned short *)0x4019000e; volatile unsigned short * qasr0 = (unsigned short *)0x40190010; volatile unsigned short * qasr1...

Error : Internal Mach-O Importer Error File 'ImportMachO.c' Line 1112 can't find section for address
HI folks, I just installed CW 9 and it's latest update 9.1. Next I created new Cocoa based project and it doesn't compile with error: Error : Internal Mach-O Importer Error File 'ImportMachO.c' Line 1112 can't find section for address Could anyone help? Thanks Robert In article <2004022021212116807%robertcerny@maccom>, Robert ?ern´┐Ż <robertcerny@mac.com> wrote: >HI folks, >I just installed CW 9 and it's latest update 9.1. Next I created new >Cocoa based project and it doesn't compile with error: Error : >Internal Mach-O Importer Error File 'ImportMachO.c' Line 1112 can't >find section for address We do have an updated Mach-O Importer that is going to be out in CW 9.2. If you write to me I can send you the beta plugin so you can try it, to see if that fixes your error I think it will. Ron -- Metrowerks, maker of CodeWarrior - "Software Starts Here" Ron Liechty - MWRon@metrowerks.com - <http://www.metrowerks.com> ...

TypeError: Can't convert 'int' object to str implicitly
Hey, Let me explain what my program is supposed to do... I am using a macro program in conjunction with a python script I am writing= .. The macro inputs data into a database we use at my job, blah blah blah. The script asks how many numbers (devices) you need to enter. Next, it asks= you to input the device numbers. When you input them, it creates a list wi= th all of the devices. I then tell it to go into the script of the Macro (f= irstdev.ahk) that will run on the back-end, and replace the word "device" w= ith the first device in the list. It then should execute the Macro, change = the device number back to the word "Device" for future use, and then delete= the first number from the list. It will repeat as long as there are number= s in the list. The error I receive is "TypeError: Can't convert 'int' object to str implic= itly" when it tries to put the device into the macro script. It worked fine= when I just had it input one device into the script without the use of lis= ts, but for whatever reason, using a list does not play nice with replacing= the words "Device" with the number from the list. Here is my script. I wil= l give you up until the part that the error occurs, as everything afterword= s is pointless. I am fairly new to python, so if anything looks screwed up or like I am an = idiot, it is because I am. import fileinput, sys, os devlist =3D [] maxdev =3D int(input("...

Error '429' ActiveX component can't create object.
Why do I get this error when I run my compiled code on another computer, but never on my own computer where I have VB6 installed.? The project in question is an ActiveX control that I am running inside a web browser. As I said, it works fine for me, but nowhere else. Why? Owen You are using components in your project that do not exist on the other machine, but do exist on yours. You need to copy these *.ocx files over to the new machine and register them before it can run on that machine. Mauro "owen" <spam@spam.com> wrote in message news:2yizc.1142$0l3.888@newsfe4-gui... > > Why do I get this error when I run my compiled code on another computer, > but > never on my own computer where I have VB6 installed.? > > The project in question is an ActiveX control that I am running inside a > web > browser. As I said, it works fine for me, but nowhere else. > > Why? > > > Owen > > "Mauro" <mbiefeni@hotmail.com> wrote in message news:lXhzc.753236$oR5.629087@pd7tw3no... > You are using components in your project that do not exist on the other > machine, but do exist on yours. You need to copy these *.ocx files over to > the new machine and register them before it can run on that machine. > Mauro, I would have thought that too.... except I'm using the VB6 "Package and Deployment Wizard" to create the install for the other machine, and it tells me a list of all...

how to convert string like '\u5927' to unicode string u'\u5927' #2
Here's my solution _unicodeRe = re.compile("(\\\u[\da-f]{4})") def unisub(mo): return unichr(int(mo.group(1)[2:],16)) unicodeStrFromNetwork = '\u5927' unicodeStrNative = _unicodeRe(unisub, unicodeStrFromNetwork) But I think there must be a more straightforward way to do it. Chris Song wrote: > Here's my solution > > _unicodeRe = re.compile("(\\\u[\da-f]{4})") > def unisub(mo): > return unichr(int(mo.group(1)[2:],16)) > > unicodeStrFromNetwork = '\u5927' > unicodeStrNative = _unicodeRe(unisub, unicodeStrFromNetwork) &g...

Any reason why $_FILES['userfile']['error'] wouldn't be populated?
Hi, I am in the middle of writing an image upload script and am limiting the size of uploads via upload_max_filesize. This all seems to be working well, and if I try and upload a bigger file then I get an UPLOAD_ERR_INI_SIZE sat in $_FILES['userfile']['error']. All hunkey dorey. However, in my testing there are one or two large files that cause problems. PHP appears to abort the upload early as it should, but when my script runs, $_FILES isn't populated at all?! I have tried to narrow down the difference in these file but I can't seem to find anything definate. All the ones that fail are AVI or WMV files if that gives any clue, but even if I rename them to MPG (others of which work ok), and check the MIME type being sent up has also changed to mpg, then they still fail as before. I have sent bigger and smaller files all ok, so it's not size. I can't see anything in the filename itself that would cause problems. Any ideas? On 27 May 2007 04:38:47 -0700, lister <listerofsmeg01@hotmail.com> wrote: >I am in the middle of writing an image upload script and am limiting >the size of uploads via upload_max_filesize. This all seems to be >working well, and if I try and upload a bigger file then I get an >UPLOAD_ERR_INI_SIZE sat in $_FILES['userfile']['error']. All hunkey >dorey. > >However, in my testing there are one or two large files that cause >problems. PHP appears to abort the upload early as it...

error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'
Hi, i wrote the code in C and compiled in VC++ compiler. at that time it has thrown the below mentioned error. error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast Herewith i have added the code also. ----------------------------------- #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { char message[15]=":80a1:SSBKRO"; char *location; char* receiver='\0'; char* rec='\0'; int i,j,cnt=0; int mt511=(int) strlen(":80a1:"); printf("%s\n",message); if((location=strstr(message,":80a1:")) != NULL) { for(i=0;i<mt511;i++) location++; for(j=mt511;j<mt511+8;j++) while(*location!='\0') { strcpy(rec,message[j]); strcat(receiver,rec); cnt++; } /*for(i=0;i<mt511;i++) location++; strncpy(receiver,location,cnt);*/ } else { for(i=mt511;i<cnt;i++) { strcpy(rec,"X"); strcat(receiver,rec); } } printf("%s\n",receiver); return 0; } ---------------------------------------- Kindly help me to resolve this issue. Thanks In advance. Regards, kaizen kaizen wrote: > { strcpy(rec,message[j]); second parameter is a character, and should be a C-string (const char*) perhaps you wanted to do like: char tmp[2]; tmp[0]=message[j]; tmp[1]='\0'...

DBI:Pg script returning 'can't call method' error
This is my script in its current (troubleshooting) state: ---------------------------------------------------------- #!/usr/bin/perl -w use DBI; #use DBD::Pg; use strict; my $dbname = "test"; my $dbh = DBI->connect("DBI:Pg:dbname= $dbname;host=localhost;port=5432","","", {RaiseError => 1, PrintError => 1 }) or die "Can't connect to the db: $DBI::errstr\n"; if (undef $dbh) {die "cannot connect to database:$!\n";} else {print "Success connecting!\n";} my $statement = "select count(*) from t...

Run-time error '424': Object required
Hi all, I'm running a VERY simple bit of code that is supposed to set the record source of the current form based on the entries in two unbound fields to act as a rudimentary search tool. The code is as follows... excuse my over use of ifs and thens but its the only way my brain will logically work out what i am doing. ***Code Segment*** Private Sub Search_Click() Dim strSQL As String, UserLogged As String strSQL = "" strSQL = "SELECT * FROM tblIncidents " If (((Me.IDSearch = "") Or (Me.IDSearch Is Null)) And ((Me.KeywordSearch = "") Or (Me.KeywordSearch Is Null))) Then 'do nowt Else strSQL = strSQL & "WHERE " End If If Me.IDSearch = "" Or Me.IDSearch Is Null Then 'do nowt Else strSQL = strSQL & "(incidentid = '" & Me.IDSearch & "') " End If If (Me.IDSearch = "" Or Me.IDSearch Is Null) Then 'do nowt Else strSQL = strSQL & "AND " End If If Me.KeywordSearch = "" Or Me.KeywordSearch Is Null Then 'do nowt Else strSQL = strSQL & "(incidenttitle LIKE '*" & Me.KeywordSearch & "*') " End If strSQL = strSQL & ";" Me.RecordSource = strSQL End Sub ***End Code Segment*** The Error message appears on the fifth line: If (((Me.IDSearch = "") Or (Me.IDSearch Is Null)) And ((Me.KeywordSearch = "") Or (Me.KeywordSearc...

converting strings to most their efficient types '1' --> 1, 'A' ---> 'A', '1.2'---> 1.2
Hello, I'm importing large text files of data using csv. I would like to add some more auto sensing abilities. I'm considing sampling the data file and doing some fuzzy logic scoring on the attributes (colls in a data base/ csv file, eg. height weight income etc.) to determine the most efficient 'type' to convert the attribute coll into for further processing and efficient storage... Example row from sampled file data: [ ['8','2.33', 'A', 'BB', 'hello there' '100,000,000,000'], [next row...] ....] Aside from a missing attribu...

python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly
This is the code I run (python 3.3) host = ... user = ... passwd = ... from ftplib import FTP ftp = FTP(host, user, passwd) ftp.mkd(b'NewDir') ftp.rmd(b'NewDir') This is the traceback Traceback (most recent call last): File "ftp-problem", line 9, in <module> ftp.mkd(b'NewDir') File "/usr/lib/python3.3/ftplib.py", line 612, in mkd resp = self.voidcmd('MKD ' + dirname) TypeError: Can't convert 'bytes' object to str implicitly The problem is that I do something like this in a backup progra...

Setting an object to existing form generates 'can't find form' error
Hi I am attempting to set global variable (bad practice, will replace with class later, just exploring an idea) with the following code in an startup module from globaldec.bas... Global gfrmClient As Form Global gstrClientForm As String from startup.bas.. gstrClientForm = "frmClients" Set gfrmClient = Forms(gstrClientForm) At runtime I get 'MSA can't find form "frmClients"' Thanks in advance S Is the form open at the time? If not, it's not a member of the Forms collection. HTH - Turtle "SMc" <seamusmcluskey@yahoo.ca> wrote in message news:4e9424a5.0406151137.2efa4e17@posting.google.com... > Hi > > I am attempting to set global variable (bad practice, will replace > with class later, just exploring an idea) with the following code in > an startup module > > from globaldec.bas... > > Global gfrmClient As Form > Global gstrClientForm As String > > > from startup.bas.. > > gstrClientForm = "frmClients" > Set gfrmClient = Forms(gstrClientForm) > > At runtime I get 'MSA can't find form "frmClients"' > > Thanks in advance > > S ...

can't get the $_GET['id'] after the header is sent but page doesn't redirect
In the first if, the page is displayed without any company cars selected. If there is a company selected, then the id value is posted and captured by the redirect (1st elseif). Then one of two things can happen. The final else the selected company/id cars get displayed in the browser, or in the case of a post to a form for excel, the a header gets sent to the to the current_sightingsXL.php page. The current_sightingsXL.php and current_sightings.php pages test out. The second elseif works with one minor problem. I have to type in the url with the id to get it to download to excel. if{XXXX }elseif($_POST['redirect']&&$_POST['redirect']!=$_SERVER['PHP_SELF']){ Header("Location: ".$_POST['redirect'].".php?id=".$_POST['id']); exit; }elseif($_POST['assign']=='Open in Excel'){ Header("Location: current_sightingsXL.php?id=".$_GET:['id']); exit; }else{ xxxxx}; When the first elseif gets hit then this happens in the url: http://www.allcapitalrail.com/current_sightings.php?id=117 Then if I post the button to excel, this should happen but it doesn't: www.allcapitalrailXL.com?id=117 However, if I type the above line in the url then the excel download works. What happens is when I click the excel post button the get id doens't get into the url. I get www.allcapitalrail.com which starts over. But at this point if I type in the www.allcapitalrail.com/...

Removing the letters 't' 'i' 'x' and 'y'
Im having trouble with figuring out how to write a function which will remove the letters 't' 'i' 'x' and 'y' from any input string in matlab. for example modstr(pixy) should result in ans = 'p' or modstr(picture) should result in ans = 'pcure' if anyone could offer any help or hints i would really appreciate it. Thank You >> modstr=@(s) s(~ismember(s,'tixy')) modstr = @(s)s(~ismember(s,'tixy')) >> modstr('picture') ans = pcure % Bruno ...

Web resources about - Error - "`+': can't convert nil into String" - comp.lang.ruby

Resources last updated: 3/26/2016 8:05:15 PM