Android java object to sqlite

How do I use SQLite in android?

I’ve founde already a few answers to this topic (for example this), but it is not working. I only get the warning, that it cannot resolve the method ‘openOrCreateDatabase(java.lang.String, int, null)’. Here is my sourcecode:

8 Answers 8

SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation.

 public class MySQLiteHelper extends SQLiteOpenHelper < public static final String TABLE_COMMENTS = "comments"; public static final String COLUMN_ID = "_id"; public static final String COLUMN_COMMENT = "comment"; private static final String DATABASE_NAME = "commments.db"; private static final int DATABASE_VERSION = 1; // Database creation sql statement private static final String DATABASE_CREATE = "create table " + TABLE_COMMENTS + "(" + COLUMN_ID + " integer primary key autoincrement, " + COLUMN_COMMENT + " text not null);"; public MySQLiteHelper(Context context) < super(context, DATABASE_NAME, null, DATABASE_VERSION); >@Override public void onCreate(SQLiteDatabase database) < database.execSQL(DATABASE_CREATE); >@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) < Log.w(MySQLiteHelper.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS " + TABLE_COMMENTS); onCreate(db); >> 

As the commenter has given you the example, you will need to create a subclass of SQLiteOpenHelper class and override the onCreate and onUpgrade methods which will create your database and tables. Then you can use the method getReadableDatabase( ) or getWritableDatabase() of this helper class to get copy of a SQLite database. You can execute the queries on this object. The code snippet below demonstrates it.

public class DBAdapter < private SQLiteDatabase database; private Context context; private DatabaseHelper dbHelper; private class DatabaseHelper extends SQLiteOpenHelper < public DatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) < super(context, name, factory, version); >@Override public void onCreate(SQLiteDatabase db) < db.execSQL(CREATE_TABLES_QUERY); >@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) < db.execSQL("DROP TABLE IF EXIST "+TABLE_QUERY); >> public DBAdapter(Context ctx) < this.context = ctx; >public DBAdapter open() throws SQLException < dbHelper = new DatabaseHelper(context, DBNAME, null,DBVERSION); database = dbHelper.getWritableDatabase(); return this; >public Cursor executeQuery() < Cursor result = database.rawQuery(YOUR_QUERY, null); return result; >> 
public class Sqlhelper extends SQLiteOpenHelper < private SQLiteDatabase db; public static final String KEY_ROWID = "_id"; public static final String KEY_FNAME = "firstname"; Sqlhelper DB = null; private static final String DATABASE_NAME = "dbname.db"; private static final int DATABASE_VERSION = 2; public static final String DATABASE_TABLE_NAME = "db"; private static final String DATABASE_TABLE_CREATE = "CREATE TABLE " + DATABASE_TABLE_NAME + "(" + "_id INTEGER PRIMARY KEY AUTOINCREMENT,"+ "firstname TEXT NOT NULL);"; public Sqlhelper(Context context) < super(context, DATABASE_NAME, null, DATABASE_VERSION); >@Override public void onCreate(SQLiteDatabase db) < try< db.execSQL(DATABASE_TABLE_CREATE); Log.d("DATABASE", "Table Was Created"); >catch(Exception e) < e.printStackTrace(); >> public void open() < getWritableDatabase(); >@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)

Create «database» name package and include it

Читайте также:  Menu example in php

Create SQLitHelper name class

