• Post Reply Bookmark Topic Watch Topic
  • New Topic

Guidance in reference to splitting up this class to manageable parts  RSS feed

 
Keith Zettler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello . Dalvik in eclipse is giving me an error "W/dalvikvm(274): VFY: arbitrarily rejecting large method (regs=259 count=9200)"
It would seem i have crossed a line in the sand in reference to acceptable class size and or complexity.
I am a self taught programmer and i use that term loosely .
Is there any way to consolidate this class ? How could i split it in half ?
This class is populated with variables from another class

Thank you in advance for any input

package com.example.

Graph1Activity
 
Ashish Dutt
Ranch Hand
Posts: 172
Java MySQL Database Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow, huge listing of a program... have you tried creating custom interfaces and placing the required methods in the interface and then just implement them
 
Keith Zettler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashish Dutt wrote:wow, huge listing of a program... have you tried creating custom interfaces and placing the required methods in the interface and then just implement them


I am not sure how to go about that. could you show me an example? thanks
 
Ashish Dutt
Ranch Hand
Posts: 172
Java MySQL Database Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to docs at oracle, "In the Java programming language, an interface is a reference type, similar to a class, that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces." Now, if your code has a lot of constants then you can define them in an interface and later implement it. You can refer to the following link http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html and/or http://docs.oracle.com/javase/tutorial/java/IandI/usinginterface.html
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are simpler solutions at hand here that doesn't need interfaces. I haven't gone through all 1500 lines of code, but I think you could reduce a lot of your code by just using arrays

Something like this.. I am just showing a 3 elements long version.. but you can extend it to be any amount. also, this is just part of your code that I have modified to see how you can use arrays.. you should really be converting several lists of variables to arrays

>
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keith Zettler wrote:Is there any way to consolidate this class ? How could i split it in half ?

That's the wrong way of thinking. Do you in fact want to split it in half?
You may be able to split it in thirds, or tenths, or as many pieces as makes sense.

Jayesh has almost certainly put his finger on the nub of the problem though: you're not using arrays (or Lists).

Why do you have 100 separately named variables?
If indeed they are variables (which seems unlikely), you should almost certainly put them in an array.
And if they aren't and you MUST be able to access them by individual names, make them an enum.

BTW: For future reference, that is FAR too much code to post.
Also: the lines in it are FAR TOO LONG (←click).
Please re-read the UseCodeTags page again. Thoroughly.

Thanks.

Winston
 
Keith Zettler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
Keith Zettler wrote:Is there any way to consolidate this class ? How could i split it in half ?

That's the wrong way of thinking. Do you in fact want to split it in half?
You may be able to split it in thirds, or tenths, or as many pieces as makes sense.

Jayesh has almost certainly put his finger on the nub of the problem though: you're not using arrays (or Lists).

Why do you have 100 separately named variables?
If indeed they are variables (which seems unlikely), you should almost certainly put them in an array.
And if they aren't and you MUST be able to access them by individual names, make them an enum.

BTW: For future reference, that is FAR too much code to post.
Also: the lines in it are FAR TOO LONG (←click).
Please re-read the UseCodeTags page again. Thoroughly.

Thanks.

Winston


Truth is i haven't a clue how to use Arrays or lists in even the most rudimentary way. So with the advice from taken from this thread i am going learn how to utilize these .I had a nagging sense that i was building this app the hard way but i had no guidance in the way of strategy. There are alot of tutorials out there for accomplishing this and accomplishing that but i have difficulty finding learning resources in reference to the architecture of a program and the most efficient way to get from a-z. I have read the guidelines and i will keep future posts in line with the guidelines. Thank both of you
 
Keith Zettler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayesh A Lalwani wrote:There are simpler solutions at hand here that doesn't need interfaces. I haven't gone through all 1500 lines of code, but I think you could reduce a lot of your code by just using arrays

Something like this.. I am just showing a 3 elements long version.. but you can extend it to be any amount. also, this is just part of your code that I have modified to see how you can use arrays.. You should really be converting several lists of variables to arrays

>


Jayesh what code does this string replace within the activity? These integers are the sum of 2 seekbars from another activity .


Answering this question will accelerate my understanding significantly
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!