Solved

groovy example issue

Posted on 2016-10-10
10
113 Views
Last Modified: 2016-10-18
Hi,

I wrote my groovy class as below
class FirstGroovyClass {
String name
String place
def methodOne(){
println "hola"
	}
	static main(args) {
	
	}

}

Open in new window


i wrote my implementation code by creating object as below
import FirstGroovyClass
//class FirstGroovyClassImplementation {

	def object=new FirstGroovyClass()
	object.methodOne()
	
	
	
	def objectTwo=new FirstGroovyClass(name:'FirstGroovyClasse',place:'FirstGroovyClasssss')
	println objecTwo.getName
//}

Open in new window


some how objectTwo is not able to see getName() or getPlace() default methods which groovy should automatically create.

when i ran as groovy script i am getting below error

hola
Caught: groovy.lang.MissingPropertyException: No such property: objecTwo for class: FirstGroovyClassImplementation
groovy.lang.MissingPropertyException: No such property: objecTwo for class: FirstGroovyClassImplementation
      at FirstGroovyClassImplementation.run(FirstGroovyClassImplementation.groovy:10)


please advise
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
10 Comments
 
LVL 14

Expert Comment

by:CPColin
ID: 41837487
You wrote objecTwo when you probably meant objectTwo.
0
 
LVL 7

Author Comment

by:gudii9
ID: 41837505
even objectTwo same error?
hola
Caught: groovy.lang.MissingPropertyException: No such property: getName for class: FirstGroovyClass
groovy.lang.MissingPropertyException: No such property: getName for class: FirstGroovyClass
      at FirstGroovyClassImplementation.run(FirstGroovyClassImplementation.groovy:10)
please advise
0
 
LVL 14

Accepted Solution

by:
CPColin earned 250 total points
ID: 41837508
If Groovy properties act like properties do in other languages, you probably need to type either objectTwo.getName(), with the parentheses, or objectTwo.name, without "get".
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 7

Author Comment

by:gudii9
ID: 41845230
both not working
0
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 250 total points
ID: 41845910
both not working
Post the new error messages please
0
 
LVL 7

Author Comment

by:gudii9
ID: 41847276
hola
Caught: groovy.lang.MissingPropertyException: No such property: getName for class: FirstGroovyClass
groovy.lang.MissingPropertyException: No such property: getName for class: FirstGroovyClass
      at FirstGroovyClassImplementation.run(FirstGroovyClassImplementation.groovy:10)
my code is

import FirstGroovyClass
//class FirstGroovyClassImplementation {

      def object=new FirstGroovyClass()
      object.methodOne()
      
      
      
      def objectTwo=new FirstGroovyClass(name:'FirstGroovyClasse',place:'FirstGroovyClasssss')
      println objectTwo.getName
//}


above i am running as Run As---> Groovy script

class FirstGroovyClass {
String name
String place
def methodOne(){
println "hola"
	}
	static main(args) {
	
	}

}

Open in new window


i wonder why EE do not have separate groovy topic? where i can suggest add one?
0
 
LVL 7

Author Comment

by:gudii9
ID: 41847460
any good sample examples around these?
0
 
LVL 7

Author Comment

by:gudii9
ID: 41848736
class FirstGroovyClass {
	String name
	String place
	
	def methodOne(){
		println "hola"
	}
	//static main(args) {
	//}
}

Open in new window


import FirstGroovyClass
//class FirstGroovyClassImplementation {

	def object=new FirstGroovyClass()
	object.methodOne()
	
	
	
	def objectTwo=new FirstGroovyClass(name:'FirstGroovyClasse',place:'FirstGroovyClasssss')
	/*def method1(){
		println objectTwo.name;
	}*/
//}

Open in new window


when i ran FirstGroovyClassImplementation as groovy script i got
hola

i saw examples here which i explore more
https://www.tutorialspoint.com/groovy/groovy_json.htm
0
 
LVL 7

Author Comment

by:gudii9
ID: 41848788
//class GroovyLoop {
	//methodTwenty(){

