I have one fragment
which should save an hour, after doing all the code it simply generates an error when executing it
SelectordeAlarmas.java ( fragment
which will capture the alarms)
package company.viral.organizadorjec.FragmentMenu.Perfil;
import android.app.AlarmManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.icu.util.Calendar;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import company.viral.organizadorjec.ActivitysPrincipales.MainActivity;
import company.viral.organizadorjec.R;
public class SelectordeAlarmas extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//creamos la vista del fragment
View view = inflater.inflate(R.layout.selector_alarma, container, false);
final AlarmManager alarma;
//cramos las variables del layout
Button acepalarm = (Button) view.findViewById(R.id.btnaceptaralarma);
Button boralarm = (Button) view.findViewById(R.id.btnborraralarma);
Button cancelar = (Button) view.findViewById(R.id.btncancelaralarma);
//los TV
final TextView alarmview = (TextView)view.findViewById(R.id.avisoalarm);
//alarma
final TimePicker timePicker = (TimePicker)view.findViewById(R.id.timePicker);
//instanciamos la alarma
alarma=(AlarmManager)getActivity().getSystemService(Context.ALARM_SERVICE);
//necesitamos un calendar para la seleccion de tiempo
final Calendar calendar=Calendar.getInstance();
//implementar el metodo de aceptar alarma y cambiar aviso
acepalarm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calendar.set(Calendar.HOUR_OF_DAY,timePicker.getHour());
calendar.set(Calendar.MINUTE,timePicker.getMinute());
int hora=timePicker.getHour();
int minuto=timePicker.getMinute();
alarmview.setText("La alarma esta a "+hora+":"+minuto);
}
});
//implementamos el motodo del boton de cerrar sesion
cancelar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//establecemos un mensaje de alerta para la confirmacion
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage("¿Desea cerrar sesion?");
builder.setTitle("Alerta!");
builder.setPositiveButton("SI", new DialogInterface.OnClickListener() {
//de ser positivo vamos al inicio y cerramo
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i= new Intent(getContext(), MainActivity.class);
startActivity(i);
getActivity().finish();
}
});
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog=builder.create();
dialog.show();
}
});
return view;
}
}
selector_alarm.xml (xml of the fragment)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="company.viral.organizadorjec.FragmentMenu.Perfil.SelectordeAlarmas">>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<Space
android:layout_width="match_parent"
android:layout_height="35dp" />
<TextView
android:text="Seleccione su alarma."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:gravity="center"
android:textSize="24sp"
tools:textColor="@android:color/holo_blue_dark" />
<TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/timePicker" />
<TextView
android:text="Alarma no establecida."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/avisoalarm"
android:gravity="center"
android:textSize="24sp"
tools:textColor="@android:color/holo_blue_dark" />
<Space
android:layout_width="match_parent"
android:layout_height="35dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="Aceptar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@android:style/Widget.Button"
android:id="@+id/btnaceptaralarma"
android:onClick="onClickAceptarR" />
<Button
android:text="Borrar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@android:style/Widget.Button"
android:id="@+id/btnborraralarma"
android:onClick="onClickAceptarR" />
<Button
android:text="Cancelar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btncancelaralarma"
android:layout_weight="1"
android:onClick="onClickRegresar"
style="@android:style/Widget.Button" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>
This is for a schedule... at the moment I just want the selected time to be set to the TextView
one that says "alarm not set"
and simply when accessing fragment
I get this in thelogcat
01-28 14:40:50.817 1717-1717/? E/dalvikvm: Could not find class 'com.google.android.finsky.hygiene.HygieneJobService', referenced from method com.google.android.finsky.dailyhygiene.DailyHygiene.a
01-28 14:40:50.828 1717-1717/? E/dalvikvm: Could not find class 'com.google.android.finsky.services.MaintenanceWindowJobService', referenced from method com.google.android.finsky.dailyhygiene.DailyHygiene.g
01-28 14:40:51.552 1717-1717/? E/Finsky: [1] com.google.android.finsky.wear.bl.a(847): onConnectionFailed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
01-28 14:40:58.950 1500-1500/company.viral.organizadorjec E/AndroidRuntime: FATAL EXCEPTION: main
Process: company.viral.organizadorjec, PID: 1500
java.lang.NoClassDefFoundError: android.icu.util.Calendar
at company.viral.organizadorjec.FragmentMenu.Perfil.SelectordeAlarmas.onCreateView(SelectordeAlarmas.java:46)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1677)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:536)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
01-28 14:44:11.338 3616-3616/? E/cutils-trace: Error opening trace file: No such file or directory (2)
01-28 14:44:11.639 3616-3616/? E/memtrack: Couldn't load memtrack module (No such file or directory)
01-28 14:44:11.639 3616-3616/? E/android.os.Debug: failed to load memtrack module: -2
01-28 14:46:00.524 153-776/? E/AudioMTKHardware: setCommonParameters() still have param.size() = 1, remain param = "screen_state=off"
01-28 14:56:31.430 806-806/? E/RemoteViews: ANR Warning,RemoteViews can only be used once ,if not ,it may cause ANR in hosts such as Laucher,SystemUI. keys for search <ANR Exception MSG History>
01-28 14:57:25.630 806-806/? E/Sensors: new acc setDelay handle(0),ns(66667000) err! go to hwmsen
01-28 14:57:25.880 153-25479/? E/AudioMTKHardware: setCommonParameters() still have param.size() = 1, remain param = "screen_state=on"
The main error is:
Uses:
Instead of :
import android.icu.util.Calendar
;