Reputation: 287
I am trying to read calendar events by specifying the date selection on query. No matter why I do I get error "Calendar.getInstance cannot be resolved to a type" on this line:
Calendar c_start= new Calendar.getInstance();
This is weird because I do import the java.util.Calendar;
Here is my code
package com.authorwjf.calsample;
import java.text.Format;
import java.text.SimpleDateFormat;
import android.util.Log;
import android.app.Activity;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.provider.CalendarContract;
import android.content.DialogInterface;
import android.database.Cursor;
import java.util.Calendar;
@Override
public void onClick(View v) {
TextView tv = (TextView)findViewById(R.id.data);
String title = "N/A";
Long start = 0L;
switch(v.getId()) {
case R.id.next:
if(!mCursor.isLast()) mCursor.moveToNext();
break;
case R.id.previous:
if(!mCursor.isFirst()) mCursor.moveToPrevious();
break;
}
Format df = DateFormat.getDateFormat(this);
Format tf = DateFormat.getTimeFormat(this);
try {
title = mCursor.getString(0);
start = mCursor.getLong(1);
} catch (Exception e) {
//ignore
}
tv.setText(title+" בתאריך "+df.format(start)+" בשעה "+tf.format(start));
}
}
Upvotes: 1
Views: 9566
Reputation: 121
Calendar follow Singleton design patten, then the costructor of the object is called by getInstace() method, this is why you must remove new
keyword when you instance the object.
Final code : Calendar c_start = Calendar.getInstance();
Upvotes: 0
Reputation: 541
change your code from..
Calendar c_start= new Calendar.getInstance();
to
Calendar c_start= Calendar.getInstance();
because Calendar.getInstance()
return an object of calendar..
Upvotes: 2
Reputation: 127
You have to simply change from
Calendar c_start= new Calendar.getInstance();
to
Calendar c_start = Calendar.getInstance();
Means you have to just remove new
keyword.
Upvotes: 7
Reputation: 1360
If you are really using this:
Calendar c_start= new Calendar.getInstance();
Then remove the new
keyword and it will work
Upvotes: 1