Error android.database.sqlite.SQLiteException: uknown error (code 0) - image

I have existing ListView which filled with some information from SQLite database. I want to store and retrieve images from SQLite database then show it in ListView. I had already build Databasehandler and Adapter for that. But, the problem is when I run my project it get uknown error (code 0): Native could not create new byte[].
-Logcat
11-10 00:32:24.797: E/AndroidRuntime(2295): FATAL EXCEPTION: main
11-10 00:32:24.797: E/AndroidRuntime(2295): android.database.sqlite.SQLiteException: unknown error (code 0): Native could not create new byte[]
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.database.CursorWindow.nativeGetBlob(Native Method)
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.database.CursorWindow.getBlob(CursorWindow.java:399)
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.database.AbstractWindowedCursor.getBlob(AbstractWindowedCursor.java:45)
11-10 00:32:24.797: E/AndroidRuntime(2295): at kre.db.DatabaseHandler.getAllCard(DatabaseHandler.java:275)
11-10 00:32:24.797: E/AndroidRuntime(2295): at com.example.kre.MyWallet.onActivityCreated(MyWallet.java:58)
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:848)
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.app.BackStackRecord.run(BackStackRecord.java:635)
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.os.Handler.handleCallback(Handler.java:615)
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.os.Handler.dispatchMessage(Handler.java:92)
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.os.Looper.loop(Looper.java:137)
11-10 00:32:24.797: E/AndroidRuntime(2295): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-10 00:32:24.797: E/AndroidRuntime(2295): at java.lang.reflect.Method.invokeNative(Native Method)
11-10 00:32:24.797: E/AndroidRuntime(2295): at java.lang.reflect.Method.invoke(Method.java:511)
11-10 00:32:24.797: E/AndroidRuntime(2295): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-10 00:32:24.797: E/AndroidRuntime(2295): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-10 00:32:24.797: E/AndroidRuntime(2295): at dalvik.system.NativeStart.main(Native Method)
-MyWallet
package com.example.kre;
import kre.adapter.ListAdapterMyWallet;
import kre.db.DatabaseHandler;
import kre.model.Card;
import kre.model.Category;
import com.example.login.R;
import android.os.Bundle;
import android.app.Fragment;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
public class MyWallet extends Fragment {
public MyWallet(){}
ArrayList<Card> cardList = new ArrayList<Card>();
List<Category> listCategory;
ListView listView;
ListAdapterMyWallet adapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.mywallet, container, false);
return rootView;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
listView = (ListView) getView().findViewById(R.id.list);
DatabaseHandler db = new DatabaseHandler(getActivity());
/*listCategory = db.getAllCategory();
if(listCategory.size()==0)
{
db.addCategory(new Category("Food"));
db.addCategory(new Category("Shopping"));
db.addCategory(new Category("Health"));
listCategory = db.getAllCategory();
}*/
List<Card> cards = db.getAllCard();
if(cards.size() == 0)
{
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte imageInByte[] = stream.toByteArray();
db.addCard(new Card(imageInByte, "Pizza Hut", 0));
}
for(Card cd : cards){
String log = "ID: " + cd.getId() + "Image: " + cd.getCardImg() + "Name: " + cd.getCardName()
+ "Card Type Id: " + cd.getCardTypeId();
Log.d("Result: ", log);
cardList.add(cd);
}
adapter = new ListAdapterMyWallet(getActivity(), R.layout.list_row_mywallet, cardList);
listView.setAdapter(adapter);
}
}
-ListAdapterMyWallet
package kre.adapter;
import kre.model.Card;
import com.example.login.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
public class ListAdapterMyWallet extends ArrayAdapter<Card> {
Context context;
int layoutResourceId;
ArrayList<Card> cardItems = new ArrayList<Card>();
public ListAdapterMyWallet(Context context, int layoutResourceId ,ArrayList<Card> cardItems) {
super(context, layoutResourceId, cardItems);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.cardItems = cardItems;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
CardHolder holder = null;
if(row==null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new CardHolder();
holder.txtCardName = (TextView)row.findViewById(R.id.card_name);
holder.imgIcon = (ImageView)row.findViewById(R.id.card_img);
row.setTag(holder);
}else
{
holder = (CardHolder)row.getTag();
}
Card card = cardItems.get(position);
holder.txtCardName.setText(card.getCardName());
//convert byte to bitmap take from contact class
byte[] outImage=card.getCardImg();
ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage);
Bitmap theImage = BitmapFactory.decodeStream(imageStream);
holder.imgIcon.setImageBitmap(theImage);
return row;
}
static class CardHolder
{
ImageView imgIcon;
TextView txtCardName;
}
}
-DatabaseHandler
package kre.db;
import java.util.ArrayList;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import kre.model.Profile;
import kre.model.Card;
import kre.model.Category;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
//Database name
private static final String DATABASE_NAME = "KRE";
//Table names
private static final String TABLE_PROFILE = "profile";
private static final String TABLE_CATEGORY = "category";
private static final String TABLE_CARD = "card";
//Common column names
private static final String KEY_ID = "id";
private static final String KEY_CREATED_AT ="created_at";
//Profile column names
private static final String KEY_IMG = "img";
private static final String KEY_EMAIL = "email";
private static final String KEY_NAME = "name";
private static final String KEY_PHONE = "phone";
//Category column names
private static final String KEY_CATEGORY ="category";
//Card column names
private static final String KEY_CARD_IMG = "card_img";
private static final String KEY_CARD_NAME = "card_name";
private static final String KEY_CARD_TYPE_ID ="card_type_id";
public DatabaseHandler(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
//Category table create statement
private static final String CREATE_TABLE_CATEGORY = "CREATE TABLE " + TABLE_CATEGORY
+ "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_CATEGORY + " TEXT,"
+ KEY_CREATED_AT + " DATETIME" + ")";
//Card table create statement
private static final String CREATE_TABLE_CARD = "CREATE TABLE " + TABLE_CARD
+ "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_CARD_IMG + " BLOB," +
KEY_CARD_NAME + " TEXT," + KEY_CARD_TYPE_ID + " INTEGER," + KEY_CREATED_AT + " DATETIME" + ")";
//Profile table create statement
private static final String CREATE_TABLE_PROFILE = "CREATE TABLE " + TABLE_PROFILE +
"(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_IMG + " BLOB," +
KEY_EMAIL + " TEXT," + KEY_NAME + " TEXT," + KEY_PHONE + " TEXT" + ")";
#Override
public void onCreate(SQLiteDatabase db){
db.execSQL(CREATE_TABLE_CATEGORY);
db.execSQL(CREATE_TABLE_PROFILE);
db.execSQL(CREATE_TABLE_CARD);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVesion, int newVersion){
db.execSQL("DROP TABLE IF EXIST " + TABLE_PROFILE);
db.execSQL("DROP TABLE IF EXIST " + TABLE_CATEGORY);
db.execSQL("DROP TABLE IF EXIST " + TABLE_CARD);
onCreate(db);
}
//Profile
public void addProfile(Profile profile){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_IMG, profile.getImg());
values.put(KEY_EMAIL, profile.getEmail());
values.put(KEY_NAME, profile.getName());
values.put(KEY_PHONE, profile.getPhone());
db.insert(TABLE_PROFILE, null, values);
db.close();
}
public Profile getProfile(int id){
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_PROFILE, new String[]{KEY_ID, KEY_IMG, KEY_EMAIL, KEY_NAME, KEY_PHONE},
KEY_ID + "=?", new String[]{String.valueOf(id)}, null, null, null, null);
if(cursor!=null)
cursor.moveToFirst();
Profile profile = new Profile(Integer.parseInt(cursor.getString(0)), cursor.getBlob(1),
cursor.getString(2), cursor.getString(3), cursor.getString(4));
return profile;
}
public List<Profile> getAllProfile(){
List<Profile> profileList = new ArrayList<Profile>();
String selectQuery = "SELECT * FROM " + TABLE_PROFILE;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if(cursor.moveToFirst())
{
do{
Profile profile = new Profile();
profile.setID(Integer.parseInt(cursor.getString(0)));
profile.setImg(cursor.getBlob(1));
profile.setEmail(cursor.getString(2));
profile.setName(cursor.getString(3));
profile.setPhone(cursor.getString(4));
profileList.add(profile);
}while(cursor.moveToNext());
}
return profileList;
}
public int getProfileCounts(){
int count = 0;
String countQuery = "SELECT * FROM " + TABLE_PROFILE;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
if(cursor != null && !cursor.isClosed()){
count = cursor.getCount();
cursor.close();
}
return count;
}
public int updateProfile(Profile profile){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_IMG, profile.getImg());
values.put(KEY_EMAIL, profile.getEmail());
values.put(KEY_NAME, profile.getName());
values.put(KEY_PHONE, profile.getPhone());
return db.update(TABLE_PROFILE, values, KEY_ID + " = ?", new String[]{String.valueOf(profile.getID())});
}
public void updatePicture(byte[] imageInByte, int id){
SQLiteDatabase db = this.getWritableDatabase();
String strSQL = "UPDATE profile SET img = '"+imageInByte+"' WHERE id = " +id+"";
db.execSQL(strSQL);
db.close();
}
public void deleteProfile(Profile profile){
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_PROFILE, KEY_ID + "=?", new String[]{String.valueOf(profile.getID())});
db.close();
}
//Category
public void addCategory(Category category){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_CATEGORY, category.getCategory());
values.put(KEY_CREATED_AT, getDateTime());
db.insert(TABLE_CATEGORY, null, values);
db.close();
}
public Category getCategory(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CATEGORY, new String[] { KEY_ID,
KEY_CATEGORY}, KEY_ID + "=?", new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
Category category = new Category(Integer.parseInt(cursor.getString(0)),
cursor.getString(1));
// return contact
return category;
}
public List<Category> getAllCategory(){
List<Category> categoryList = new ArrayList<Category>();
String selectQuery = "SELECT * FROM " + TABLE_CATEGORY;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if(cursor.moveToFirst()){
do{
Category category = new Category();
category.setId(Integer.parseInt(cursor.getString(0)));
category.setCategory(cursor.getString(1));
category.setCreatedAt(cursor.getString(2));
categoryList.add(category);
}while(cursor.moveToNext());
}
return categoryList;
}
public int updateCategory(Category category) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_CATEGORY, category.getCategory());
return db.update(TABLE_CATEGORY, values, KEY_ID + " = ?", new String[] { String.valueOf(category.getId())});
}
public void deleteCategory(Category category) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_CATEGORY, KEY_ID + " = ?", new String[] { String.valueOf(category.getId())});
db.close();
}
public int getCategoryCount(){
String countQuery = "SELECT * FROM " + TABLE_CATEGORY;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
return cursor.getCount();
}
//Card
public void addCard(Card card){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_CARD_IMG, card.getCardImg());
values.put(KEY_CARD_NAME, card.getCardName());
values.put(KEY_CARD_TYPE_ID, Integer.toString(card.getCardTypeId()));
values.put(KEY_CREATED_AT, getDateTime());
db.insert(TABLE_CARD, null, values);
db.close();
}
public List<Card> getAllCardWithCategory(int categoryId){
List<Card> cardList = new ArrayList<Card>();
String selectQuery = "SELECT * FROM " + TABLE_CARD + " WHERE " + KEY_CARD_TYPE_ID + "=" + String.valueOf(categoryId) + ";";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if(cursor.moveToFirst()){
do{
Card card = new Card();
card.setCardId(Integer.parseInt(cursor.getString(0)));
card.setCardImg(cursor.getBlob(1));
card.setCardName(cursor.getString(2));
card.setCardTypeId(Integer.parseInt(cursor.getString(3)));
card.setCreatedAt(cursor.getString(4));
cardList.add(card);
}while(cursor.moveToLast());
}
return cardList;
}
public List<Card> getAllCard(){
List<Card> cardList = new ArrayList<Card>();
String selectQuery = "SELECT * FROM " + TABLE_CARD;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if(cursor.moveToFirst()){
do{
Card card = new Card();
card.setCardId(Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_ID))));
card.setCardImg(cursor.getBlob(cursor.getColumnIndex(KEY_CARD_IMG)));
card.setCardName(cursor.getString(cursor.getColumnIndex(KEY_CARD_NAME)));
card.setCardTypeId(Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_CARD_TYPE_ID))));
card.setCreatedAt(cursor.getString(cursor.getColumnIndex(KEY_CREATED_AT)));
cardList.add(card);
}while(cursor.moveToLast());
}
return cardList;
}
//getDateTime function
private String getDateTime() {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss", Locale.getDefault());
Date date = new Date();
return dateFormat.format(date);
}
}
when I delete db.addCard method, my program work, but i can't add images into database. Another fragment of my program is to store profile picture and information, whether this is due to lack of memory?
Sorry for my bad English, any help is welcome! Thanks

