{"id":2570,"date":"2022-08-30T15:25:58","date_gmt":"2022-08-30T15:25:58","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/03\/getting-compile-errors-i-dont-uderstand-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:25:58","modified_gmt":"2022-08-30T15:25:58","slug":"getting-compile-errors-i-dont-uderstand-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/getting-compile-errors-i-dont-uderstand-collection-of-common-programming-errors\/","title":{"rendered":"Getting compile errors, I don&#39;t uderstand-Collection of common programming errors"},"content":{"rendered":"<p>I am a very frustrated newbee! I really don&#8217;t know where to start. I have an app based on the one in the dummies book. Got it working. Then tried to convert it to use the WIMMOne dialogs for time and date. After a bunch of false starts I loaded one of their samples and got it working. I then isolated the code in that and pasted in my sample. I cannot get past errors. (It doesn&#8217;t help that eclipse constantly adds some of its own. Sometimes I load the source and all statements, including imports, are marked as errors, sometimes I get the R.id,&#8212; in error, I have even had it marked comments as in error.<\/p>\n<p>However, I have cleaned it and reloaded it enough times that I think I am down to a few real errors.<\/p>\n<p>There are a couple basic differences between mine and the sample code: The sample is one big activity java file, mine is in a fragment. Mine had a separate java file for the time dialog. The sample was in the one file, so I coded mine that way. Mine has two menus, a list from which the user goes to a &#8220;detail&#8221; menu. The sample is all one screen.<\/p>\n<p>There were 2 JAR files from WIMM, I have both in my libs.<\/p>\n<p>To save space I included the first part, where I am getting 3 errors, but will be happy to provide it all if needed.<\/p>\n<p>The first is the sample. It works and even with my commented code, there are no compile errors: Thanks,Clark<\/p>\n<pre><code>    package com.test.medication;\n\n\n    \/**************************\n     * Java Imports\n     **************************\/\n    import java.util.Calendar;\n\n    \/******************************\n     * android imports\n     ******************************\/\n    import android.app.AlarmManager;\n    import android.app.Dialog;\n    import android.app.PendingIntent;\n    import android.content.Context;\n    import android.content.Intent;\n    import android.net.Uri;\n    import android.os.Bundle;\n    import android.text.format.Time;\n    import android.util.Log;\n    import android.view.View;\n    import android.widget.Button;\n    import android.widget.EditText;\n\n    \/******************************\n     * Wimm imports\n     ******************************\/\n    import com.wimm.framework.app.LauncherActivity;\n    import com.wimm.framework.app.TextInputDialog;\n    import com.wimm.framework.app.TimePickerDialog;\n    import com.wimm.framework.app.TimePickerDialog.OnTimeSelectedListener;\n\n    public class MedicationsActivity extends LauncherActivity \n    {\n\n\n        \/****************************\n         * private globals\n         ****************************\/\n        private TextInputDialog textDialog;\n        private TimePickerDialog timeDialog;\n        private long msToCount = 0;\n        private static String textInput = \"please enter pills\";\n        private EditText timeDisplay;\n        private EditText pillsDisplay;\n        private long newMs = 0;\n        private int Hours;\n        private int Minutes;\n        private static int hoursToCount = 0;\n        private static int minutesToCount = 0;\n        private Calendar c ;\n        private int mIndex = 0;\n        private boolean textEntered = false;\n\n    \/\/ get an store the simple name of this class into an String\n    private static final String TAG = MedicationsActivity.class.getSimpleName();\n\n\n     \/***********************\n     *  define constants\n     **********************\/\n    \/\/ define id for both the time dialog, and the enter pills dialog\n    static final int TIME_DIALOG_ID = 0;\n    static final int PILLS_DIALOG_ID = 1;\n    \/\/ the actions for the intent definitions posted \n    public static final String ACTION_POST_NOTIFICATION     = \"com.test.medication.action.POST\";\n    public static final String ACTION_UPDATE_NOTIFICATION   = \"com.test.medication.action.UPDATE\";\n    public static final String ACTION_CANCEL_NOTIFICATION   = \"com.test.medication.action.CANCEL\";\n\n    \/\/delay between views\n    private static final int viewDelay      = 5000;  \/\/ ms\n\n    @Override\n    public void onCreate(Bundle savedInstanceState) \n    {\n\n        \/\/-----------------------------------------------\n        \/\/ initialize time entry listener\n            \/\/ pass current state\n            super.onCreate(savedInstanceState);\n\n            \/\/ open up main layout resource and upload into wimm \n            setContentView(R.layout.main);\n\n            Log.d(\"MedsMC\",\"S onCrt-1\");\n\n            \/\/ Subscribe listeners to the buttons and text fields\n            Button okButton = (Button)findViewById(R.id.ok);\n            Button pillsButton = (Button)findViewById(R.id.enterPills);\n            pillsDisplay = (EditText)findViewById(R.id.entryMeds);\n            timeDisplay = (EditText)findViewById(R.id.entryTime); \n            Log.d(\"MedsMC\",\"S onCrt-2L\" + timeDisplay);\n\n            \/\/ set up the time picker dialog with initial time\n            \/\/and subscribe a listener upon the press of ok n the time dialog\n            TimePickerDialog myTimerHandler = new TimePickerDialog(this);\n            myTimerHandler.setTime(6, 0);\n            myTimerHandler.setTimeSelectedListener(timeSetListener);\n            Log.d(\"MedsMC\",\"S onCrt-3myTH\" + timeDisplay);\n<\/code><\/pre>\n<p>This is my latest with 3 of the errors: the &#8220;TimePickerDialog&#8221; is used in several places and always has an error.<\/p>\n<pre><code>package com.dummies.android.taskreminder;\nimport java.text.SimpleDateFormat; \nimport java.util.Calendar;  \nimport java.util.Date;\n\nimport android.app.DatePickerDialog.OnDateSetListener;\n\/\/import android.app.TimePickerDialog.OnTimeSetListener;\nimport android.content.ContentUris;\nimport android.content.ContentValues;\nimport android.database.Cursor;\nimport android.net.Uri;   \/\/\nimport android.os.Bundle;  \/\/\nimport android.os.Handler; \nimport android.support.v4.app.DialogFragment;\nimport android.support.v4.app.Fragment;\nimport android.support.v4.app.FragmentTransaction;\nimport android.support.v4.app.LoaderManager.LoaderCallbacks;\nimport android.support.v4.content.CursorLoader;\nimport android.support.v4.content.Loader;\nimport android.view.LayoutInflater;\nimport android.view.View;  \/\/\n\/\/import android.view.View.OnClickListener;\nimport android.view.ViewGroup;\nimport android.widget.Button; \/\/\nimport android.widget.DatePicker;\nimport android.widget.EditText;  \/\/\n\/\/import android.widget.TimePicker;\nimport android.widget.Toast;\nimport android.util.Log;  \/\/\nimport android.text.format.Time;\nimport android.app.Dialog; \/\/\nimport android.content.Context;\nimport android.content.Intent;\n\n\/*******************************************\n * wimm imports\n *\/\n\nimport com.wimm.framework.app.LauncherActivity;\n\/\/import com.wimm.framework.app.TextInputDialog;\nmport com.wimm.framework.app.TimePickerDialog;\nimport com.wimm.framework.app.TimePickerDialog.OnTimeSelectedListener;\n\/\/import com.wimm.framework.app.DatePickerDialog;\n\/\/import com.wimm.framework.app.DatePickerDialog.OnDateSelectedListener;\n\n\npublic class ReminderEditFragment\n             extends Fragment\n             implements OnDateSetListener,\n           \/\/             OnTimeSetListener,\n                        LoaderCallbacks \n   {\n\n    private TimePickerDialog timeDialog;\n    \/\/private EditText timeDisplay;\n\n    private static int intHours = 0;\n    private static int intMinutes = 0;\n    private long lngNewMs = 0;\n    private Calendar calC ;\n\n    \/\/ define constent to be used \n    private static final String DATE_FORMAT = \"yyyy-MM-dd\";\n    private static final String TIME_FORMAT = \"kk:mm\";\n\n    static final int TIME_DIALOG_ID = 0;\n    static final int PILLS_DIALOG_ID = 1;\n\n    public static final String DEFAULT_EDIT_FRAGMENT_TAG = \"editFragmentTag\"; \n    private EditText mTitleText;\n\n    private EditText mBodyText;\n    \/\/private TextInputDialog textDialog;\n    \/\/private TextInputDialog mBodyDialog;\n\n    \/\/private TimePickerDialog timeDialog;\n    private Button mTimeButton;\n\n\n    \/\/private Button timeDisplay;\n\n    \/\/private TimePickerDialog mTimeDialog;\n\n    private Button mDateButton;\n    private Button mConfirmButton;\n    private Calendar mCalendar;\n\n    \/\/OK\n    @Override\n    public void onSaveInstanceState(Bundle outState)\n       {\n        super.onSaveInstanceState(outState);\n        \/\/ save the calendar instance\n            outState.putSerializable(CALENDAR, mCalendar);\n       }\n\n    private long mRowId;        \n\n\n    \/\/OK\n    @Override\n    public void onCreate(Bundle savedInstanceState)\n       { \n        \/\/-- house keeping\n        super.onCreate(savedInstanceState);\n        Log.d(\"RemindEF\",\"S onCrt\");\n\n        if (savedInstanceState != null &amp;&amp;\n            savedInstanceState.containsKey(CALENDAR) )\n           {\n             mCalendar = (Calendar) savedInstanceState.getSerializable(CALENDAR);\n             Log.d(\"RemindEF\",\"Cs onCrt:\" + mCalendar);\n           }\n        else\n           {\n             mCalendar = Calendar.getInstance();\n             Log.d(\"RemindEF\",\"C onCrt:\" + mCalendar);\n           }\n        Bundle arguments = getArguments(); \n\n        \/\/-----------------\n        \/\/  retrieve row id from list\n        if (arguments != null)\n           {\n            mRowId = arguments.getLong(ReminderProvider.COLUMN_ROWID);\n            Log.d(\"RemindEF\",\"A onCrt:\" + mRowId);\n               }                \n\n        \/\/-----------------------------------------------\n        \/\/ initialize time entry listener\n    \/\/???????? ERROR: The method setContentView(int) is undefined for the type ReminderEditFragment\n           setContentView(R.layout.reminder_edit);\n\n           Log.d(\"RemindEF\",\"X onCrt\");\n\n    \/\/???????ERROR: The method findViewById(int) is undefined for the type ReminderEditFragment\n           mTimeButton = (Button)findViewById(R.id.reminder_time); \n           Log.d(\"MedsMC\",\"S onCrt-2L\" + mTimeButton);\n\n    \/\/?????? ERROR: The constructor TimePickerDialog(ReminderEditFragment) is undefined\n            TimePickerDialog myTimerHandler = new TimePickerDialog(this);\n            myTimerHandler.setTime(6, 0);\n            myTimerHandler.setTimeSelectedListener(timeSetListener);\n            Log.d(\"MedsMC\",\"S onCrt-3myTH\" + mTimeButton);\n<\/code><\/pre>\n<ol>\n<li>\n<p>You are copying code that was being used in an <code>Activity<\/code> and using it in a <code>Fragment<\/code>.<\/p>\n<p>This will require some modification.<\/p>\n<pre><code>setContentView(R.layout.reminder_edit);\n<\/code><\/pre>\n<p>This is used to set the layout. It is called inside <code>onCreate()<\/code>.<\/p>\n<pre><code>mTimeButton = (Button) findViewById(R.id.reminder_time); \n<\/code><\/pre>\n<p>This is used to get a reference to a certain View.<\/p>\n<p>In a <code>Fragment<\/code>, to set the layout and find views we override <code>onCreateView()<\/code>:<\/p>\n<pre><code>@Override\npublic View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){\n    View v = inflater.inflate(R.layout.reminder_edit, null);\n    mTimeButton = (Button) v.findViewById(R.id.reminder_time); \n    return v;\n}\n<\/code><\/pre>\n<pre><code>TimePickerDialog myTimerHandler = new TimePickerDialog(this);\n<\/code><\/pre>\n<p>The argument of the <code>TimePickerDialog<\/code> constructor is a <code>Context<\/code> object. In an Activity <code>this<\/code> would be valid because it would reference the Activity&#8217;s instance. In a Fragment you should call <code>getActivity()<\/code> instead.<\/p>\n<pre><code>TimePickerDialog myTimerHandler = new TimePickerDialog(getActivity());\n<\/code><\/pre>\n<\/li>\n<li>\n<p>This is mainly an attempt to explain what the compilation errors <em>mean<\/em>.<\/p>\n<blockquote>\n<p>ERROR: The method setContentView(int) is undefined for the type ReminderEditFragment<\/p>\n<\/blockquote>\n<p>You are calling a <code>setContentView<\/code> method on <code>ReminderEditFragment<\/code>, but <code>ReminderEditFragment<\/code> has no such method.<\/p>\n<p>It appears that you are trying to call <code>Activity.setContentView<\/code> on <code>this<\/code>. But <code>this<\/code> is not an <code>Activity<\/code> &#8230; because of your refactoring.<\/p>\n<blockquote>\n<p>ERROR: The method findViewById(int) is undefined for the type ReminderEditFragment<\/p>\n<\/blockquote>\n<p>Same as above, for a different <code>Activity<\/code> method.<\/p>\n<p>(I&#8217;m not an Android expert, but it seems that you are doing things on a Fragment that you should be doing on an Activity. Perhaps, your Fragment class needs a reference to some Activity instance that it can use for those calls &#8230; ?)<\/p>\n<blockquote>\n<p>ERROR: The constructor TimePickerDialog(ReminderEditFragment) is undefined<\/p>\n<\/blockquote>\n<p>The standard <code>TimePickerDialog<\/code> class has 2 constructors, but neither of them take a single <code>ReminderEditFragment<\/code> argument. You need to look at the <code>TimePickerDialog<\/code> javadoc &#8230;<\/p>\n<\/li>\n<li>\n<p>1) Don&#8217;t run your app, when active XML file.<br \/>\nIf you did it, clean project and remove generated file<\/p>\n<p>2) ?lways save project <code>Ctrl + Shift + S<\/code> after adding widgets to layout. After saving will generated an addresses of this widgets and will have no problem with<br \/>\n<code>The method findViewById(int) is undefined for the type ReminderEditFragment<\/code><\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-02-03 02:34:49. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am a very frustrated newbee! I really don&#8217;t know where to start. I have an app based on the one in the dummies book. Got it working. Then tried to convert it to use the WIMMOne dialogs for time and date. After a bunch of false starts I loaded one of their samples and [&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-2570","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2570","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=2570"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2570\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}