Posts

Showing posts from 2014

How to solve Gradle project sync failed error in Android Studio

Image
Before Android Studio I was using MotoDev an android IDE by Motorola. But, I found Android Studio which was developed on IDEA. Whenever we create a new project using Android Studio it develops on Gradle. A very common problem with Gradle that if we don't have internet then it fails building your project and gives an exception:   Gradle project sync failed error This error caused because it always try to find libraries over Internet and when it fails to find the dependencies then it fails. So, in order to execute you project offline you must need to fix this project setup. Click on Invalidate Caches/Restart from the File Menu Click on Invalidate and Restart Let it download all the Gradle stuff it needs once, Gradle build success ! Rebuild project. After successful build of the project you may able to build your project offline.

Read Multiple Rows from Android SQLite Helper

This blog is in continuity with my previous three posts which were related to creation of a database helper class , insertion of new data entry intothe table and selection of a record from the database . After creating database in android and open the connection we had to add entries into the database. And after that we have seen how to select a single record from the database. But now it's time to move to more advance level of retrieving records from the table. And now we must need to select multiple records from the table and populate it to the collection of POJO. ( PreferenceInfo.java ) In order to retrieve a stored record into database we had to provide an identity value which will search the record into table against that id. But, here we are planning to search all the records from the database. A List is a collection which maintains an ordering for its elements. Every element in the List has an index. Each element can thus be accessed by its index, with the...

Read One Record from SQLite Android Helper

This blog is in continuity with my previous two posts which was related to creation of a database helper class and insertion of new data entry into the table . After creating database in android and open the connection we had to add entries into the database. But, as we are already done with the insertion of records into the table. So, now it's time to search for the added record. So, here we will use  PreferenceInfo  POJO for assigning retrieved values to the object. in order to retrieve a stored record into database we must need to provide an identity value which will search the record into table against that id. public PreferenceInfo getUser(int id){ As I have already mentioned in my previous two blogs; we must need to get a readabledatabase object because here we only need to read a database. SQLiteDatabase db=null; // 1. get reference to readable DB try{ db = this.getReadableDatabase(); }catch (Exception e){ Toast.makeText(currentContext, "database...

Insert new record into SQLite Database Android

This blog is in continuity with my previous post which was related to creation of a database helper class. After creating database in android and open the connection we need to add entries into the database. But before that we just need to create a POJO (Plain Old Java Object) for the table so that we can store the values and directly send it to the database. POJO of PreferenceInfo can be downloaded from this link. ( PreferenceInfo.java ) In order to add a new entry into the database we get a SQLiteDatabase writable instance by adding following line SQLiteDatabase db = this.getWritableDatabase(); After getting the database we must need to set the values that we need to persist into the database to sepecific column name: ContentValues newValues = new ContentValues(); newValues.put(E_MAIL, preferenceInfo.getEmail()); newValues.put(PASSWORD, preferenceInfo.getPassword()); newValues.put(USER_NAME, preferenceInfo.getUserName()); newValues.put(MOBILE_NUMBER, prefer...

Android Database Helper

For every android application we mostly need to create a data layer which keeps the parametric data and some user related settings persisted. But it's not equivalent to the actual data layer that we have in our desktop based or web based application where we have an external database server. Because we can't keep such a huge application on our mobile devices. In order to access stored data into our application, we can try two different approaches, one is to keep the data into a database server and access it via web service. But, for some user related settings why do we need such hassle. Because we don't need to access internet all the time in order to retrieve some basic user related information. So we will go for second approach which is to store a file on our local device and access it directly. But, we want to make a structure in order to retrieve data and store data in some generic form. Yes, just like we do in databases. So, here in andorid SQLLite is a ...

Maven + Struts2 + Spring + Hibernate + Struts2-Convention-Plugin + Hibernate Search

Image
This blog is in continuation with one of my previous blog  maven+struts2+spring+hibernate+struts2 connvention plugin . So, you must need to open this post in order to get better understanding by sample code. First question raises up in mind that why do we need 'hibernate search' when we have 'hibernate' already in our application. But HibernateSearch is completley different from hibernate. As hibernateSearch is giving a capability of indexing in your application by using Lucene. And instead of adding too many line of code in order to integrate lucene with your application. You can simply integrate hibernatesearch with your application and rest will be taken care by this. In lucene the major problem we face is to merge indexes. But, in HibernateSearch after each transaction indexes get updated automatically. Few things must need to consider before jumping into code.  HibernateSearch never replace the existing index, once it created then it will be keep on...