Related

AsyncTask Crashing on postExecute

I have a problem when using asyntask to query all the data in a table and put it in an array List and then send it to the server. I am able to send the data to the server successfully. But the application crashes on the postexecute of the asynctask giving the following error:
(W/System.errīš• org.json.JSONException: Value ["com.atlantis.eclectics.agentbank.SyncMembersActivity$MemberRecords#41b06d18","com.atlantis.eclectics.agentbank.SyncMembersActivity$MemberRecords#41b070b8"] of type org.json.JSONArray cannot be converted to JSONObject)..
What could be problem? Where am i getting it wrong. Someone please help...Thanks very much.
package com.practical.tasks.school;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.NotificationManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
#SuppressWarnings("deprecation")
public class SyncMembersActivity extends ActionBarActivity {
CustomHttpClient jParser = new CustomHttpClient();
ListView lstView;
public MainDB dbs;
public SQLiteDatabase db;
public static String fname;
String username = "atlantis";
String password = "#t1#ntis";
Button submit;
String statusN = "NO";
String statusY = "YES";
String url = "http://123.456.78.90:1234/Api/create/Post";
String FirstName = "";
String SecondName = "";
String MobileNumber = "";
String DateofBirth = "";
String Gender = "";
String GroupName = "";
String GroupAccountNo = "";
String IdentificationID = "";
String IdentificationType = null;
String CreatedBy = null;
String Residence = "";
private int notificationIdOne = 111;
private int numMessagesOne = 0;
private NotificationManager myNotificationManager;
String account_statusY = "True";
private ProgressDialog prgDialog;
private ArrayAdapter<String> listAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sync_members);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeActionContentDescription("Services");
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#5A92F7")));
lstView = (ListView) findViewById(R.id.lstSample);
submit = (Button) findViewById(R.id.upload);
prgDialog = new ProgressDialog(this);
prgDialog.setMessage("Please wait...");
prgDialog.setCancelable(false);
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
if (isNetworkAvailable(getApplicationContext())) {
new HttpAsyncTask().execute(FirstName, SecondName, MobileNumber, DateofBirth, Gender, GroupName, GroupAccountNo, IdentificationID, IdentificationType, CreatedBy, Residence);
} else {
showAlert("No internet Connectivity...");
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_sync_members, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public class MemberRecords {
String FirstName;
String SecondName;
String MobileNumber;
String DateofBirth;
String Gender;
String GroupName;
String GroupAccountNo;
String IdentificationID;
String IdentificationType;
String CreatedBy;
String Residence;
public String getFirstName() {
return FirstName;
}
public String getSecondName() {
return SecondName;
}
public String getMobileNumber() {
return MobileNumber;
}
public String getDateofBirth() {
return DateofBirth;
}
public String getGender() {
return Gender;
}
public String getGroupName() {
return GroupName;
}
public String getGroupAccountNo() {
return GroupAccountNo;
}
public String getIdentificationID() {
return IdentificationID;
}
public String getIdentificationType() {
return IdentificationType;
}
public String getCreatedBy() {
return CreatedBy;
}
public String getResidence() {
return Residence;
}
public void setFirstName(String newfirstName) {
FirstName = newfirstName;
}
public void setSecondName(String newSecondName) {
SecondName = newSecondName;
}
public void setMobileNumber(String mobileNumber) {
MobileNumber = mobileNumber;
}
public void setDateofBirth(String dateofBirth) {
DateofBirth = dateofBirth;
}
public void setGender(String gender) {
Gender = gender;
}
public void setGroupName(String groupName) {
GroupName = groupName;
}
public void setGroupAccountNo(String groupAccountNo) {
GroupAccountNo = groupAccountNo;
}
public void setIdentificationID(String identificationID) {
IdentificationID = identificationID;
}
public void setIdentificationType(String identificationType) {
IdentificationType = identificationType;
}
public void setCreatedBy(String createdBy) {
CreatedBy = createdBy;
}
public void setResidence(String residence) {
Residence = residence;
}
}
public boolean isConnected() {
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected())
return true;
else
return false;
}
public static String POST(String url, MemberRecords my) {
InputStream inputStream;
String result = "";
String username = "atlantis";
String password = "#t1#ntis";
Integer n;
try {
// 1. create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// 2. make POST request to the given URL
HttpPost httpPost = new HttpPost("http://41.186.47.26:4433/Api/Account/PostAddSignatory");
String json = "";
Log.e("Url", "Url Here:" + url);
// 3. build jsonObject
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("FirstName", my.getFirstName());
jsonObject.accumulate("SecondName", my.getSecondName());
jsonObject.accumulate("MobileNumber", my.getMobileNumber());
jsonObject.accumulate("DateofBirth", my.getDateofBirth());
jsonObject.accumulate("Gender", my.getGender());
jsonObject.accumulate("GroupName", my.getGroupName());
jsonObject.accumulate("GroupAccountNo", my.getGroupAccountNo());
jsonObject.accumulate("IdentificationID", my.getIdentificationID());
jsonObject.accumulate("IdentificationType", my.getIdentificationType());
jsonObject.accumulate("CreatedBy", my.getCreatedBy());
jsonObject.accumulate("Residence", my.getResidence());
json = jsonObject.toString();
Log.e("Url", "Request:" + json);
StringEntity se = new StringEntity(json);
httpPost.setHeader(HTTP.CONTENT_TYPE, "application/json");
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
Header header = new BasicScheme().authenticate(credentials, httpPost);
httpPost.addHeader(header);
httpPost.setEntity(se);
HttpResponse httpResponse = httpclient.execute(httpPost);
inputStream = httpResponse.getEntity().getContent();
if (inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
} catch (Exception e) {
Log.e("InputStream", e.getLocalizedMessage());
//e.printStackTrace();
}
// 11. return result
return result;
}
private static String convertInputStreamToString(InputStream inputStream) throws IOException, JSONException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = "";
String result = "";
while ((line = bufferedReader.readLine()) != null)
result += line;
Log.e("Url", "Response:" + result);
inputStream.close();
return result;
}
private class HttpAsyncTask extends AsyncTask<String, Void,String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
prgDialog.show();
}
#Override
protected String doInBackground(String... urls) {
dbs = new MainDB(SyncMembersActivity.this);
db = dbs.getWritableDatabase();
Integer n=null;
MemberRecords my = new MemberRecords();
List<MemberRecords> member_list = new ArrayList<>();
try {
Cursor cursor = db.rawQuery("SELECT * FROM tbl_memberData" +
" where sync_status = '" + statusN + "' AND account_status = '" + account_statusY + "'", null);
if (cursor.moveToFirst()) {
do {
my = new MemberRecords();
my.setGroupName(cursor.getString(1));
my.setIdentificationID(cursor.getString(2));
my.setIdentificationType(cursor.getString(3));
my.setFirstName(cursor.getString(4));
my.setSecondName(cursor.getString(5));
my.setDateofBirth(cursor.getString(6));
my.setMobileNumber(cursor.getString(7));
my.setGender(cursor.getString(8));
my.setGroupAccountNo(cursor.getString(9));
my.setCreatedBy(cursor.getString(10));
my.setResidence(cursor.getString(11));
member_list.add(my);
} while (cursor.moveToNext());
}
cursor.close();
} catch (NumberFormatException e) {
e.printStackTrace();
}
for ( n = 0; n < member_list.size(); n++) {
POST(url, member_list.get(n));
}
db.close();
return String.valueOf(member_list);
}
//onPostExecute displays the results of the AsyncTask.
//Response format
//Response:{"ResponseCode":"00","ResponseMsg":"Successful"}
//Response:{"ResponseCode":"01","ResponseMsg":"Failed"}
#Override
protected void onPostExecute (String result){
prgDialog.dismiss();
Toast.makeText(getBaseContext(),"Saved Successfully",Toast.LENGTH_LONG).show();
dbs = new MainDB(SyncMembersActivity.this);
db = dbs.getWritableDatabase();
String updateQuery = "Update tbl_memberData set sync_status = '" + statusY + "' where account_status='" + account_statusY + "'";
db.execSQL(updateQuery);
String success="";
String message="";
try {
JSONObject jsonBreaker = new JSONObject(result);
success = jsonBreaker.getString("ResponseCode");
message = jsonBreaker.getString("ResponseMsg");
if (success.equalsIgnoreCase("00")) {
prgDialog.dismiss();
showAlert(message);
} else if (success.equalsIgnoreCase("01")) {
prgDialog.dismiss();
//do
showAlert(message);
} else {
prgDialog.dismiss();
Toast.makeText(getBaseContext(), "Error, Please try again...", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
private void showAlert(String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message).setTitle("Response from Server")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do nothing
}
});
AlertDialog alert = builder.create();
alert.show();
}
public boolean isNetworkAvailable(final Context context) {
final ConnectivityManager connectivityManager = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
return connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isConnected();
}
}
If you would baste stacktrace and opoint where rxception is thrown would be much easier.
Anyway
Your result is probably and JSONArray not an JSONObject so this
JSONObject jsonBreaker = new JSONObject(result);
Is causing the exception. Construct JSONArray insteed of JSONObject and this shoult be fine (this is my blind guess cuz no viable info here)

