ListView RuntimeException [duplicate]










0
















This question already has an answer here:



  • What is a NullPointerException, and how do I fix it?

    12 answers



  • Why Android app crashes for initializing variable with findViewById(R.id.******) at the beginning of the class?

    4 answers



  • Your content must have a ListView whose id attribute is 'android.R.id.list'

    7 answers



I have created an app to fetch the contact list after getting logged in, But after Log in the app is getting stopped instead of opening ContactActivity.java
here is my LOGCAT and the ContactActivity Code. please someone help...



i tried to resolve the problem but didn't get success



LOGCAT:



W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@45289e1
I/Timeline: Timeline: Activity_launch_request time:145293352 intent:Intent cmp=com.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.delaroystudios.sqlitelogin, PID: 26883
java.lang.RuntimeException: Unable to instantiate activity ComponentInfocom.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2625)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.Activity.findViewById(Activity.java:2401)
at com.delaroystudios.filterContacts.activities.ContactActivity.<init>(ContactActivity.java:26)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:163) 
at android.app.ActivityThread.main(ActivityThread.java:6238) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823) 
I/Process: Sending signal. PID: 26883 SIG: 9
Application terminated.


contact_list_view.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>

</LinearLayout>


ContactActivity.java



package com.delaroystudios.filterContacts.activities;

import android.app.ListActivity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import android.provider.ContactsContract;
import android.widget.Toast;

import com.delaroystudios.sqlitelogin.R;

import java.util.ArrayList;

public class ContactActivity extends ListActivity

ListView lv = (ListView) findViewById(R.id.list);
Cursor cursor;

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_list_view);


cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null,null);
startManagingCursor(cursor);

String from = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID;
int to = android.R.id.text1, android.R.id.text2;

SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_expandable_list_item_2,cursor,from,to);
setListAdapter(listAdapter);

lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);



@Override
public long getSelectedItemId()
return super.getSelectedItemId();


@Override
public int getSelectedItemPosition()
return super.getSelectedItemPosition();


@Override
public boolean onCreateOptionsMenu(Menu menu)
return super.onCreateOptionsMenu(menu);











share|improve this question















marked as duplicate by Nilesh Rathod android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 15 '18 at 7:29


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 1





    You need to do findViewById inside onCreate() after setContentView() method

    – Nilesh Rathod
    Nov 15 '18 at 7:30












  • @NileshRathod still not Working

    – shubham kumar
    Nov 15 '18 at 7:33











  • @NileshRathod Process: com.delaroystudios.sqlitelogin, PID: 30184 java.lang.RuntimeException: Unable to start activity ComponentInfocom.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2723)

    – shubham kumar
    Nov 15 '18 at 7:35











  • than check this stackoverflow.com/questions/11050817/…

    – Nilesh Rathod
    Nov 15 '18 at 7:36






  • 1





    @NileshRathod thanks that link worked for me :)

    – shubham kumar
    Nov 15 '18 at 7:48















0
















This question already has an answer here:



  • What is a NullPointerException, and how do I fix it?

    12 answers



  • Why Android app crashes for initializing variable with findViewById(R.id.******) at the beginning of the class?

    4 answers



  • Your content must have a ListView whose id attribute is 'android.R.id.list'

    7 answers



I have created an app to fetch the contact list after getting logged in, But after Log in the app is getting stopped instead of opening ContactActivity.java
here is my LOGCAT and the ContactActivity Code. please someone help...



i tried to resolve the problem but didn't get success



LOGCAT:



W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@45289e1
I/Timeline: Timeline: Activity_launch_request time:145293352 intent:Intent cmp=com.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.delaroystudios.sqlitelogin, PID: 26883
java.lang.RuntimeException: Unable to instantiate activity ComponentInfocom.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2625)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.Activity.findViewById(Activity.java:2401)
at com.delaroystudios.filterContacts.activities.ContactActivity.<init>(ContactActivity.java:26)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:163) 
at android.app.ActivityThread.main(ActivityThread.java:6238) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823) 
I/Process: Sending signal. PID: 26883 SIG: 9
Application terminated.


contact_list_view.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>

</LinearLayout>


ContactActivity.java



package com.delaroystudios.filterContacts.activities;

import android.app.ListActivity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import android.provider.ContactsContract;
import android.widget.Toast;

import com.delaroystudios.sqlitelogin.R;

import java.util.ArrayList;

public class ContactActivity extends ListActivity

ListView lv = (ListView) findViewById(R.id.list);
Cursor cursor;

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_list_view);


cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null,null);
startManagingCursor(cursor);

String from = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID;
int to = android.R.id.text1, android.R.id.text2;

SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_expandable_list_item_2,cursor,from,to);
setListAdapter(listAdapter);

lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);



@Override
public long getSelectedItemId()
return super.getSelectedItemId();


@Override
public int getSelectedItemPosition()
return super.getSelectedItemPosition();


@Override
public boolean onCreateOptionsMenu(Menu menu)
return super.onCreateOptionsMenu(menu);











share|improve this question















marked as duplicate by Nilesh Rathod android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 15 '18 at 7:29


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 1





    You need to do findViewById inside onCreate() after setContentView() method

    – Nilesh Rathod
    Nov 15 '18 at 7:30












  • @NileshRathod still not Working

    – shubham kumar
    Nov 15 '18 at 7:33











  • @NileshRathod Process: com.delaroystudios.sqlitelogin, PID: 30184 java.lang.RuntimeException: Unable to start activity ComponentInfocom.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2723)

    – shubham kumar
    Nov 15 '18 at 7:35











  • than check this stackoverflow.com/questions/11050817/…

    – Nilesh Rathod
    Nov 15 '18 at 7:36






  • 1





    @NileshRathod thanks that link worked for me :)

    – shubham kumar
    Nov 15 '18 at 7:48













0












0








0









This question already has an answer here:



  • What is a NullPointerException, and how do I fix it?

    12 answers



  • Why Android app crashes for initializing variable with findViewById(R.id.******) at the beginning of the class?

    4 answers



  • Your content must have a ListView whose id attribute is 'android.R.id.list'

    7 answers



I have created an app to fetch the contact list after getting logged in, But after Log in the app is getting stopped instead of opening ContactActivity.java
here is my LOGCAT and the ContactActivity Code. please someone help...



i tried to resolve the problem but didn't get success



LOGCAT:



W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@45289e1
I/Timeline: Timeline: Activity_launch_request time:145293352 intent:Intent cmp=com.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.delaroystudios.sqlitelogin, PID: 26883
java.lang.RuntimeException: Unable to instantiate activity ComponentInfocom.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2625)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.Activity.findViewById(Activity.java:2401)
at com.delaroystudios.filterContacts.activities.ContactActivity.<init>(ContactActivity.java:26)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:163) 
at android.app.ActivityThread.main(ActivityThread.java:6238) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823) 
I/Process: Sending signal. PID: 26883 SIG: 9
Application terminated.


contact_list_view.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>

</LinearLayout>


ContactActivity.java



package com.delaroystudios.filterContacts.activities;

import android.app.ListActivity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import android.provider.ContactsContract;
import android.widget.Toast;

import com.delaroystudios.sqlitelogin.R;

import java.util.ArrayList;

public class ContactActivity extends ListActivity

ListView lv = (ListView) findViewById(R.id.list);
Cursor cursor;

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_list_view);


cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null,null);
startManagingCursor(cursor);

String from = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID;
int to = android.R.id.text1, android.R.id.text2;

SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_expandable_list_item_2,cursor,from,to);
setListAdapter(listAdapter);

lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);



@Override
public long getSelectedItemId()
return super.getSelectedItemId();


@Override
public int getSelectedItemPosition()
return super.getSelectedItemPosition();


@Override
public boolean onCreateOptionsMenu(Menu menu)
return super.onCreateOptionsMenu(menu);











share|improve this question

















This question already has an answer here:



  • What is a NullPointerException, and how do I fix it?

    12 answers



  • Why Android app crashes for initializing variable with findViewById(R.id.******) at the beginning of the class?

    4 answers



  • Your content must have a ListView whose id attribute is 'android.R.id.list'

    7 answers



I have created an app to fetch the contact list after getting logged in, But after Log in the app is getting stopped instead of opening ContactActivity.java
here is my LOGCAT and the ContactActivity Code. please someone help...



i tried to resolve the problem but didn't get success



LOGCAT:



W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@45289e1
I/Timeline: Timeline: Activity_launch_request time:145293352 intent:Intent cmp=com.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.delaroystudios.sqlitelogin, PID: 26883
java.lang.RuntimeException: Unable to instantiate activity ComponentInfocom.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2625)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.Activity.findViewById(Activity.java:2401)
at com.delaroystudios.filterContacts.activities.ContactActivity.<init>(ContactActivity.java:26)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:163) 
at android.app.ActivityThread.main(ActivityThread.java:6238) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823) 
I/Process: Sending signal. PID: 26883 SIG: 9
Application terminated.