import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class SQLitHelper extends SQLiteOpenHelper < public static final String DataBase_Name = "ABC"; public static final int Version = 1; public static final String TblUser = "TblUser"; public static final String TblClassList = "TblClassList"; public static final String TblStudentList = "TblStudentList"; public SQLitHelper(Context context) < super(context, DataBase_Name, null, Version); >@Override public void onCreate(SQLiteDatabase db) < db.execSQL("Create table " + TblUser + "(id INTEGER PRIMARY KEY," + "uid INTEGER," + "fname TEXT," + "lname TEXT," + "email TEXT," + "password TEXT," + "teacher TEXT," + "student TEXT," + "parent TEXT," + "status TEXT," + "landing_page TEXT," + "createdate TEXT," + "birthdate TEXT," + "profilepic TEXT," + "phone TEXT," + "address TEXT," + "gender TEXT," + "age TEXT," + "googleid TEXT," + "facebookid TEXT," + "alert_time TEXT," + "sch_name TEXT,"+ "login_with TEXT,"+ "default_zone TEXT)"); db.execSQL("Create table " + TblClassList + "(id INTEGER PRIMARY KEY," + "cid INTEGER," + "uid INTEGER," + "title TEXT," + "color TEXT," + "startdate TEXT," + "enddate TEXT," + "qrcode TEXT," + "createdate TEXT," + "not_submitted_count TEXT," + "status TEXT," + "extra1 TEXT," + "extra2 TEXT)"); db.execSQL("Create table " + TblStudentList + "(id INTEGER PRIMARY KEY," + "uid INTEGER," + "cid INTEGER," + "fname TEXT," + "lname TEXT," + "email TEXT," + "profilepic TEXT," + "student_name TEXT," + "isleader TEXT," + "add_homework TEXT," + "track_submission TEXT," + "status TEXT," + "edit_homework TEXT," + "del_homework TEXT," + "last_access TEXT)"); >@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) < >> 

Create DataHelper class