How to retrieve data from mysql database from what is the input on my textfield

For example I have entered my pin to 123 in my text field I want that program to Show the balance, card number and account number of that certain pin
i used setters and getters to get the pin from the previous frame (login)
Here is my code
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.event.*;
import java.sql.*;
import javax.swing.table.*;
public class Test extends JFrame
{
private static final Test sh1 = new Test();
public static Test getInstance()
{
return sh1;
}
Container c;
Connection con;
Statement st;
ResultSet rs;
ResultSetMetaData rm;
JTable tb;
JButton btnback = new JButton("Back");
JTextField pin = new JTextField("");
public void setUser(String user) {this.pin.setText(user);}
public String getUser() {return this.pin.getText();}
public Test(){
this.setTitle("Data");
this.setSize(500,500);
this.setLocation(800, 80);
this.setBackground(Color.black);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c=this.getContentPane();
c.setLayout(new FlowLayout());
c.add(btnback);
c.add(pin);
stud();
}
public void stud()
{
Vector ColName = new Vector();
Vector Data = new Vector();
try{
String driver="com.mysql.jdbc.Driver";
String db="jdbc:mysql://localhost:3306/atm";
String user="root";
String pass="";
Class.forName(driver);
con=DriverManager.getConnection(db,user,pass);
st=con.createStatement();
String pincodee = pin.getText().trim();
String sqltb = "Select balance,cardnumber , accountnumber from accounts WHERE "
+ "pincode = '"+pincodee+"' ";
rs = st.executeQuery(sqltb);
rm = rs.getMetaData();
int col = rm.getColumnCount();
for(int i = 1; i <= col; i++)
{
ColName.addElement(rm.getColumnName(i));
}
while(rs.next())
{
Vector row = new Vector(col);
for(int i = 1; i <= col; i++)
{
row.addElement(rs.getObject(i));
String s = rs.getString(2);
pin.setText(s);
}
Data.addElement(row);
}
}
catch (Exception ex)
{
}
tb = new JTable( Data, ColName);
tb.repaint();
JScrollPane sc = new JScrollPane(tb);
sc.validate();
c.add(sc);
}
public static void main(String[] args)
{
Test s = new Test();
s.setVisible(true);
}
}
You need to create a button which says 'Go!' or something like that and add an action listener to it that calls your stud() method.
look here for example..
http://www.javaprogrammingforums.com/java-swing-tutorials/278-how-add-actionlistener-jbutton-swing.html
Your code is not going to work either way, you need to rewrite a great deal of it but the ActionListener class is your friend if you want actions on the user interface to call logic code.