for(def i=0;i<=10;i++){
	println(i)
}
	//}
	
//}

def j=10;

while(j<20){
	println(j)
	j++
}

Open in new window


above gave

0
1
2
3
4
5
6
7
8
9
10
10
11
12
13
14
15
16
17
18
19
0
 
LVL 7

Author Comment

by:gudii9
ID: 41848813
//class GroovyLoop {
	//methodTwenty(){

for(def i=0;i<=10;i++){
	println(i)
}
	//}
	
//}

def j=10;

while(j<20){
	println(j)
	j++
}

def list1=[1,4,6]
for(def z:list1)
println(z)


1.upto(5){
	println("EE")
}


1.step(6,3){
	println"$it"
}

3.times{
	println"EEE"
}


def arr=new String[3]
arr[0]="one"
arr[1]="two"
arr[2]="three"
println arr

println arr.length
println arr.size()
def arrInt=[1,2,5] as Integer[]
println arrInt.min()

def list=[]
println list.size


def lists=new ArrayList<String>()

def listss=[9,8,0]

lists.add("ep");
println lists

lists << "eh"
println lists

lists.push("ss")
println lists

lists.putAt(1,"zz")
println lists

println lists[1]

println lists.get(2)
println lists.getAt(0)
println lists[-1]

println lists.remove("zz")
println lists
lists.add("ep1");
lists.add("ep2");
lists.add("ep3");
 lists.remove(2)
 println lists
 
 lists=lists - "ep2"
 println lists
 
 
 def listNum=[1,6,4,7,9,0,2,9]
 println listNum.count(9)
 
 println listNum.sort()
 
 def liste=[4,7,[9,0],2,4,8]
 println liste
 println liste.flatten()
 
 
 def mapEx=[:]
 mapEx.put('color','blue')
 println mapEx.size()
 
 mapEx['size']='low'
 println mapEx.size()
 
 mapEx.length='22'
 println mapEx.size()
 
 mapEx << ['height':"39"]
 println mapEx.size()
 
 println mapEx['height']
 println mapEx.height
 
 def file=new File('TestFile.txt')
 println file.text
 
 
 def files=new File('TestFile.txt')
 println files.readLines()[3]
 
 println files.readLines().each {
	 line ->println line
 }
 
 
 
 files.readLines().each {
	 line ->line.tokenize().each{
		 word ->if(word=='e'){
			 println word
		 }
	 }
 }
 
 
 files.readLines().each {
	 line ->line.tokenize().each{
		 word ->
		 println word
	 }
 }
 
 
 def fileee=new File('TestFile.txt')
 //println fileee.absolutePath
 
 println file.size()
 
 println "File ? ${fileee.isFile()}"
 println  "Director ? ${fileee.isDirectory()}"
 
 //println file.renameTo('TestFile3.txt')
 
 def fils=new File('writeHere.txt')
 fils.write("blah")
 fils << "next blah"
 
 
 
 
 
 

Open in new window


0
1
2
3
4
5
6
7
8
9
10
10
11
12
13
14
15
16
17
18
19
1
4
6
EE
EE
EE
EE
EE
1
4
EEE
EEE
EEE
[one, two, three]
3
3
1
0
[ep]
[ep, eh]
[ep, eh, ss]
[ep, zz, ss]
zz
ss
ep
ss
true
[ep, ss]
[ep, ss, ep2, ep3]
[ep, ss, ep3]
2
[0, 1, 2, 4, 6, 7, 9, 9]
[4, 7, [9, 0], 2, 4, 8]
[4, 7, 9, 0, 2, 4, 8]
1
2
3
4
39
39
qqqq xxggg
sss
zz
e
tttttttttt
aaanext blah
e
qqqq xxggg
sss
zz
e
tttttttttt
aaanext blah
[qqqq xxggg, sss, zz, e, tttttttttt, aaanext blah]
e
qqqq
xxggg
sss
zz
e
tttttttttt
aaanext
blah
48
File ? true
Director ? false
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question