import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.util.Log; import java.util.ArrayList; import java.util.HashMap; public class DataHelper < SQLitHelper sqLitHelper; SQLiteDatabase sqLiteDatabase; Context context; final String TAG = "DataHelper"; public DataHelper(Context context) < sqLitHelper = new SQLitHelper(context); this.context = context; sqLiteDatabase = sqLitHelper.getWritableDatabase(); >public void open() < try < sqLiteDatabase = sqLitHelper.getWritableDatabase(); >catch (Exception e) < e.printStackTrace(); >> public void close() < try < sqLiteDatabase.close(); >catch (Exception e) < e.printStackTrace(); >> public void insertUser(HashMap list) < ContentValues values = new ContentValues(); open(); try < for (String str : list.keySet()) values.put(str, list.get(str)); long rowId = sqLiteDatabase.insert(SQLitHelper.TblUser, null, values); >catch (Exception e) < Log.e(TAG, "insertUser " + e.toString()); >finally < close(); >> public void updateUser(HashMap list, int uid) < ContentValues values = new ContentValues(); open(); try < for (String str : list.keySet()) values.put(str, list.get(str)); long rows = sqLiteDatabase.update(SQLitHelper.TblUser, values, "uid=" + uid, null); >catch (Exception e) < Log.e(TAG, "insertUser " + e.toString()); >finally < close(); >> public int getUserRecordCount() < int count = 0; try < open(); Cursor cursor = sqLiteDatabase.rawQuery("Select * from " + SQLitHelper.TblUser, null); count = cursor.getCount(); cursor.close(); >catch (Exception e) < Logger.debugLog(TAG, "userCount : " + e.toString()); >finally < close(); >return count; > public HashMap getUserDetail() < HashMaplist = new HashMap<>(); Cursor cursor = null; try < open(); cursor = sqLiteDatabase.rawQuery("SELECT * FROM " + SQLitHelper.TblUser, null); if (cursor.getColumnCount() >0) < while (cursor.moveToNext()) < list.put("uid", cursor.getString(cursor.getColumnIndex("uid"))); list.put("fname", cursor.getString(cursor.getColumnIndex("fname"))); list.put("lname", cursor.getString(cursor.getColumnIndex("lname"))); list.put("default_zone", cursor.getString(cursor.getColumnIndex("default_zone"))); list.put("teacher", cursor.getString(cursor.getColumnIndex("teacher"))); list.put("student", cursor.getString(cursor.getColumnIndex("student"))); list.put("parent", cursor.getString(cursor.getColumnIndex("parent"))); list.put("email", cursor.getString(cursor.getColumnIndex("email"))); list.put("gender", cursor.getString(cursor.getColumnIndex("gender"))); list.put("birthdate", cursor.getString(cursor.getColumnIndex("birthdate"))); list.put("profilepic", cursor.getString(cursor.getColumnIndex("profilepic"))); list.put("sch_name", cursor.getString(cursor.getColumnIndex("sch_name"))); list.put("login_with", cursor.getString(cursor.getColumnIndex("login_with"))); >> > catch (Exception e) < Logger.debugLog(TAG, "getUserDetail : " + e.toString()); >finally < close(); if (cursor != null) if (!cursor.isClosed()) cursor.close(); >return list; > public boolean deleteUserList() < try < open(); if (sqLiteDatabase.delete(SQLitHelper.TblUser, null, null) >0)< return true; >else < return false; >> catch (Exception e) < Logger.debugLog(TAG, "deleteUserList : " + e.toString()); >finally < close(); >return false; > public boolean insertClassList(MClassList mClassList) < try < open(); ContentValues contentValues = new ContentValues(); contentValues.put("cid", mClassList.getId()); contentValues.put("uid", mClassList.getUid()); contentValues.put("title", mClassList.getTitle()); contentValues.put("color", mClassList.getColor()); contentValues.put("startdate", mClassList.getStartdate()); contentValues.put("enddate", mClassList.getEnddate()); contentValues.put("qrcode", mClassList.getQrcode()); contentValues.put("createdate", mClassList.getCreatedate()); contentValues.put("status", mClassList.getStatus()); contentValues.put("not_submitted_count", mClassList.getNot_sub_count()); long null, contentValues); Logger.debugLog(TAG, "insertClassList : Sus"); return true; >catch (Exception e) < Logger.debugLog(TAG, "insertClassList : " + e.toString()); >finally < close(); >return false; > public ArrayList getClassList() < ArrayListclssArrayList = new ArrayList<>(); Cursor cursor = null; try < open(); String Query = QueryBuilder.classListQuery(); cursor = sqLiteDatabase.rawQuery(Query, null); if (cursor.getColumnCount() >0) < while (cursor.moveToNext()) < MClassList mClassList = new MClassList(); mClassList.setId(cursor.getInt(cursor.getColumnIndex("cid"))); mClassList.setUid(cursor.getInt(cursor.getColumnIndex("uid"))); mClassList.setTitle(cursor.getString(cursor.getColumnIndex("title"))); mClassList.setColor(cursor.getString(cursor.getColumnIndex("color"))); mClassList.setStartdate(cursor.getString(cursor.getColumnIndex("startdate"))); mClassList.setEnddate(cursor.getString(cursor.getColumnIndex("enddate"))); mClassList.setQrcode(cursor.getString(cursor.getColumnIndex("qrcode"))); mClassList.setCreatedate(cursor.getString(cursor.getColumnIndex("createdate"))); mClassList.setStatus(cursor.getString(cursor.getColumnIndex("status"))); mClassList.setNot_sub_count(cursor.getString(cursor.getColumnIndex("not_submitted_count"))); clssArrayList.add(mClassList); >> > catch (Exception e) < Logger.debugLog(TAG, "getClassList : " + e.toString()); >finally < close(); if (cursor != null) if (!cursor.isClosed()) cursor.close(); >return clssArrayList; > public boolean deleteClassList() < try < open(); if (sqLiteDatabase.delete(SQLitHelper.TblClassList, null, null) >0)< return true; >else < return false; >> catch (Exception e) < Logger.debugLog(TAG, "deleteClassList : " + e.toString()); >finally < close(); >return false; > public boolean deleteStudentList() < try < open(); if (sqLiteDatabase.delete(SQLitHelper.TblStudentList, null, null) >0) < return true; >else < return false; >> catch (Exception e) < Logger.debugLog(TAG, "deleteStudentList : " + e.toString()); >finally < close(); >return false; > public void deleteStudent(int cid,int uid) < try < open(); sqLiteDatabase.delete(SQLitHelper.TblStudentList, "uid=" + uid + " AND cid=" + cid, null); >catch (Exception e) < Logger.debugLog(TAG, "deleteStudent : " + e.toString()); >finally < close(); >> > 

