Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8674511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:43:42+00:00 2026-06-12T19:43:42+00:00

I want to store some data when mobile is not in covered area. and

  • 0

I want to store some data when mobile is not in covered area. and when service came back it will upload data on the server. but data is not inserting. i`ve checked many tutorail on net. but same all the time. app close unexpecdately.

LogCat error

        10-12 12:08:54.754: E/Service Example(1374): Service Started.. 
        10-12 12:08:54.814: E/AndroidRuntime(1374): FATAL EXCEPTION: main
        10-12 12:08:54.814: E/AndroidRuntime(1374): java.lang.RuntimeException: Unable    create service com.remote.synchronizer.haris.OfflineDataService:  java.lang.NullPointerException
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:1955)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at android.app.ActivityThread.access$2500(ActivityThread.java:117)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at android.os.Handler.dispatchMessage(Handler.java:99)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at android.os.Looper.loop(Looper.java:123)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at android.app.ActivityThread.main(ActivityThread.java:3683)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at java.lang.reflect.Method.invokeNative(Native Method)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at java.lang.reflect.Method.invoke(Method.java:507)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at dalvik.system.NativeStart.main(Native Method)
        10-12 12:08:54.814: E/AndroidRuntime(1374): Caused by: java.lang.NullPointerException
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at com.remote.synchronizer.haris.SQLiteAdapter.Write(SQLiteAdapter.java:59)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at com.remote.synchronizer.haris.OfflineDataService.onCreate(OfflineDataService.java:37)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:1945)
        10-12 12:08:54.814: E/AndroidRuntime(1374):     ... 10 more

SQLiteAdapter

    package com.remote.synchronizer.haris;

    import java.util.ArrayList;
    import java.util.List;
    import org.apache.http.NameValuePair;
    import org.apache.http.message.BasicNameValuePair;

    import android.content.ContentValues;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.util.Log;

    public class SQLiteAdapter extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "Product";
    public static final String TABLE_NAME = "Order";
    public static final int DATABASE_VERSION = 1;
    public static final String KEY_ID = "_id";  
    public static final String KEY_NAME = "name";
    public static final String KEY_SHOP = "shop";
    private static final String KEY_CITY = "city";
    private static final String KEY_DATE = "date";
    private static final String KEY_ORDER = "order";


    private static final String CREATE_TABLE =
        "CREATE TABLE " + TABLE_NAME + " ("
        + KEY_ID + " integer primary key autoincrement, "
        + KEY_NAME + " VARCHAR,"
        + KEY_SHOP + " VARCHAR," + KEY_CITY + " VARCHAR, " + KEY_DATE + " VARCHAR, " + KEY_ORDER + " VARCHAR " + ");";


    public SQLiteAdapter(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);  
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE);   
    }

    private SQLiteDatabase sqLiteDatabase;
    private SQLiteAdapter sqLiteHelper;

    /*private Context context;

    public SQLiteAdapter(Context c){
        context = c;
    }
    */
    public void Read() throws android.database.SQLException {
        sqLiteDatabase = sqLiteHelper.getReadableDatabase();        
    }

    public void Write() throws android.database.SQLException {
        sqLiteDatabase = sqLiteHelper.getWritableDatabase();    
    }

    public void close(){
        sqLiteHelper.close();
    }

    public long insert(String name, String shop, String city, String date, String order){

        ContentValues contentValues = new ContentValues();
        contentValues.put(KEY_NAME, name);
        contentValues.put(KEY_SHOP, shop);
        contentValues.put(KEY_SHOP, city);
        contentValues.put(KEY_DATE, date);
        contentValues.put(KEY_ORDER, order);
        return sqLiteDatabase.insert(TABLE_NAME, null, contentValues);
    }

    public int deleteAll(){
        return sqLiteDatabase.delete(TABLE_NAME, null, null);
    }

    /*public void delete_byID(int id){
        sqLiteDatabase.delete(TABLE_NAME, KEY_ID+"="+id, null);
    }

    public Cursor queueAll(){
        String[] columns = new String[]{KEY_ID, KEY_NAME, KEY_SHOP, KEY_CITY,  KEY_DATE, KEY_ORDER};
        Cursor cursor = sqLiteDatabase.query(TABLE_NAME, columns, 
                null, null, null, null, null);

        return cursor;
    }*/

    public List<NameValuePair> getAllContacts() {
        List<NameValuePair> postParameters = new ArrayList<NameValuePair>();

        String selectQuery = "SELECT  * FROM " + TABLE_NAME;
        Read();
        Cursor cursor = sqLiteDatabase.rawQuery(selectQuery, null);

        if(cursor.moveToFirst()){
            while(!cursor.isAfterLast())
            {
                postParameters.add(new BasicNameValuePair("User", cursor.getString(cursor.getColumnIndex(KEY_NAME))));
                postParameters.add(new BasicNameValuePair("ShopName", cursor.getString(cursor.getColumnIndex(KEY_SHOP))));
                postParameters.add(new BasicNameValuePair("city", cursor.getString(cursor.getColumnIndex(KEY_CITY))));
                postParameters.add(new BasicNameValuePair("OrderDate", cursor.getString(cursor.getColumnIndex(KEY_DATE))));
                postParameters.add(new BasicNameValuePair("OrderDetail", cursor.getString(cursor.getColumnIndex(KEY_ORDER))));
                cursor.moveToNext();
            }

        }
        cursor.close();
        return postParameters;

    };



    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w(SQLiteAdapter.class.getName(),
                "Upgrading database from version " + oldVersion + " to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS " + CREATE_TABLE);
            onCreate(db);
    }

}

OfflineDataService.java

    package com.remote.synchronizer.haris;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Timer;
    import java.util.TimerTask;
    import org.apache.http.NameValuePair;

    import android.app.IntentService;
    import android.content.Intent;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.Toast;

    public class OfflineDataService extends IntentService {

    boolean wifi,edge;
    private Timer timer= new Timer();
    SQLiteDatabase db;
    String un,shop,city,date,order;
    private SQLiteAdapter mySQLiteAdapter;
    Cursor cursor;

    public OfflineDataService() {
        super("OfflineDataService");
    }

    @Override   
    public void onCreate() {

        super.onCreate();
        Log.e("Service Example", "Service Started.. ");

         mySQLiteAdapter = new SQLiteAdapter(this);
         mySQLiteAdapter.Write();

}   

    @Override
    protected void onHandleIntent(Intent intent) {

        Bundle bundle=intent.getExtras();
        un=bundle.getString("un");
        shop=bundle.getString("shop");
        city=bundle.getString("city");
        date=bundle.getString("date");
        order=bundle.getString("order");

        Log.e("Service Started", "Successful");

        //Inserting New Record
        mySQLiteAdapter.insert(un,shop,city,date,order);


        timer.scheduleAtFixedRate(new TimerTask(){

            @Override
            public void run() {

                //Checking network connectivity
                   wifi=NetworkInfo.Wifi(OfflineDataService.this);
                   edge=NetworkInfo.EDGE(OfflineDataService.this);

                       if(wifi==true||edge==true)
                       {
                           DataSender();
                       }
                       else
                       {
                           //Toast toast=Toast.makeText(getApplicationContext(), "Testing", toast.LENGTH_LONG).show();
                       }
            }

        }, 1000, 5000);


    }

    /*@Override
    public void onDestroy() {

        super.onDestroy();
        Log.e("Service Example", "Service Destroyed.. ");
        mySQLiteAdapter.deleteAll();


    }*/

    private void DataSender()
    {
        timer.cancel();

        List<NameValuePair> contacts=new ArrayList<NameValuePair>();

        contacts=mySQLiteAdapter.getAllContacts();

         String url="http://10.0.2.2:3325/Product/Create?"; 

         int response = 0;

            try 
            {
                response = CustomHttpClient.executeHttpPost(url, contacts);

                if(response==200)
                {
                    //notification
                }

                else{}
                    //error.setText("Sorry!! Try again later.\n Response Code: "+ response);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            //  error.setText(e.toString());
            }
    }

}

What’s wrong with my code?

New Error in log cat

10-12 14:57:00.424: E/Service Example(1494): Service Started.. 
10-12 14:57:00.664: E/Database(1494): Failure 1 (near "Order": syntax error) on 0x5b7638 when preparing 'CREATE TABLE Order (_id integer primary key autoincrement, name VARCHAR,shop VARCHAR,city VARCHAR, date VARCHAR, order VARCHAR );'.
10-12 14:57:00.764: E/AndroidRuntime(1494): FATAL EXCEPTION: main
10-12 14:57:00.764: E/AndroidRuntime(1494): java.lang.RuntimeException: Unable to create service com.remote.synchronizer.haris.OfflineDataService: android.database.sqlite.SQLiteException: near "Order": syntax error: CREATE TABLE Order (_id integer primary key autoincrement, name VARCHAR,shop VARCHAR,city VARCHAR, date VARCHAR, order VARCHAR );
10-12 14:57:00.764: E/AndroidRuntime(1494):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:1955)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at android.app.ActivityThread.access$2500(ActivityThread.java:117)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at android.os.Looper.loop(Looper.java:123)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at android.app.ActivityThread.main(ActivityThread.java:3683)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at java.lang.reflect.Method.invokeNative(Native Method)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at java.lang.reflect.Method.invoke(Method.java:507)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at dalvik.system.NativeStart.main(Native Method)
10-12 14:57:00.764: E/AndroidRuntime(1494): Caused by: android.database.sqlite.SQLiteException: near "Order": syntax error: CREATE TABLE Order (_id integer primary key autoincrement, name VARCHAR,shop VARCHAR,city VARCHAR, date VARCHAR, order VARCHAR );
10-12 14:57:00.764: E/AndroidRuntime(1494):     at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1763)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at com.remote.synchronizer.haris.SQLiteAdapter.onCreate(SQLiteAdapter.java:42)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:126)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at com.remote.synchronizer.haris.SQLiteAdapter.Write(SQLiteAdapter.java:59)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at com.remote.synchronizer.haris.OfflineDataService.onCreate(OfflineDataService.java:37)
10-12 14:57:00.764: E/AndroidRuntime(1494):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:1945)
10-12 14:57:00.764: E/AndroidRuntime(1494):     ... 10 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:43:44+00:00Added an answer on June 12, 2026 at 7:43 pm

    You define your sqLiteHelper but never initialize it. This means when this line below (in your Write() method) is run, it causes the NullPointerException shown in logcat.

    sqLiteDatabase = sqLiteHelper.getWritableDatabase();
    

    Change it to…

    sqLiteDatabase = this.getWritableDatabase();
    

    ..or make sure sqLiteHelper is intialized before use.

    NOTE: As it stands, your Read() method will fail in the same way unless you initialize sqLiteHelper or us this instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my application (PHP, but that shouldn't matter) to store some data in
I want to store some data during my site viewing. Sometime i need to
I store some data in MySQL and want to filter out rows that match
I want to temporary store some mapping data. The mapping is one to one.
I want to create a data store to allow me to store some data.
I want to store the average values of some data that is occasionally generated
I want to store some value from SQLite database in my buffer, but the
Greetings, I want to store some data in a redis db and don't know
Suppose I have some data I want to post to a server. You're in
I want to store some data from structures like this: class Project { ChildA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.