Converting MapWritable to a string in Hadoop

When I run my output with the toString() method I am getting:
#zombie org.apache.hadoop.io.MapWritable#b779f586
#zombies org.apache.hadoop.io.MapWritable#c8008ef9
#zona org.apache.hadoop.io.MapWritable#99e061a1
#zoology org.apache.hadoop.io.MapWritable#9d0060be
#zzp org.apache.hadoop.io.MapWritable#3e52c108
Here is my reducer code, how can I get the map values to print out instead?
package sample;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.MapWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.Reducer;
public class IntSumReducer
extends Reducer<Text,MapWritable,Text,MapWritable> {
private MapWritable result = new MapWritable();
String temp = "";
public void reduce(Text key, Iterable<MapWritable> values, Context context)throws IOException, InterruptedException {
result.clear();
for (MapWritable val : values) {
Iterable<Writable> keys = val.keySet();
for (Writable k : keys) {
IntWritable tally = (IntWritable) val.get(k);
if (result.containsKey(k)) {
IntWritable tallies = (IntWritable) result.get(k);
tallies.set(tallies.get() + tally.get());
temp = toString() + " : " + tallies.get();
result.put(new Text(temp), tallies);
} else {
temp = k.toString() + " : " + tally.get();
result.put(new Text(temp), tally);
}
}
}
context.write(key, result);
}
}
Thanks for the help
Adding a class like this should work:
class MyMapWritable extends MapWritable {
#Override
public String toString() {
StringBuilder result = new StringBuilder();
Set<Writable> keySet = this.keySet();
for (Object key : keySet) {
result.append("{" + key.toString() + " = " + this.get(key) + "}");
}
return result.toString();
}
}
Then call it like so:
MyMapWritable mw = new MyMapWritable();
mw.toString();
Your result is a MapWritable, and the toString() method is not overridden in MapWritable.
You can create new class that extends MapWritable and create your own toString() method in it.
Change your code after that to :
public class IntSumReducer extends Reducer<Text,MapWritable,Text,YourMapWritable> {
private YourMapWritable result = new YourMapWritable();
String temp = "";
...

JDBC database java using vector of vectors

Does someone can help my by creating an database query with vectors?
I want to query the Lieferranten Table of the nordwind database and showing it on a JTable.
My problem is how to show data sets in the jTable1?
This is my previous code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.sql.*;
import java.util.*;
public class Anzeige extends JFrame {
private JTable jTable1 = new JTable(5, 5);
private DefaultTableModel jTable1Model = (DefaultTableModel) jTable1.getModel();
private JScrollPane jTable1ScrollPane = new JScrollPane(jTable1);
public Anzeige (String title) {
super (title);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int frameWidth = 676;
int frameHeight = 467;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
jTable1ScrollPane.setBounds(72, 56, 521, 289);
jTable1.getColumnModel().getColumn(0).setHeaderValue("Title 1");
jTable1.getColumnModel().getColumn(1).setHeaderValue("Title 2");
jTable1.getColumnModel().getColumn(2).setHeaderValue("Title 3");
jTable1.getColumnModel().getColumn(3).setHeaderValue("Title 4");
jTable1.getColumnModel().getColumn(4).setHeaderValue("Title 5");
cp.add(jTable1ScrollPane);
// Ende Komponenten
setResizable(false);
setVisible(true);
}
public static void main(String[] args) {
new Anzeige("Anzeige");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection dbConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/nordwind", "root", "");
Statement statement = dbConn.createStatement();
ResultSet results = statement.executeQuery("SELECT * FROM Lieferranten");
Vector vector = new Vector();
while (results.next()) {
String s1 = results.getString(2);
String s2 = results.getString(5);
System.out.println(s1 + "\n" + s2);
System.out.println(results.getString(2) + " " + results.getString(5));
Vector data = new Vector();
data.add(results.getString(1));
data.add(results.getString(2));
vector.add(data);
}
//results.close();
statement.close();
dbConn.close();
}
catch (InstantiationException e) {
System.err.println("Error in Instantiation!");
}
catch (ClassNotFoundException e) {
System.err.println("Class not found!");
}
catch (IllegalAccessException e) {
System.err.println("Access denied!");
}
catch (SQLException e) {
System.err.println("SQL Error!");
}
}
}
I assume that you will get five column values as you had added five column titles. After that use addRow(java.util.Vector) method of DefaultTableModel to insert row in jTable1.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.sql.*;
import java.util.*;
public class Anzeige extends JFrame {
private JTable jTable1 = new JTable(5, 5);
private DefaultTableModel jTable1Model = (DefaultTableModel) jTable1.getModel();
private JScrollPane jTable1ScrollPane = new JScrollPane(jTable1);
public Anzeige (String title) {
super (title);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int frameWidth = 676;
int frameHeight = 467;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
jTable1ScrollPane.setBounds(72, 56, 521, 289);
jTable1.getColumnModel().getColumn(0).setHeaderValue("Title 1");
jTable1.getColumnModel().getColumn(1).setHeaderValue("Title 2");
jTable1.getColumnModel().getColumn(2).setHeaderValue("Title 3");
jTable1.getColumnModel().getColumn(3).setHeaderValue("Title 4");
jTable1.getColumnModel().getColumn(4).setHeaderValue("Title 5");
cp.add(jTable1ScrollPane);
// Ende Komponenten
setResizable(false);
setVisible(true);
}
public static void main(String[] args) {
new Anzeige("Anzeige");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection dbConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/nordwind", "root", "");
Statement statement = dbConn.createStatement();
ResultSet results = statement.executeQuery("SELECT * FROM Lieferranten");
while (results.next()) {
String s1 = results.getString(2);
String s2 = results.getString(5);
System.out.println(s1 + "\n" + s2);
System.out.println(results.getString(2) + " " + results.getString(5));
Vector data = new Vector();
data.add(results.getString(1));
data.add(results.getString(2));
data.add(results.getString(3));
data.add(results.getString(4));
data.add(results.getString(5));
jTable1Model.addRow(data);
}
//results.close();
statement.close();
dbConn.close();
}
catch (InstantiationException e) {
System.err.println("Error in Instantiation!");
}
catch (ClassNotFoundException e) {
System.err.println("Class not found!");
}
catch (IllegalAccessException e) {
System.err.println("Access denied!");
}
catch (SQLException e) {
System.err.println("SQL Error!");
}
}
}