Create class QueryBuilder

public class QueryBuilder < public static String teacherABCList(int cid) < Calendar c = Calendar.getInstance(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String formatDate = df.format(c.getTime()).toString(); String Query = "SELECT * FROM " + SQLitHelper.TblTeacherHomeworkAll + " WHERE cid='" + cid + "'" + " AND duedate>= " +"'"+ formatDate+"'" + " ORDER BY duedate DESC "; return Query; > ============================== public static String studentXXXListQuery(int uid,String status) < Calendar c = Calendar.getInstance(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String formatDate = df.format(c.getTime()).toString(); String Query = "SELECT * FROM " + SQLitHelper.TblStudentHomeworkAll + " WHERE uid='" + uid + "'" + " AND status= " +"'"+ status+"'"+" AND isDone='N'" + " ORDER BY duedate DESC "; return Query; >=========================================== public static String studentListQuery(String questionID) < String query = "SELECT * FROM " + SQLitHelper.TblStudentCheckAnswer + " WHERE qid mt24"> 
)" data-controller="se-share-sheet" data-se-share-sheet-title="Share a link to this answer" data-se-share-sheet-subtitle="" data-se-share-sheet-post-type="answer" data-se-share-sheet-social="facebook twitter devto" data-se-share-sheet-location="2" data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f" data-se-share-sheet-license-name="CC BY-SA 3.0" data-s-popover-placement="bottom-start">Share
answered Jan 4, 2018 at 13:00
Add a comment |
0

use below example to create database

 import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; import com.ayconsultancy.sumeshmedicals.SumeshMedicalContext; import com.ayconsultancy.sumeshmedicals.model.PlaceModel; import com.ayconsultancy.sumeshmedicals.utils.Utils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; /** * Created by Admin33 on 16-02-2016. */ public class DBHelper extends SQLiteOpenHelper < static String DATABASE_NAME = "sumesh_medicals"; static int DATABASE_VERSION = 1; static DBHelper dbHelperInstance; static SQLiteDatabase db; public DBHelper(Context context) < super(context, DATABASE_NAME, null, DATABASE_VERSION); >public static DBHelper getInstance() < if (dbHelperInstance == null) < dbHelperInstance = new DBHelper(SumeshMedicalContext.getContext()); >return dbHelperInstance; > @Override public void onCreate(SQLiteDatabase db) < Utils.ShowLogD("in sqlite oncreate"); try < db.execSQL(DBQueries.CREATE_OTC_TABLE); db.execSQL(DBQueries.CREATE_SHOP_DETAILS_TABLE); db.execSQL(DBQueries.CREATE_USER_DETAILS_TABLE); db.execSQL(DBQueries.CREATE_CITY_TABLE); >catch (Exception e) < e.printStackTrace(); >// insertIntoShopDetails(db); // insertIntoOTcPrescrion(db); > public synchronized SQLiteDatabase getDababase() < if (db == null || (db != null && !db.isOpen())) < db = this.getWritableDatabase(); >return db; > public synchronized void close() < super.close(); if (db != null) db.close(); >@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) < >> 

Источник

Saving ArrayList in SQLite database in Android

I've been working with SQLite on android and I would like to add an arraylist to a column in a table, and then fetch the data back as an arraylist. The arraylist is a list of Longs. I've noticed that SQL has an option for storing BLOBS, however it looks like I need to convert the arraylist to a byte[] first before being able to store it as a blob in my SQLite database. If anyone has a solution on how to save arraylists into an SQLite database that would be greatly appreciated. Or is there any other option for saving my array of data, i should consider?

7 Answers 7

ArrayList inputArray=new ArrayList(); 
Gson gson = new Gson(); String inputString= gson.toJson(inputArray); System.out.println("inputString inputString" to save the value of ArrayList in SQLite Database

To retreive:

Get the String from the SQLiteDatabse what you saved and changed into ArrayList type like below: outputarray is a String which is get from SQLiteDatabase for this example.

Type type = new TypeToken>() <>.getType(); ArrayList finalOutputString = gson.fromJson(outputarray, type); 

@Md.ImranChoudhury 'Gson (github.com/google/gson) is a library for converting Java objects to and from JSON using reflection.'

Please forgive me for savagely plagiarizing my previous answer to BLOB vs. VARCHAR for storing arrays in a MySQL table. The other answers over there are also very pertinent.

I think Con's approach is probably better than using java serialization since java's builtin serialization will need additional bytes, and non-java applications will have a harder time dealing with the data.

public static void storeInDB(ArrayList longs) throws IOException, SQLException < ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(bout); for (long l : longs) < dout.writeLong(l); >dout.close(); byte[] asBytes = bout.toByteArray(); PreparedStatement stmt = null; // however you get this. stmt.setBytes(1, asBytes); stmt.executeUpdate(); stmt.close(); > public static ArrayList readFromDB() throws IOException, SQLException < ArrayListlongs = new ArrayList(); ResultSet rs = null; // however you get this. while (rs.next()) < byte[] asBytes = rs.getBytes("myLongs"); ByteArrayInputStream bin = new ByteArrayInputStream(asBytes); DataInputStream din = new DataInputStream(bin); for (int i = 0; i < asBytes.length/8; i++) < longs.add(din.readLong()); >return longs; > > 

Note: If your lists will sometimes contain more than 31 longs (248 bytes), then you'll need to use BLOB. You cannot use BINARY() or VARBINARY() in MySQL. I realize you're asking about SQLite, but in the spirit of completely plagiarizing my previous answer, I will pretend you're asking about MySQL:

mysql> CREATE TABLE t (a VARBINARY(2400)) ; ERROR 1074 (42000): Column length too big for column 'a' (max = 255); use BLOB or TEXT instead 

Источник

Insert JSON data into the SQLite database in android

I want to insert the data from JSON array into the SQLite database. I have created two classes CategoryHelper.java and AndroidJSONParsingActivity.java to get the java response. When I run the code got the exception in databaseHelper.saveCategoryRecord(id,name); My API is working fine and giving me the data. My code is below: CategoryHelper.java

package com.androidhive.jsonparsing; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class CategoryHelper < private static final int DATABASE_VERSION = 2; private static final String DATABASE_NAME = "category.db"; private static final String TABLE_NAME = "tbcategory"; public static final String CATEGORY_COLUMN_ID = "_id"; public static final String CATEGORY_COLUMN_NAME = "name"; Category openHelper; private SQLiteDatabase database; public CategoryHelper(Context context)< openHelper = new Category(context); database = openHelper.getWritableDatabase(); >public void saveCategoryRecord(String id, String name) < ContentValues contentValues = new ContentValues(); contentValues.put(CATEGORY_COLUMN_ID, id); contentValues.put(CATEGORY_COLUMN_NAME, name); database.insert(TABLE_NAME, null, contentValues); >public Cursor getTimeRecordList() < return database.rawQuery("select * from " + TABLE_NAME, null); >private class Category extends SQLiteOpenHelper < public Category(Context context) < // TODO Auto-generated constructor stub super(context, DATABASE_NAME, null, DATABASE_VERSION); >@Override public void onCreate(SQLiteDatabase db) < // TODO Auto-generated method stub db.execSQL("CREATE TABLE " + TABLE_NAME + "( " + CATEGORY_COLUMN_ID + " INTEGER PRIMARY KEY, " + CATEGORY_COLUMN_NAME + " TEXT )" ); >@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) < // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS"+ TABLE_NAME); onCreate(db); >> > 
package com.androidhive.jsonparsing; import java.util.ArrayList; import java.util.HashMap; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.ListActivity; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; public class AndroidJSONParsingActivity extends ListActivity < // url to make request private static String url="API TO GET THE DATA"; // JSON Node names private static final String TAG_CATEGORY = "categories"; private static final String TAG_CATEGORY_ID = "category_id"; private static final String TAG_NAME = "name"; private static final String TAG_IS_ACTIVE = "is_active"; // contacts JSONArray JSONArray contacts = null; private CategoryHelper databaseHelper; //private SQLiteDatabase mydatabase = null; @Override public void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.main); // Hashmap for ListView ArrayList> contactList = new ArrayList>(); // Creating JSON Parser instance JSONParser jParser = new JSONParser(); // getting JSON string from URL JSONObject json = jParser.getJSONFromUrl(url); try < // Getting Array of Contacts contacts = json.getJSONArray(TAG_CATEGORY); // looping through All Contacts for(int i = 0; i < contacts.length(); i++)< JSONObject c = contacts.getJSONObject(i); // Storing each json item in variable String String name = c.getString(TAG_NAME); String is_active = c.getString(TAG_IS_ACTIVE); databaseHelper.saveCategoryRecord(id,name); // creating new HashMap HashMapmap = new HashMap(); // adding each child node to HashMap key => value map.put(TAG_CATEGORY_ID, id); map.put(TAG_NAME, name); map.put(TAG_IS_ACTIVE, is_active); // adding HashList to ArrayList contactList.add(map); > > catch (JSONException e) < e.printStackTrace(); >/** * Updating parsed JSON data into ListView * */ ListAdapter adapter = new SimpleAdapter(this, contactList, R.layout.list_item, new String[] < TAG_NAME, TAG_IS_ACTIVE, TAG_CATEGORY_ID >, new int[] < R.id.name, R.id.email, R.id.mobile >); setListAdapter(adapter); // selecting single ListView item ListView lv = getListView(); // Launching new screen on Selecting Single ListItem lv.setOnItemClickListener(new OnItemClickListener() < @Override public void onItemClick(AdapterViewparent, View view, int position, long id) < // getting values from selected ListItem String name = ((TextView) view.findViewById(R.id.name)).getText().toString(); String cost = ((TextView) view.findViewById(R.id.email)).getText().toString(); String description = ((TextView) view.findViewById(R.id.mobile)).getText().toString(); // Starting new intent Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class); in.putExtra(TAG_NAME, name); in.putExtra(TAG_IS_ACTIVE, cost); in.putExtra(TAG_CATEGORY_ID, description); startActivity(in); >>); > > 
01-21 20:13:49.226: E/AndroidRuntime(301): FATAL EXCEPTION: main 01-21 20:13:49.226: E/AndroidRuntime(301): java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.NullPointerException 01-21 20:13:49.226: E/AndroidRuntime(301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 01-21 20:13:49.226: E/AndroidRuntime(301): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 01-21 20:13:49.226: E/AndroidRuntime(301): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 01-21 20:13:49.226: E/AndroidRuntime(301): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 01-21 20:13:49.226: E/AndroidRuntime(301): at android.os.Handler.dispatchMessage(Handler.java:99) 01-21 20:13:49.226: E/AndroidRuntime(301): at android.os.Looper.loop(Looper.java:123) 01-21 20:13:49.226: E/AndroidRuntime(301): at android.app.ActivityThread.main(ActivityThread.java:4627) 01-21 20:13:49.226: E/AndroidRuntime(301): at java.lang.reflect.Method.invokeNative(Native Method) 01-21 20:13:49.226: E/AndroidRuntime(301): at java.lang.reflect.Method.invoke(Method.java:521) 01-21 20:13:49.226: E/AndroidRuntime(301): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-21 20:13:49.226: E/AndroidRuntime(301): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-21 20:13:49.226: E/AndroidRuntime(301): at dalvik.system.NativeStart.main(Native Method) 01-21 20:13:49.226: E/AndroidRuntime(301): Caused by: java.lang.NullPointerException 01-21 20:13:49.226: E/AndroidRuntime(301): at com.androidhive.jsonparsing.AndroidJSONParsingActivity.onCreate(AndroidJSONParsingActivity.java:65) 01-21 20:13:49.226: E/AndroidRuntime(301): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-21 20:13:49.226: E/AndroidRuntime(301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 

Please guide me how can I insert the JSON array data into the database or where I am doing wrong. Every response is appreciable.

Источник

Оцените статью