Hello people,
I am making some application and I have some error, which I can not solve, I searched on google but nothing helped me.
I have Main class and "Lasta" class, Lasta is name of class.
In Main class I only have this code:
package com.nemanjapetrovic.ndevelope.lasta;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity
{
Lasta lasta = new Lasta();
Button date,time,search;
EditText from_station,to_station;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
date = (Button)findViewById(R.id.date);
time = (Button)findViewById(R.id.time);
search = (Button)findViewById(R.id.search);
from_station = (EditText)findViewById(R.id.from_station);
to_station = (EditText)findViewById(R.id.to_station);
date.setText(lasta.get_DATE());
time.setText(lasta.get_TIME());
}
public void dateButton_OnClick(View v)
{
lasta.DateChange();
date.setText(lasta.get_DATE());
}
public void timeButton_OnClick(View v)
{
lasta.TimeChange();
time.setText(lasta.get_TIME());
}
public void seachButton_OnClick(View v)
{
lasta.Search();
}
}
In another class, Lasta class I have method who creates DatePickerDialog, and also TimePickerDialog.
Here is a code:
package com.nemanjapetrovic.ndevelope.lasta;
import android.app.Activity;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.os.Bundle;
import android.view.View;
public class Lasta extends Activity
{
private String _STATION_FROM;
private String _STATION_TO;
private String _DATE;
private String _TIME;
private Calendar nowCalendar = Calendar.getInstance();
public Lasta()
{
this._STATION_FROM = "";
this._STATION_TO = "";
UpdateDATE();
UpdateTIME();
}
public Lasta(String sf, String st, String d, String t)
{
this._STATION_FROM = sf;
this._STATION_TO = st;
this._DATE = d;
this._TIME = t;
}
HERE I AM GETTING AN ERROR
private DatePickerDialog.OnDateSetListener dateDialog = new DatePickerDialog.OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
nowCalendar.set(Calendar.YEAR, year);
nowCalendar.set(Calendar.MONTH, monthOfYear);
nowCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
UpdateDATE();
}
};
HERE I AM GETTING AN ERROR
public void DateChange()
{
new DatePickerDialog(this, DatePickerDialog.THEME_HOLO_DARK, dateDialog, nowCalendar.get(Calendar.YEAR), nowCalendar.get(Calendar.MONTH), nowCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
private void UpdateDATE()
{
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
this._DATE = df.format(this.nowCalendar.getTime());
}
I am getting an error in method called:
public void DateChange()
{
new DatePickerDialog(this, DatePickerDialog.THEME_HOLO_DARK, dateDialog, nowCalendar.get(Calendar.YEAR), nowCalendar.get(Calendar.MONTH), nowCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
Here is an error code:
04-18 21:53:14.192: E/AndroidRuntime(31880):
FATAL EXCEPTION: main
04-18 21:53:14.192: E/AndroidRuntime(31880): java.lang.IllegalStateException: Could not execute method of the activity
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.view.View$1.onClick(View.java:3804)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.view.View.performClick(View.java:4439)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.widget.Button.performClick(Button.java:139)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.view.View$PerformClick.run(View.java:18395)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.os.Handler.handleCallback(Handler.java:725)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.os.Handler.dispatchMessage(Handler.java:92)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.os.Looper.loop(Looper.java:176)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.app.ActivityThread.main(ActivityThread.java:5319)
04-18 21:53:14.192: E/AndroidRuntime(31880): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 21:53:14.192: E/AndroidRuntime(31880): at java.lang.reflect.Method.invoke(Method.java:511)
04-18 21:53:14.192: E/AndroidRuntime(31880): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
04-18 21:53:14.192: E/AndroidRuntime(31880): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
04-18 21:53:14.192: E/AndroidRuntime(31880): at dalvik.system.NativeStart.main(Native Method)
04-18 21:53:14.192: E/AndroidRuntime(31880): Caused by: java.lang.reflect.InvocationTargetException
04-18 21:53:14.192: E/AndroidRuntime(31880): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 21:53:14.192: E/AndroidRuntime(31880): at java.lang.reflect.Method.invoke(Method.java:511)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.view.View$1.onClick(View.java:3799)
04-18 21:53:14.192: E/AndroidRuntime(31880): ... 12 more
04-18 21:53:14.192: E/AndroidRuntime(31880): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.app.Activity.getSystemService(Activity.java:4662)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.app.Dialog.<init>(Dialog.java:164)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.app.AlertDialog.<init>(AlertDialog.java:114)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.app.AlertDialog.<init>(AlertDialog.java:110)
04-18 21:53:14.192: E/AndroidRuntime(31880): at android.app.DatePickerDialog.<init>(DatePickerDialog.java:113)
04-18 21:53:14.192: E/AndroidRuntime(31880): at com.nemanjapetrovic.ndevelope.lasta.Lasta.DateChange(Lasta.java:99)
04-18 21:53:14.192: E/AndroidRuntime(31880): at com.nemanjapetrovic.ndevelope.lasta.MainActivity.dateButton_OnClick(MainActivity.java:40)
Sorry for this long question. Thank you!