我是一個非常沮喪newbee! 我真的不知道從哪裏開始。我有一個基於傻瓜書中的應用程序的應用程序。得到它的工作。然後嘗試將其轉換爲使用時間和日期的WIMMOne對話框。在一堆錯誤的開始之後,我加載了其中一個樣本並使其工作。然後我將代碼分離出來並粘貼到我的示例中。我無法過去的錯誤。 (這不利於日食不斷增加了一些它自己。有時我加載源和所有報表,包括進口,被標記爲錯誤,有時我得到的R.id,---錯誤,我甚至有它標誌着註釋爲錯誤。收到編譯錯誤,我不uderstand
不過,我已經洗乾淨,並重新加載它足夠的時間,我覺得我到幾個真正的錯誤。
有地雷和示例代碼之間的一對夫婦的基本區別: 樣本是一個大的活動的java文件,礦是一個片段礦,在當時對話框一個單獨的Java文件中的樣品是在一個文件中,所以我編寫我的這種方式礦有兩個菜單,列表。用戶從中進入「詳細」菜單。樣品全部爲一個屏幕。
共有來自WIMM 2個JAR文件,我在庫兼得。
爲了節省空間,我包括了第一部分,我得到了3個錯誤,但如果需要的話,我會很樂意提供。
首先是樣品。它的工作原理,甚至與我的註釋代碼,沒有編譯錯誤: 謝謝,克拉克
package com.test.medication;
/**************************
* Java Imports
**************************/
import java.util.Calendar;
/******************************
* android imports
******************************/
import android.app.AlarmManager;
import android.app.Dialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.format.Time;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
/******************************
* Wimm imports
******************************/
import com.wimm.framework.app.LauncherActivity;
import com.wimm.framework.app.TextInputDialog;
import com.wimm.framework.app.TimePickerDialog;
import com.wimm.framework.app.TimePickerDialog.OnTimeSelectedListener;
public class MedicationsActivity extends LauncherActivity
{
/****************************
* private globals
****************************/
private TextInputDialog textDialog;
private TimePickerDialog timeDialog;
private long msToCount = 0;
private static String textInput = "please enter pills";
private EditText timeDisplay;
private EditText pillsDisplay;
private long newMs = 0;
private int Hours;
private int Minutes;
private static int hoursToCount = 0;
private static int minutesToCount = 0;
private Calendar c ;
private int mIndex = 0;
private boolean textEntered = false;
// get an store the simple name of this class into an String
private static final String TAG = MedicationsActivity.class.getSimpleName();
/***********************
* define constants
**********************/
// define id for both the time dialog, and the enter pills dialog
static final int TIME_DIALOG_ID = 0;
static final int PILLS_DIALOG_ID = 1;
// the actions for the intent definitions posted
public static final String ACTION_POST_NOTIFICATION = "com.test.medication.action.POST";
public static final String ACTION_UPDATE_NOTIFICATION = "com.test.medication.action.UPDATE";
public static final String ACTION_CANCEL_NOTIFICATION = "com.test.medication.action.CANCEL";
//delay between views
private static final int viewDelay = 5000; // ms
@Override
public void onCreate(Bundle savedInstanceState)
{
//-----------------------------------------------
// initialize time entry listener
// pass current state
super.onCreate(savedInstanceState);
// open up main layout resource and upload into wimm
setContentView(R.layout.main);
Log.d("MedsMC","S onCrt-1");
// Subscribe listeners to the buttons and text fields
Button okButton = (Button)findViewById(R.id.ok);
Button pillsButton = (Button)findViewById(R.id.enterPills);
pillsDisplay = (EditText)findViewById(R.id.entryMeds);
timeDisplay = (EditText)findViewById(R.id.entryTime);
Log.d("MedsMC","S onCrt-2L" + timeDisplay);
// set up the time picker dialog with initial time
//and subscribe a listener upon the press of ok n the time dialog
TimePickerDialog myTimerHandler = new TimePickerDialog(this);
myTimerHandler.setTime(6, 0);
myTimerHandler.setTimeSelectedListener(timeSetListener);
Log.d("MedsMC","S onCrt-3myTH" + timeDisplay);
這是我最新的與錯誤3:「TimePickerDialog」在多個地方被使用,始終有一個錯誤。
package com.dummies.android.taskreminder;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.app.DatePickerDialog.OnDateSetListener;
//import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.ContentUris;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri; //
import android.os.Bundle; //
import android.os.Handler;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View; //
//import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button; //
import android.widget.DatePicker;
import android.widget.EditText; //
//import android.widget.TimePicker;
import android.widget.Toast;
import android.util.Log; //
import android.text.format.Time;
import android.app.Dialog; //
import android.content.Context;
import android.content.Intent;
/*******************************************
* wimm imports
*/
import com.wimm.framework.app.LauncherActivity;
//import com.wimm.framework.app.TextInputDialog;
mport com.wimm.framework.app.TimePickerDialog;
import com.wimm.framework.app.TimePickerDialog.OnTimeSelectedListener;
//import com.wimm.framework.app.DatePickerDialog;
//import com.wimm.framework.app.DatePickerDialog.OnDateSelectedListener;
public class ReminderEditFragment
extends Fragment
implements OnDateSetListener,
// OnTimeSetListener,
LoaderCallbacks<Cursor>
{
private TimePickerDialog timeDialog;
//private EditText timeDisplay;
private static int intHours = 0;
private static int intMinutes = 0;
private long lngNewMs = 0;
private Calendar calC ;
// define constent to be used
private static final String DATE_FORMAT = "yyyy-MM-dd";
private static final String TIME_FORMAT = "kk:mm";
static final int TIME_DIALOG_ID = 0;
static final int PILLS_DIALOG_ID = 1;
public static final String DEFAULT_EDIT_FRAGMENT_TAG = "editFragmentTag";
private EditText mTitleText;
private EditText mBodyText;
//private TextInputDialog textDialog;
//private TextInputDialog mBodyDialog;
//private TimePickerDialog timeDialog;
private Button mTimeButton;
//private Button timeDisplay;
//private TimePickerDialog mTimeDialog;
private Button mDateButton;
private Button mConfirmButton;
private Calendar mCalendar;
//OK
@Override
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
// save the calendar instance
outState.putSerializable(CALENDAR, mCalendar);
}
private long mRowId;
//OK
@Override
public void onCreate(Bundle savedInstanceState)
{
//-- house keeping
super.onCreate(savedInstanceState);
Log.d("RemindEF","S onCrt");
if (savedInstanceState != null &&
savedInstanceState.containsKey(CALENDAR))
{
mCalendar = (Calendar) savedInstanceState.getSerializable(CALENDAR);
Log.d("RemindEF","Cs onCrt:" + mCalendar);
}
else
{
mCalendar = Calendar.getInstance();
Log.d("RemindEF","C onCrt:" + mCalendar);
}
Bundle arguments = getArguments();
//-----------------
// retrieve row id from list
if (arguments != null)
{
mRowId = arguments.getLong(ReminderProvider.COLUMN_ROWID);
Log.d("RemindEF","A onCrt:" + mRowId);
}
//-----------------------------------------------
// initialize time entry listener
//???????? ERROR: The method setContentView(int) is undefined for the type ReminderEditFragment
setContentView(R.layout.reminder_edit);
Log.d("RemindEF","X onCrt");
//???????ERROR: The method findViewById(int) is undefined for the type ReminderEditFragment
mTimeButton = (Button)findViewById(R.id.reminder_time);
Log.d("MedsMC","S onCrt-2L" + mTimeButton);
//?????? ERROR: The constructor TimePickerDialog(ReminderEditFragment) is undefined
TimePickerDialog myTimerHandler = new TimePickerDialog(this);
myTimerHandler.setTime(6, 0);
myTimerHandler.setTimeSelectedListener(timeSetListener);
Log.d("MedsMC","S onCrt-3myTH" + mTimeButton);
錯誤消息表明您嘗試調用不存在的類上的方法。在示例代碼中,名爲_setContentView()_的方法是類_MedicationsActivity_的一部分,該類擴展了_LauncherActivity_(可擴展_Activity_)。也許你的類應該_擴展_Activity _...,儘管每個類只能在Java中擴展一個類。 – jahroy