contact_list_view.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>

</LinearLayout>


ContactActivity.java



package com.delaroystudios.filterContacts.activities;

import android.app.ListActivity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import android.provider.ContactsContract;
import android.widget.Toast;

import com.delaroystudios.sqlitelogin.R;

import java.util.ArrayList;

public class ContactActivity extends ListActivity

ListView lv = (ListView) findViewById(R.id.list);
Cursor cursor;

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_list_view);


cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null,null);
startManagingCursor(cursor);

String from = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID;
int to = android.R.id.text1, android.R.id.text2;

SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_expandable_list_item_2,cursor,from,to);
setListAdapter(listAdapter);

lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);



@Override
public long getSelectedItemId()
return super.getSelectedItemId();


@Override
public int getSelectedItemPosition()
return super.getSelectedItemPosition();


@Override
public boolean onCreateOptionsMenu(Menu menu)
return super.onCreateOptionsMenu(menu);






This question already has an answer here:



  • What is a NullPointerException, and how do I fix it?

    12 answers



  • Why Android app crashes for initializing variable with findViewById(R.id.******) at the beginning of the class?

    4 answers



  • Your content must have a ListView whose id attribute is 'android.R.id.list'

    7 answers







android listview simplecursoradapter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 18:59









TWL

2,059625




2,059625










asked Nov 15 '18 at 7:29









shubham kumarshubham kumar

11




11




marked as duplicate by Nilesh Rathod android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 15 '18 at 7:29


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Nilesh Rathod android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 15 '18 at 7:29


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 1





    You need to do findViewById inside onCreate() after setContentView() method

    – Nilesh Rathod
    Nov 15 '18 at 7:30












  • @NileshRathod still not Working

    – shubham kumar
    Nov 15 '18 at 7:33











  • @NileshRathod Process: com.delaroystudios.sqlitelogin, PID: 30184 java.lang.RuntimeException: Unable to start activity ComponentInfocom.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2723)

    – shubham kumar
    Nov 15 '18 at 7:35











  • than check this stackoverflow.com/questions/11050817/…

    – Nilesh Rathod
    Nov 15 '18 at 7:36






  • 1





    @NileshRathod thanks that link worked for me :)

    – shubham kumar
    Nov 15 '18 at 7:48












  • 1





    You need to do findViewById inside onCreate() after setContentView() method

    – Nilesh Rathod
    Nov 15 '18 at 7:30












  • @NileshRathod still not Working

    – shubham kumar
    Nov 15 '18 at 7:33











  • @NileshRathod Process: com.delaroystudios.sqlitelogin, PID: 30184 java.lang.RuntimeException: Unable to start activity ComponentInfocom.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2723)

    – shubham kumar
    Nov 15 '18 at 7:35











  • than check this stackoverflow.com/questions/11050817/…

    – Nilesh Rathod
    Nov 15 '18 at 7:36






  • 1





    @NileshRathod thanks that link worked for me :)

    – shubham kumar
    Nov 15 '18 at 7:48







1




1





You need to do findViewById inside onCreate() after setContentView() method

– Nilesh Rathod
Nov 15 '18 at 7:30






You need to do findViewById inside onCreate() after setContentView() method

– Nilesh Rathod
Nov 15 '18 at 7:30














@NileshRathod still not Working

– shubham kumar
Nov 15 '18 at 7:33





@NileshRathod still not Working

– shubham kumar
Nov 15 '18 at 7:33













@NileshRathod Process: com.delaroystudios.sqlitelogin, PID: 30184 java.lang.RuntimeException: Unable to start activity ComponentInfocom.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2723)

– shubham kumar
Nov 15 '18 at 7:35





@NileshRathod Process: com.delaroystudios.sqlitelogin, PID: 30184 java.lang.RuntimeException: Unable to start activity ComponentInfocom.delaroystudios.sqlitelogin/com.delaroystudios.filterContacts.activities.ContactActivity: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2723)

– shubham kumar
Nov 15 '18 at 7:35













than check this stackoverflow.com/questions/11050817/…

– Nilesh Rathod
Nov 15 '18 at 7:36





than check this stackoverflow.com/questions/11050817/…

– Nilesh Rathod
Nov 15 '18 at 7:36




1




1





@NileshRathod thanks that link worked for me :)

– shubham kumar
Nov 15 '18 at 7:48





@NileshRathod thanks that link worked for me :)

– shubham kumar
Nov 15 '18 at 7:48












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto