{"id":1614,"date":"2022-08-30T15:18:00","date_gmt":"2022-08-30T15:18:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/my-program-tells-me-that-my-method-is-undefined-for-my-type-what-does-that-mean-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:18:00","modified_gmt":"2022-08-30T15:18:00","slug":"my-program-tells-me-that-my-method-is-undefined-for-my-type-what-does-that-mean-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/my-program-tells-me-that-my-method-is-undefined-for-my-type-what-does-that-mean-collection-of-common-programming-errors\/","title":{"rendered":"My program tells me that my method is undefined for my type what does that mean?-Collection of common programming errors"},"content":{"rendered":"<p>I wrote a code that is supposed to take an array and sort it from smallest value to largest, but I get an error. this is the code<\/p>\n<pre><code>public class minHeapify{\n    public static void exchange(int a[],int i,int j) {\n        int temp = a[i];\n        a[i] = a[j];\n        a[j] = temp;\n    }\n    public static int parent(int i) {\n        return (int) Math.floor((i - 1)\/2);\n    }\n    public static int left(int i) {\n        return 2*i + 1;\n    }\n    public static int right(int i) {\n        return 2*(i+1);\n    }\n    public minHeapify(int a[], int start,int end) {\n        int l = left(start); int r = right(start);\n        int smallest;\n        if(l &gt;= end){\n            smallest = (a[l] &lt; a[start])? l: start;\n        }\n        if(r &gt;= end){\n            smallest = (a[r] &lt; a[smallest])? r: smallest;\n        }\n        if(smallest != start) {\n            exchange(a,start,smallest);\n            minHeapify(a,smallest,end);\n        }\n    }\n} \n<\/code><\/pre>\n<p>the error that I get is &#8221; The method minHeapify(int[], int, int) is undefined for the type minHeapify&#8221; and im not sure what that means.<\/p>\n<ol>\n<li>\n<p>The problem is that the method has the same name as the class and has no return type. Therefore, from the compiler&#8217;s point of view, it&#8217;s a constructor rather than an ordinary method. And a constructor can&#8217;t call itself in the manner your method is trying to.<\/p>\n<p>Rename the method and add a return type. If the method needs to be automatically invoked upon construction, simply call it from the constructor.<\/p>\n<\/li>\n<li>\n<p>Java thinks that <code>public minHeapify(int a[], int start,int end)<\/code> is a constructor, not a normal method. You can fix it by respecting the convention that class names are uppercase: <code>public class MinHeapify<\/code>.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-27 12:02:07. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I wrote a code that is supposed to take an array and sort it from smallest value to largest, but I get an error. this is the code public class minHeapify{ public static void exchange(int a[],int i,int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } public static int parent(int i) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1614","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1614"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1614\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}