android:麻烦用联系人填充listview(android : Trouble populating listview with contacts)
我在google和stackoverflow上看了很多,最后写了一些代码,我认为应该按照预期将联系人放到listview中。 但我总是得到这个错误。 谁能帮我 ?
这是我的主要课程:
package com.shoaiblalich.pinchme; import java.util.ArrayList; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; import android.provider.ContactsContract.RawContacts; import android.app.Activity; import android.database.Cursor; import android.view.Menu; import android.widget.ListView; import android.widget.SimpleCursorAdapter; public class Main extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); populateContactList(); } private void populateContactList() { // TODO Auto-generated method stub Cursor cur = getContacts(); String[] fields = new String[] {ContactsContract.Data.DISPLAY_NAME}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,cur,fields,new int[] {android.R.id.text1});; ListView lv = (ListView) findViewById(R.id.listView1); lv.setAdapter(adapter); } @SuppressWarnings("deprecation") private Cursor getContacts() { // TODO Auto-generated method stub Uri uri = ContactsContract.Contacts.CONTENT_URI; String [] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME }; String selection = null; String[] selectionArgs = null; String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + "COLLATE LOCALIZED ASC"; return managedQuery(uri,projection,selection,selectionArgs,sortOrder); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
这就是我的logCat显示的内容:
01-02 12:28:44.037: E/AndroidRuntime(8074): FATAL EXCEPTION: main 01-02 12:28:44.037: E/AndroidRuntime(8074): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shoaiblalich.pinchme/com.shoaiblalich.pinchme.Main}: android.database.sqlite.SQLiteException: near "LOCALIZED": syntax error (code 1): , while compiling: SELECT _id, display_name FROM view_contacts_restricted WHERE ((1)) ORDER BY display_nameCOLLATE LOCALIZED ASC 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2304) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread.access$700(ActivityThread.java:165) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.os.Handler.dispatchMessage(Handler.java:99) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.os.Looper.loop(Looper.java:137) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread.main(ActivityThread.java:5450) 01-02 12:28:44.037: E/AndroidRuntime(8074): at java.lang.reflect.Method.invokeNative(Native Method) 01-02 12:28:44.037: E/AndroidRuntime(8074): at java.lang.reflect.Method.invoke(Method.java:525) 01-02 12:28:44.037: E/AndroidRuntime(8074): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187) 01-02 12:28:44.037: E/AndroidRuntime(8074): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 01-02 12:28:44.037: E/AndroidRuntime(8074): at dalvik.system.NativeStart.main(Native Method) 01-02 12:28:44.037: E/AndroidRuntime(8074): Caused by: android.database.sqlite.SQLiteException: near "LOCALIZED": syntax error (code 1): , while compiling: SELECT _id, display_name FROM view_contacts_restricted WHERE ((1)) ORDER BY display_nameCOLLATE LOCALIZED ASC 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.content.ContentProviderProxy.query(ContentProviderNative.java:385) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.content.ContentResolver.query(ContentResolver.java:417) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.content.ContentResolver.query(ContentResolver.java:360) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.Activity.managedQuery(Activity.java:1826) 01-02 12:28:44.037: E/AndroidRuntime(8074): at com.shoaiblalich.pinchme.Main.getContacts(Main.java:51) 01-02 12:28:44.037: E/AndroidRuntime(8074): at com.shoaiblalich.pinchme.Main.populateContactList(Main.java:30) 01-02 12:28:44.037: E/AndroidRuntime(8074): at com.shoaiblalich.pinchme.Main.onCreate(Main.java:22) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.Activity.performCreate(Activity.java:5369) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267) 01-02 12:28:44.037: E/AndroidRuntime(8074): ... 11 more 01-02 12:28:45.547: I/Process(8074): Sending signal. PID: 8074 SIG: 9
我真的很难把联系人放到列表视图中。 如果我的问题太混乱,有人可以告诉我如何从头开始这样做吗?
I've looked around a lot on google and stackoverflow and finally wrote some code which I think should get the contacts into the listview as expected. But I always get this error. Can anyone help me ?
This is my Main class :
package com.shoaiblalich.pinchme; import java.util.ArrayList; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; import android.provider.ContactsContract.RawContacts; import android.app.Activity; import android.database.Cursor; import android.view.Menu; import android.widget.ListView; import android.widget.SimpleCursorAdapter; public class Main extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); populateContactList(); } private void populateContactList() { // TODO Auto-generated method stub Cursor cur = getContacts(); String[] fields = new String[] {ContactsContract.Data.DISPLAY_NAME}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,cur,fields,new int[] {android.R.id.text1});; ListView lv = (ListView) findViewById(R.id.listView1); lv.setAdapter(adapter); } @SuppressWarnings("deprecation") private Cursor getContacts() { // TODO Auto-generated method stub Uri uri = ContactsContract.Contacts.CONTENT_URI; String [] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME }; String selection = null; String[] selectionArgs = null; String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + "COLLATE LOCALIZED ASC"; return managedQuery(uri,projection,selection,selectionArgs,sortOrder); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
And this is what my logCat displays:
01-02 12:28:44.037: E/AndroidRuntime(8074): FATAL EXCEPTION: main 01-02 12:28:44.037: E/AndroidRuntime(8074): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shoaiblalich.pinchme/com.shoaiblalich.pinchme.Main}: android.database.sqlite.SQLiteException: near "LOCALIZED": syntax error (code 1): , while compiling: SELECT _id, display_name FROM view_contacts_restricted WHERE ((1)) ORDER BY display_nameCOLLATE LOCALIZED ASC 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2304) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread.access$700(ActivityThread.java:165) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.os.Handler.dispatchMessage(Handler.java:99) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.os.Looper.loop(Looper.java:137) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread.main(ActivityThread.java:5450) 01-02 12:28:44.037: E/AndroidRuntime(8074): at java.lang.reflect.Method.invokeNative(Native Method) 01-02 12:28:44.037: E/AndroidRuntime(8074): at java.lang.reflect.Method.invoke(Method.java:525) 01-02 12:28:44.037: E/AndroidRuntime(8074): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187) 01-02 12:28:44.037: E/AndroidRuntime(8074): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 01-02 12:28:44.037: E/AndroidRuntime(8074): at dalvik.system.NativeStart.main(Native Method) 01-02 12:28:44.037: E/AndroidRuntime(8074): Caused by: android.database.sqlite.SQLiteException: near "LOCALIZED": syntax error (code 1): , while compiling: SELECT _id, display_name FROM view_contacts_restricted WHERE ((1)) ORDER BY display_nameCOLLATE LOCALIZED ASC 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.content.ContentProviderProxy.query(ContentProviderNative.java:385) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.content.ContentResolver.query(ContentResolver.java:417) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.content.ContentResolver.query(ContentResolver.java:360) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.Activity.managedQuery(Activity.java:1826) 01-02 12:28:44.037: E/AndroidRuntime(8074): at com.shoaiblalich.pinchme.Main.getContacts(Main.java:51) 01-02 12:28:44.037: E/AndroidRuntime(8074): at com.shoaiblalich.pinchme.Main.populateContactList(Main.java:30) 01-02 12:28:44.037: E/AndroidRuntime(8074): at com.shoaiblalich.pinchme.Main.onCreate(Main.java:22) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.Activity.performCreate(Activity.java:5369) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) 01-02 12:28:44.037: E/AndroidRuntime(8074): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267) 01-02 12:28:44.037: E/AndroidRuntime(8074): ... 11 more 01-02 12:28:45.547: I/Process(8074): Sending signal. PID: 8074 SIG: 9
I'm really having a tough time trying to get the contacts into the listview. If my question is too confusing, can anyone just show me how to go about doing this from scratch?
原文:https://stackoverflow.com/questions/20877957
最满意答案
我找到了解决方案OAuth2Util.getAuthzRequestContext()。getValidityPeriod()结果以毫秒为单位。
I found the soloution OAuth2Util.getAuthzRequestContext().getValidityPeriod() The result is in milliseconds.
相关问答
更多-
电脑二级考试 是考access 还是VPF[2022-06-08]
access -
这不支持。 MSF4J不声称是100%符合JAXRS,但是是一个用于构建微服务的轻量级框架。 我为此创建了JIRA [1]。 我们将在未来的版本中实施。 [1] - https://wso2.org/jira/browse/WMS-83 This is not supported. MSF4J doesn't claim to be 100% JAXRS compliant, but is a lightweight framework for building microservices. I've cr ...
-
您可以通过在repository/conf/identity/identity.xml
下启用以下配置来跳过OAuth2 / OpenIdConnect用户许可页面 true You can skip OAuth2/OpenIdConnect user consent page by enabling below configuration underin reposito ... -
Wso2访问令牌时间(Wso2 access token time)[2022-04-10]
要更改默认的到期时间,您需要在identity.xml上更新标记的值。 您正在端口9444上运行,因此可能意味着您正在运行API Manager和Identity Server,因此请记住在更新值时更改正确的identity.xml (在端口9444上运行的那个) 。 您需要重新启动服务器才能使更改生效。 当然,已生成的所有令牌将继续具有相同的到期时间,因此如果您重置APIM并要求再次生成令牌,则可能会返回旧令牌,因为它仍然是有效令 ... -
是的,您需要使用消费者/密钥密钥对来获取访问令牌。 对于用户身份验证,您可以使用不同的授权流程(SAML2,授权代码等),但是要验证客户端OAuth应用程序,您必须传递应用程序详细信息(因为您可以在系统中拥有多个应用程序,而Oauth服务器需要知道您所引用的应用程序)。 谢谢 sanjeewa。 Yes you need to have consumer/key secret pair to get access token. For user authentication you can use diff ...
-
在WSO2 IS文档中,我们可以为您的第一个问题找到答案: 与服务提供商合作 :服务提供商(SP)是提供Web服务的实体。 因此,SP是您公开API的Web服务。 对于第二个问题,答案是肯定的 。 这是可能的,WSO2套件有很多方法可以做到这一点,这取决于你想要做什么和如何做。 例如 : 您可以使用REST API在WSO2 ESB中公开您的API 。 然后,您可以使用BasicAuth 保护API 。 在doc示例中,它要求授权听众处理您的请求,因此重定向可能发生在BasicAuthHandler实现或使 ...
-
MSF4J:wso2访问服务提供商用户访问令牌到期时间(MSF4J: wso2 access service provider User Access Token Expiry Time)[2024-03-14]
我找到了解决方案OAuth2Util.getAuthzRequestContext()。getValidityPeriod()结果以毫秒为单位。 I found the soloution OAuth2Util.getAuthzRequestContext().getValidityPeriod() The result is in milliseconds. -
WSO2是否支持类似于: https : //docs.wso2.com/display/AM190/Exchanging+SAML2+Bearer+Tokens+with+OAuth2+-+SAML+Extension+Grant+Type使用JWT而不是SAML? 是的,它确实。 我们为此实施了JWT Bearer Grant。 JWT Grant背后的想法是,可以将由可信IDP发布的根据[1]有效的签名JWT交换为access_token。 按照[2]试用JWT Bearer Grant。 Faceb ...
-
我认为Store API拥有您需要的一切: 用户注册:创建新用户, 添加订阅:订阅API, 生成应用程序密钥:为应用程序生成密钥和机密值。 I think Store APIs have everything you need: User Signup: creates new user, Add a Subscription: subscribes to API, Generate an Application Key: generates the key and secret values for an ...