I am developing an android application in which I am displaying conversation List.
My code works fine in Samsung Galaxy S,Nexus one and Galaxy Nexus but the query is giving a problem in my Galaxy Grand phone.
Here is my code:
public ArrayList<String> getSMS()
{
ArrayList<String> sms = new ArrayList<String>();
Uri uriSMSURI = Uri.parse("content://mms-sms/conversations/");
Cursor cursor = getContentResolver().query(uriSMSURI, null, null, null, "date desc");
//cursor.moveToFirst();
while (cursor.moveToNext())
{
String address = cursor.getString(cursor.getColumnIndex("address"));
String body = cursor.getString(cursor.getColumnIndexOrThrow("body"));
String read = cursor.getString(cursor.getColumnIndexOrThrow("read"));
//to fetch the contact name of the conversation
String contactName = address;
Uri Nameuri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address));
Cursor cs= getContentResolver().query(Nameuri, new String[]{PhoneLookup.DISPLAY_NAME},PhoneLookup.NUMBER+"='"+address+"'",null,null);
if(cs.getCount()>0)
{
cs.moveToFirst();
contactName = cs.getString(cs.getColumnIndex(PhoneLookup.DISPLAY_NAME));
}
sms.add(contactName + "\n"+body);
}
return sms;
}
The following is the stackTrace:
06-24 17:26:21.744: E/AndroidRuntime(12764): FATAL EXCEPTION: main
06-24 17:26:21.744: E/AndroidRuntime(12764): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ssn.sms/com.ssn.sms.test}: java.lang.NullPointerException
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.app.ActivityThread.access$700(ActivityThread.java:140)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.os.Looper.loop(Looper.java:137)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.app.ActivityThread.main(ActivityThread.java:4935)
06-24 17:26:21.744: E/AndroidRuntime(12764): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 17:26:21.744: E/AndroidRuntime(12764): at java.lang.reflect.Method.invoke(Method.java:511)
06-24 17:26:21.744: E/AndroidRuntime(12764): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
06-24 17:26:21.744: E/AndroidRuntime(12764): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
06-24 17:26:21.744: E/AndroidRuntime(12764): at dalvik.system.NativeStart.main(Native Method)
06-24 17:26:21.744: E/AndroidRuntime(12764): Caused by: java.lang.NullPointerException
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.os.Parcel.readException(Parcel.java:1431)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.content.ContentResolver.query(ContentResolver.java:372)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.content.ContentResolver.query(ContentResolver.java:315)
06-24 17:26:21.744: E/AndroidRuntime(12764): at com.ssn.sms.test.getSMS(test.java:157)
06-24 17:26:21.744: E/AndroidRuntime(12764): at com.ssn.sms.test.onCreate(test.java:74)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.app.Activity.performCreate(Activity.java:5206)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
06-24 17:26:21.744: E/AndroidRuntime(12764): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
06-24 17:26:21.744: E/AndroidRuntime(12764): ... 11 more
I also referred to the below Link and used it,but still it is the same
SGS-3 bug related to SMS conversations list?
try this i have use function all sms return in json string
public JSONObject getsms()
{
JSONObject result = null;
JSONArray jarray = null;
String link[] = {"content://sms/inbox","content://sms/sent","content://sms/draft"};
try {
jarray = new JSONArray();
result = new JSONObject();
Uri uri = Uri.parse("content://sms/");
Cursor c= act.getContentResolver().query(uri, null, null ,null,null);
act.startManagingCursor(c);
// Read the sms data and store it in the list
if(c.moveToFirst()) {
for(int i=0; i < c.getCount(); i++) {
result.put("body",c.getString(c.getColumnIndexOrThrow("body")).toString());
result.put("date",c.getString(c.getColumnIndexOrThrow("date")).toString());
result.put("read",c.getString(c.getColumnIndexOrThrow("read")).toString());
result.put("type",c.getString(c.getColumnIndexOrThrow("type")).toString());
if((c.getString(c.getColumnIndexOrThrow("type")).toString()).equals("3"))
{
//Cursor cur= getContentResolver().query("", null, null ,null,null);
//startManagingCursor(cur);
String threadid = c.getString(c.getColumnIndexOrThrow("thread_id")).toString();
Cursor cur= act.getContentResolver().query(Uri.parse("content://mms-sms/conversations?simple=true"), null, "_id ="+threadid ,null,null);
act.startManagingCursor(cur);
if(cur.moveToFirst())
{
String recipientId = cur.getString(cur.getColumnIndexOrThrow("recipient_ids")).toString();
cur= act.getContentResolver().query(Uri.parse("content://mms-sms/canonical-addresses"), null, "_id = " + recipientId, null, null);
act.startManagingCursor(cur);
if(cur.moveToFirst())
{
String address = cur.getString(cur.getColumnIndexOrThrow("address")).toString();
result.put("address",address);
cur.close();
}
}
}else
{
result.put("address",c.getString(c.getColumnIndexOrThrow("address")).toString());
}
jarray.put(result);
result = new JSONObject();
c.moveToNext();
}
}
c.close();
result.put("smslist", jarray);
//result = new JSONObject(jarray.toString());
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
Related
When i am trying to display the contacts in card view when i click on Button it shows fatal exception error it doesnot display cardview anyone can solve this programming with brillliance and another error is it show only one cardview when i click on again the app will be strucked?
Showcontacts.java
public class ShowContacts extends Activity
{
private SQLiteDatabase db;
DbOperations doo;
private List<Contacts> contactsList;
private RecyclerView rv;
private Cursor c;
String names,email,address;
int phone;
String read_query = "select * from"+ ContactsTask.ContactsEntry.TABLE_NAME;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recycle_layout);
doo = new DbOperations(this);
openDatabase();
rv = (RecyclerView)findViewById(R.id.recyclerview);
initializeData();
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
rv.setLayoutManager(linearLayoutManager);
rv.setHasFixedSize(true);
ContactAdapter cc = new ContactAdapter(contactsList);
rv.setAdapter(cc);
}
public void initializeData() {
contactsList = new ArrayList<>();
c = db.rawQuery(read_query,null);
c.moveToFirst();
while (!c.isLast())
{
names = c.getString(0);
phone = c.getInt(1);
email = c.getString(2);
address = c.getString(3);
contactsList.add(new Contacts(names,phone,email,address));
}
c.isLast();
names = c.getString(0);
phone = c.getInt(1);
email = c.getString(2);
address = c.getString(3);
contactsList.add(new Contacts(names,phone,email,address));
}
private void openDatabase() {
db = openOrCreateDatabase("contactDB", Context.MODE_PRIVATE,null);
}
}
Logacat error
06-28 08:57:43.107 568-568/com.example.anilkumar.contactstask E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.anilkumar.contactstask/com.example.anilkumar.contactstask.ShowContacts}: android.database.sqlite.SQLiteException: near "fromcontacts": syntax error: , while compiling: select * fromcontacts
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: near "fromcontacts": syntax error: , while compiling: select * fromcontacts
at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1538)
at com.example.anilkumar.contactstask.ShowContacts.initializeData(ShowContacts.java:44)
at com.example.anilkumar.contactstask.ShowContacts.onCreate(ShowContacts.java:34)
at android.app.Activity.performCreate(Activity.java:4466)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
Another logact error
06-28 13:14:40.552 11252-11261/com.example.anilkumar.contactstask E/SQLiteDatabase: close() was never explicitly called on database '/data/data/com.example.anilkumar.contactstask/databases/contactDB'
android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1943)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1007)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:962)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1043)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1036)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:761)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:215)
at com.example.anilkumar.contactstask.ShowContacts.openDatabase(ShowContacts.java:66)
at com.example.anilkumar.contactstask.ShowContacts.onCreate(ShowContacts.java:33)
at android.app.Activity.performCreate(Activity.java:4466)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
Just update
String read_query = "select * from"+ ContactsTask.ContactsEntry.TABLE_NAME;
to
String read_query = "select * from "+ ContactsTask.ContactsEntry.TABLE_NAME;
Always close cursor. update your initializeData method
public void initializeData() {
try {
contactsList = new ArrayList<>();
try{
c = db.rawQuery(read_query,null);
c.moveToFirst();
while (!c.isLast())
{
names = c.getString(0);
phone = c.getInt(1);
email = c.getString(2);
address = c.getString(3);
contactsList.add(new Contacts(names,phone,email,address));
}
c.isLast();
names = c.getString(0);
phone = c.getInt(1);
email = c.getString(2);
address = c.getString(3);
contactsList.add(new Contacts(names,phone,email,address));
} catch (Exception e) {
// exception handling
} finally {
if(c != null){
c.close();
}
}
}
Am working on a project. I want to insert student details into sqlite database but i receive an error in the android monitor that "The TABLE AttendanceList does not have column named surname" and i do have that colunm. i have been stuck for days, please i help.
Here is my code.
DatabaseHandler.java
public class DatabaseHandler extends SQLiteOpenHelper {
// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "StudentAttendance";
// Contacts table name
private static final String TABLE_AttendanceList = "AttendanceList";
// Contacts Table Columns names
private static final String KEY_surname = "surname";
private static final String KEY_ID = "id";
private static final String KEY_reg_no = "reg_no";
private static final String KEY_firstname = "firstname";
private static final String KEY_lastname = "lastname";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
#Override
public void onCreate(SQLiteDatabase db) {
String CREATE_AttendanceList_TABLE = "CREATE TABLE " + TABLE_AttendanceList + "("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_reg_no + " TEXT"
+ KEY_firstname + " TEXT"
+ KEY_lastname + "TEXT"
+ KEY_surname + "TEXT" + ")";
db.execSQL(CREATE_AttendanceList_TABLE);
}
// Upgrading database
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_AttendanceList);
// Create tables again
onCreate(db);
}
/**
* All CRUD(Create, Read, Update, Delete) Operations
*/
// Adding new contact
void addAttendanceList (AttendanceList AttendanceList) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_ID, AttendanceList.getID());
values.put(KEY_reg_no, AttendanceList.getRegNo()); // RegNo
values.put(KEY_firstname, AttendanceList.getFirstname());
values.put(KEY_lastname, AttendanceList.getLastname()); // lasttname
values.put(KEY_surname, AttendanceList.getSurname());// surname
// Inserting Row
db.insert(TABLE_AttendanceList,null,values);
db.close(); // Closing database connection
}
// Getting single contact
AttendanceList getAttendanceList(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_AttendanceList, new String[] { KEY_ID,
KEY_reg_no, KEY_firstname, KEY_lastname, KEY_surname }, KEY_ID + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
AttendanceList AttendanceList = new AttendanceList(Integer.parseInt(cursor.getString(0)),
cursor.getString(1), cursor.getString(2), cursor.getString(3),cursor.getString(4));
// return AttendanceList
return AttendanceList;
}
// Getting All details
public List<AttendanceList> getAllAttendanceList() {
List<AttendanceList> contactList = new ArrayList<AttendanceList>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_AttendanceList;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
AttendanceList AttendanceList = new AttendanceList();
AttendanceList.setID(Integer.parseInt(cursor.getString(0)));
AttendanceList.setRegNo(cursor.getString(1));
AttendanceList.setFirstname(cursor.getString(2));
AttendanceList.setLastname(cursor.getString(3));
AttendanceList.setSurname(cursor.getString(4));
// Adding Attendance to list
contactList.add(AttendanceList);
} while (cursor.moveToNext());
}
// return Attendancelist
return contactList;
}
// Updating single Attendance List
public int updateContact(AttendanceList AttendanceList) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_reg_no, AttendanceList.getRegNo());
values.put(KEY_firstname, AttendanceList.getFirstname());
values.put(KEY_lastname, AttendanceList.getLastname());
values.put(KEY_surname, AttendanceList.getSurname());
// updating row
return db.update(TABLE_AttendanceList, values, KEY_ID + " = ?",
new String[] { String.valueOf(AttendanceList.getID()) });
}
// Deleting single List item
public void deleteListItem(AttendanceList AttendanceList) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_AttendanceList, KEY_ID + " = ?",
new String[] { String.valueOf(AttendanceList.getID()) });
db.close();
}
// Getting List Count
public int getListCount() {
String countQuery = "SELECT * FROM " + TABLE_AttendanceList;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
// return count
return cursor.getCount();
}
}
StudentTake100Activity.java
public class StudentTake100Activity extends AppCompatActivity {
private ListView lvStudentlist;
private StudentListAdapter adapter;
private List<StudentList> mStudentList;
private CheckBox checkBox;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_take100);
lvStudentlist= (ListView) findViewById(R.id.listview_studentlist);
final DatabaseHandler db = new DatabaseHandler(this);
mStudentList = new ArrayList<>();
//Add sample data for list
//We can get data from DB, webservice here
mStudentList.add(new StudentList(1, "U11EE1001", "Bargo","S.","Mayafi"));
mStudentList.add(new StudentList(2, "U11EE1002", "Barnsbas","Snake.","Maciji"));
mStudentList.add(new StudentList(3, "U11EE1004", "Adamu","Tanko.","Sadau"));
mStudentList.add(new StudentList(4, "U11EE1005", "Munzali","","Cire Tallafi"));
//Init adapter
adapter = new StudentListAdapter(getApplicationContext(), mStudentList);
lvStudentlist.setAdapter(adapter);
checkBox = (CheckBox) findViewById(R.id.checkBox);
lvStudentlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
StudentList studentList = (StudentList)parent.getItemAtPosition(position);
String reg_no = studentList.getReg_no();
String firstname = studentList.getFirstname();
String lastname = studentList.getLasttname();
String surname = studentList.getSurname();
db.addAttendanceList(new AttendanceList(reg_no,firstname,lastname,surname));
}
});
}
}
AttendaneList.java
public class AttendanceList {
//private variables
int _id;
String _reg_no;
String _firstname;
String _lastname;
String _surname;
// Empty constructor
public AttendanceList(){
}
// constructor
public AttendanceList(int id, String _reg_no, String _firstname, String _lastname, String _surname){
this._id = id;
this._reg_no = _reg_no;
this._firstname = _firstname;
this._lastname = _lastname;
this._surname = _surname;
}
// constructor
public AttendanceList(String _reg_no, String _firstname, String _lastname, String _surname){
this._reg_no = _reg_no;
this._firstname = _firstname;
this._lastname = _lastname;
this._surname = _surname;
}
// getting ID
public int getID(){
return this._id;
}
// setting id
public void setID(int id){
this._id = id;
}
// getting regNo
public String getRegNo(){
return this._reg_no;
}
// setting regNo
public void setRegNo(String reg_no){
this._reg_no = reg_no;
}
// getting firstname
public String getFirstname(){
return this._firstname;
}
// setting firstname
public void setFirstname(String firstname){
this._firstname = firstname;
}
// getting lastname
public String getLastname(){
return this._lastname;
}
// setting lastname
public void setLastname(String lastname){
this._lastname = lastname;
}
// getting surname
public String getSurname(){
return this._surname;
}
// setting surname
public void setSurname(String surname){
this._surname = surname;
}
}
logcat image
syntax error
06-22 10:58:04.576 2936-2961/com.sunusi2sim.mobileattendance E/Surface: getSlotFromBufferLocked: unknown buffer: 0xeeab85e0
06-22 10:58:05.957 2936-2936/com.sunusi2sim.mobileattendance E/SQLiteLog: (1) near ")": syntax error
06-22 10:58:05.959 2936-2936/com.sunusi2sim.mobileattendance E/InputEventReceiver: Exception dispatching input event.
06-22 10:58:05.959 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: CREATE TABLE AttendanceList(id INTEGER PRIMARY KEY,reg_no TEXT,firstname TEXT,lastname TEXT,surname TEXT,)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at com.sunusi2sim.mobileattendance.DatabaseHandler.onCreate(DatabaseHandler.java:47)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at com.sunusi2sim.mobileattendance.DatabaseHandler.addAttendanceList(DatabaseHandler.java:66)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at com.sunusi2sim.mobileattendance.StudentTake100Activity$1.onItemClick(StudentTake100Activity.java:54)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.widget.AdapterView.performItemClick(AdapterView.java:310)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.widget.AbsListView$PerformClick.run(AbsListView.java:3042)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.widget.AbsListView.onTouchUp(AbsListView.java:3891)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.widget.AbsListView.onTouchEvent(AbsListView.java:3656)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.View.dispatchTouchEvent(View.java:9294)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2547)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2240)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2403)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1737)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.app.Activity.dispatchTouchEvent(Activity.java:2765)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2364)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.View.dispatchPointerEvent(View.java:9514)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4230)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4096)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3787)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3844)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
06-22 10:58:05.961 2936-2936/com.sunusi2sim.mobileattendance E/MessageQueue-JNI: at android.view.ViewRootImpl$InputS
ViewAttendanceActivity
public class ViewAttendanceActivity extends AppCompatActivity {
private ListView lvStudentlist;
private StudentListAdapter adapter;
private List<StudentList> mStudentList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_attendance);
lvStudentlist= (ListView) findViewById(R.id.listview_studentlist);
DatabaseHandler db = new DatabaseHandler(this);
SQLiteDatabase connection;
connection = db.getReadableDatabase();
Cursor result=connection.rawQuery("SELECT * FROM AttendanceList", null);// database query for all AttendanceList in your table
while(result.moveToNext ())
mStudentList.add(new StudentList(result.getInt(0),result.getString(1),result.getString(2),result.getString(3),result.getString(4)));
mStudentList = new ArrayList<>();
adapter = new StudentListAdapter(getApplicationContext(), mStudentList);
lvStudentlist.setAdapter(adapter);
}
}
Error
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: FATAL EXCEPTION: main
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: Process: com.sunusi2sim.mobileattendance, PID: 1650
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sunusi2sim.mobileattendance/com.sunusi2sim.mobileattendance.ViewAttendanceActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at com.sunusi2sim.mobileattendance.ViewAttendanceActivity.onCreate(ViewAttendanceActivity.java:31)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6237)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
06-24 17:41:05.354 1650-1650/com.sunusi2sim.mobileattendance E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
Your create table query is messing it up. Column name and its type should have a space in between and also comma is missing. Use this
#Override
public void onCreate(SQLiteDatabase db) {
String CREATE_AttendanceList_TABLE = "CREATE TABLE " + TABLE_AttendanceList + "("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_reg_no + " TEXT,"
+ KEY_firstname + " TEXT,"
+ KEY_lastname + " TEXT,"
+ KEY_surname + " TEXT" + ")";
db.execSQL(CREATE_AttendanceList_TABLE);
}
You will have to uninstall the app first then run the updated code.
I would like to add texture to my model but I keep getting this error . Any help would be appreciated. Thanks
for (String i : faces) {
for (String j : i.split(" ")) {
iCoords[faceIndex] = (short) faceIndex++;
String[] faceComponent = j.split("/");
String vertex = vertexes.get(Integer.parseInt(faceComponent[0]) - 1);
// this line throws NFE
String texture = textures.get(Integer.parseInt(faceComponent[1]) - 1);
String vertexComp[] = vertex.split(" ");
String textureComp[] = texture.split(" ");
for (String v : vertexComp) {
vCoords[vertexIndex++] = Float.parseFloat(v);
}
for (String t : textureComp) {
tCoords[textureIndex++] = Float.parseFloat(t);
}
}
}
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.app.glapp/com.app.glapp.MainActivity}:
java.lang.NumberFormatException: Invalid int: ""
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5603)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: Invalid int: ""
at java.lang.Integer.invalidInt(Integer.java:137)
at java.lang.Integer.parseInt(Integer.java:358)
at java.lang.Integer.parseInt(Integer.java:331)
at com.mingatronenterprices.glapp.mesh.(mesh.java:72)
at com.mingatronenterprices.glapp.ClearRenderer.(MainActivity.java:70)
at com.app.glapp.ClearGLSurfaceView.(MainActivity.java:54)
at com.app.glapp.MainActivity.onCreate(MainActivity.java:32)
at android.app.Activity.performCreate(Activity.java:5458)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5603)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Try to modify like this:
for (String v : vertexComp) {
try {
vCoords[vertexIndex++] = Float.parseFloat(v);
}
catch (NumberFormatException e) {
}
}
for (String t : textureComp) {
try {
tCoords[textureIndex++] = Float.parseFloat(t);
}
catch (NumberFormatException e) {
}
}
I am trying to use Voice Recognition on Android. Following is my code.
This is the code of the Button that is responsible to start speech recognition.
speak.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v)
{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "City Name Please?");
startActivityForResult(intent, REQUEST_CODE);
}});
Here is a onActivityResult method.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
ArrayList<String> matches_Text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
Log.v("Results", matches_Text.get(0).toString());
//Update EditText cityname here
String normalized_cityname = matches_Text.get(0).toString().trim();
normalized_cityname = normalized_cityname.replace(" ","%20");
try {
getResponseString("http://api.openweathermap.org/data/2.5/weather?q="+normalized_cityname+"&units=metric", true);
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
The code worked ok but there are two problems I am encountering now and I am afraid that they may be related.
If I try to update text in an EditText instance cityname using cityname.setText(matches_Text.get(0).toString()), it crashes the app.
If I hit the speak button now, the google voice dialog comes up but shows can't reacg google at the moment.
Please suggest what can I do?
Adding the getResponseString method also.
public void getResponseString(String Url, boolean IsCalledOnVoiceInput) throws IOException, JSONException {
String temperature="";
String city;
String country;
String weather_main, weather_description;
MyAsyncTask xxx = new MyAsyncTask();
try {
String responseString = xxx.execute(Url).get();
TextView txtTemp = (TextView)findViewById(R.id.txt_temp);
TextView txtCity = (TextView)findViewById(R.id.txt_CityName);
TextView txtWeatherMain = (TextView)findViewById(R.id.textView2);
TextView txtWeatherDescription = (TextView)findViewById(R.id.textView3);
JSONObject reader = new JSONObject(responseString);
JSONObject main = reader.getJSONObject("main");
temperature = main.getString("temp");
Log.v("temperarure",temperature);
city = reader.getString("name");
Log.v("city",city);
JSONObject sys = reader.getJSONObject("sys");
country = sys.getString("country");
Log.v("country",country);
JSONArray weather = reader.getJSONArray("weather");
JSONObject weather_obj = weather.getJSONObject(0);
weather_main = weather_obj.getString("main");
weather_description = weather_obj.getString("description");
txtTemp.setText(temperature+" °C");
txtCity.setText(city+" ("+country+")");
txtWeatherMain.setText(weather_main);
txtWeatherDescription.setText(weather_description);
if(IsCalledOnVoiceInput)
Speak_Weather_Data(city,temperature,weather_main,weather_description);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (JSONException e){
e.printStackTrace();
}
}
Here is the log output
12-24 13:36:06.050 12164-12164/samarth.learning.http D/dalvikvm﹕ Late-enabling CheckJNI
12-24 13:36:06.300 12164-12164/samarth.learning.http D/Network﹕ Network
12-24 13:36:06.300 12164-12164/samarth.learning.http V/Lat﹕ 28.8331443
12-24 13:36:06.300 12164-12164/samarth.learning.http V/Long﹕ 78.7717138
12-24 13:36:06.360 12164-12164/samarth.learning.http D/libEGL﹕ loaded /vendor/lib/egl/libEGL_adreno.so
12-24 13:36:06.370 12164-12164/samarth.learning.http D/libEGL﹕ loaded /vendor/lib/egl/libGLESv1_CM_adreno.so
12-24 13:36:06.380 12164-12164/samarth.learning.http D/libEGL﹕ loaded /vendor/lib/egl/libGLESv2_adreno.so
12-24 13:36:06.380 12164-12164/samarth.learning.http I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:316>: EGL 1.4 QUALCOMM build: (CL4169980)
OpenGL ES Shader Compiler Version: 17.01.10.SPL
Build Date: 11/04/13 Mon
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
12-24 13:36:06.430 12164-12164/samarth.learning.http D/OpenGLRenderer﹕ Enabling debug mode 0
12-24 13:36:06.531 12164-12164/samarth.learning.http E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
12-24 13:36:06.531 12164-12164/samarth.learning.http E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
12-24 13:36:08.232 12164-12164/samarth.learning.http W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection
12-24 13:36:18.844 12164-12164/samarth.learning.http V/Results﹕ new delhi
12-24 13:36:18.844 12164-12164/samarth.learning.http D/AndroidRuntime﹕ Shutting down VM
12-24 13:36:18.844 12164-12164/samarth.learning.http W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4157c8b0)
12-24 13:36:18.854 12164-12164/samarth.learning.http E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1234, result=-1, data=Intent { (has extras) }} to activity {samarth.learning.http/samarth.learning.http.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3462)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3505)
at android.app.ActivityThread.access$1100(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1346)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at samarth.learning.http.MainActivity.onActivityResult(MainActivity.java:160)
at android.app.Activity.dispatchActivityResult(Activity.java:5322)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3458)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3505)
at android.app.ActivityThread.access$1100(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1346)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
12-24 13:36:22.558 12164-12164/samarth.learning.http I/Process﹕ Sending signal. PID: 12164 SIG: 9
is this what you mean?
i think matches_Text is sometimes NULL?! how about adding an
if(matches_Text == null){
Log.v("Results","matches_Text is NULL!");
return;
}
add above code just after ArrayList<String> matches_Text = da...
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (people.moveToNext()){
int NameIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
int NumIndex = people.getColumnIndex(PhoneLookup.NUMBER);
String Name = people.getString(NameIndex);
//String Num = people.getString(NumIndex);
myArr.add(Name.toString());
myNum.add(Num.toString());
}
Hello I am experiencing problems retrieving a contact's phone number where each time i enable this line of code
String Num = people.getString(NumIndex);
03-03 15:38:30.436: E/AndroidRuntime(496): FATAL EXCEPTION: main
03-03 15:38:30.436: E/AndroidRuntime(496): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.GhattasAk.RingMe/com.GhattasAk.RingMe.Main}: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.os.Handler.dispatchMessage(Handler.java:99)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.os.Looper.loop(Looper.java:123)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-03 15:38:30.436: E/AndroidRuntime(496): at java.lang.reflect.Method.invokeNative(Native Method)
03-03 15:38:30.436: E/AndroidRuntime(496): at java.lang.reflect.Method.invoke(Method.java:507)
03-03 15:38:30.436: E/AndroidRuntime(496): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-03 15:38:30.436: E/AndroidRuntime(496): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-03 15:38:30.436: E/AndroidRuntime(496): at dalvik.system.NativeStart.main(Native Method)
03-03 15:38:30.436: E/AndroidRuntime(496): Caused by: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
03-03 15:38:30.436: E/AndroidRuntime(496): at android.database.CursorWindow.getString_native(Native Method)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.database.CursorWindow.getString(CursorWindow.java:329)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.database.CursorWrapper.getString(CursorWrapper.java:135)
03-03 15:38:30.436: E/AndroidRuntime(496): at com.GhattasAk.RingMe.Main.onCreate(Main.java:49)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-03 15:38:30.436: E/AndroidRuntime(496): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-03 15:38:30.436: E/AndroidRuntime(496): ... 11 more
the application crashes.. I do not understand why
this is the edit to get a name based on a number is this true ?
if(state==TelephonyManager.CALL_STATE_RINGING)
{
// Find contact based on name.
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
"NUMBER = '" + number + "'", null, null);
if (cursor.moveToFirst()) {
String contactId =
cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
// Get all phone numbers.
Cursor phones = cr.query(Phone.CONTENT_URI, null,
Phone.CONTACT_ID + " = " + contactId, null, null);
while (phones.moveToNext()) {
String numb = phones.getString(phones.getColumnIndex(Phone.DISPLAY_NAME));
}
phones.close();
}
cursor.close();
Probably becouse the contact have multiple phone nrs like work...
try this:
// Find contact based on name.
//
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
"DISPLAY_NAME = '" + NAME + "'", null, null);
if (cursor.moveToFirst()) {
String contactId =
cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
//
// Get all phone numbers.
//
Cursor phones = cr.query(Phone.CONTENT_URI, null,
Phone.CONTACT_ID + " = " + contactId, null, null);
while (phones.moveToNext()) {
String number = phones.getString(phones.getColumnIndex(Phone.NUMBER));
int type = phones.getInt(phones.getColumnIndex(Phone.TYPE));
switch (type) {
case Phone.TYPE_HOME:
// do something with the Home number here...
break;
case Phone.TYPE_MOBILE:
// do something with the Mobile number here...
break;
case Phone.TYPE_WORK:
// do something with the Work number here...
break;
}
}
phones.close();
}
cursor.close();