Error with JSF+Spring+hibernate

I am trying to integrate the JSF with spring and hibernate.
Following is my code:
LeaveBean.java
package com.nagra.bean;
import java.io.Serializable;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import javax.annotation.Resource;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.hibernate.HibernateException;
import com.nagra.leaveapp.BO.LeaveInfoBo;
import com.nagra.leaveapp.model.LeaveInfo;
#ManagedBean(name="customer")
#SessionScoped
public class LeaveBean implements Serializable{
/**
*
*/
//private LeaveAppDo leaveAppDo=new LeaveAppDo();
LeaveInfoBo leaveinfoBo;
public LeaveInfoBo getLeaveinfoBo() {
return leaveinfoBo;
}
public void setLeaveinfoBo(LeaveInfoBo leaveinfoBo) {
this.leaveinfoBo = leaveinfoBo;
}
private String total_sick_leave;
private String total_paidoff_leave;
private String start_date;
private String end_date;
private String reason;
private String status;
private Date secondDate;
public Date getSecondDate() {
return secondDate;
}
public void setSecondDate(Date secondDate) {
this.secondDate = secondDate;
}
public String getTotal_sick_leave() {
return total_sick_leave;
}
public void setTotal_sick_leave(String total_sick_leave) {
this.total_sick_leave = total_sick_leave;
}
public String getTotal_paidoff_leave() {
return total_paidoff_leave;
}
public void setTotal_paidoff_leave(String total_paidoff_leave) {
this.total_paidoff_leave = total_paidoff_leave;
}
public String getStart_date() {
return start_date;
}
public void setStart_date(String start_date) {
this.start_date = start_date;
}
public String getEnd_date() {
return end_date;
}
public void setEnd_date(String end_date) {
this.end_date = end_date;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
private static final long serialVersionUID = 1L;
//resource injection
#Resource(name="jdbc/leaveapp")
//private DataSource ds;
//if resource inject is not support, you still can get it manually.
/*public CustomerBean(){
try {
Context ctx = new InitialContext();
ds = (DataSource)ctx.lookup("jdbc:mysql://localhost:3306/leaveapp");
} catch (NamingException e) {
e.printStackTrace();
}
}*/
public List<LeaveInfo> getCustomerList() throws SQLException{
System.out.println("Getting In " );
return null;
// return leaveinfoBo.retrieveData();
}
public String addCustomer() throws HibernateException
{
/* String url = "jdbc:mysql://localhost:3306/leaveapp";
Connection con = DriverManager.getConnection(url,"root","root");
System.out.println(con);
if(con==null)
throw new SQLException("Can't get database connection");
String sql="insert into leaveinformation(start_date,end_date,reason,status)values(?,?,?,?)";
java.util.Date utilDate = new Date();
// Convert it to java.sql.Date
java.sql.Date date = new java.sql.Date(utilDate.getTime());
java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime());*/
DateFormat formatter ;
try
{
System.out.println("Start date " + getStart_date());
formatter = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = formatter.parse(LeaveBean.this.getStart_date());
System.out.println(startDate);
Date endDate = formatter.parse(LeaveBean.this.getEnd_date());
// Days d = Days.daysBetween(startDate,endDate);
// int days = d.getDays();
#SuppressWarnings("deprecation")
java.sql.Date startdate=new java.sql.Date(startDate.getDate());
#SuppressWarnings("deprecation")
java.sql.Date enddate=new java.sql.Date(endDate.getDate());
/* System.out.println("Today is " +date );
PreparedStatement ps
= con.prepareStatement(sql);
ps.setDate(1,startdate,Calendar.getInstance(Locale.ENGLISH));
ps.setDate(2,enddate,Calendar.getInstance(Locale.ENGLISH));
ps.setString(3,CustomerBean.this.reason);
ps.setString(4,"Waiting");*/
LeaveInfo leave = new LeaveInfo();
System.out.println("Entering addCustomer() ");
leave.setEnd_date(enddate);
leave.setStart_date(startdate);
leave.setReason(reason);
leave.setStatus("Waiting");
System.out.println(leave.toString());
leaveinfoBo.save(leave);
clearall();
// Insert the row
/* ps.executeUpdate();
con.close();*/
sendmail();
}
catch(Exception e)
{
System.out.println("There is an error " + e.getStackTrace().toString());
e.printStackTrace();
}
return "";
}
private void clearall() {
// TODO Auto-generated method stub
setEnd_date("");
setStart_date("");
setReason("");
setStatus("");
}
public String sendmail()
{
// Recipient's email ID needs to be mentioned.
String to = "nsbharathi88#gmail.com";
// Sender's email ID needs to be mentioned
String from = "web#gmail.com";
// Assuming you are sending email from localhost
String host = "localhost";
// Get system properties
Properties properties = System.getProperties();
// Setup mail server
properties.setProperty("mail.smtp.host", host);
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
try{
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set Subject: header field
message.setSubject("This is the Subject Line!");
// Now set the actual message
message.setText("This is actual message");
// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
return "";
}
}
applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- Database Configuration -->
<import resource="classes/spring/database/DataSource.xml"/>
<import resource="classes/spring/database/Hibernate.xml"/>
<!-- Beans Declaration -->
<import resource="classes/spring/bean/LeaveApp.xml"/>
</beans>
I am getting the following error when i run this on the tomcat server:
Start date 2012-02-03
java.lang.NullPointerException
at com.nagra.bean.LeaveBean.addCustomer(LeaveBean.java:167)
Fri Feb 03 00:00:00 IST 2012
Entering addCustomer()
LeaveInfo [id=0, total_sick_leave=15, total_paidoff_leave=15, start_date=1970-01- 01, end_date=1970-01-01, reason=cfklsn, status=Waiting]
There is an error [Ljava.lang.StackTraceElement;#fc644a
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
I think, your startdate and enddate is of type String, Change it to java.util.Date and try
start_date=1970-01- 01
Your start date has a space in it. It wont parse.

Resources