5

我正在开发RSS订阅应用程序从基本的谷歌资源文件夹。 现在我将所有三个内容显示为示例中的建议。Xmlapter示例不工作.contains(联系阅读器,Rss订阅源,照片显示)

1.Contacts。 2.照片。 3.RSS饲料

这里是链接:

RSS FIELD -xmladapters

我托管的代码非常好按我的要求。只有更改包和项目名称。 但其显示致命错误:

logcat的:

04-09 17:40:02.894: E/AndroidRuntime(770): FATAL EXCEPTION: main 
    04-09 17:40:02.894: E/AndroidRuntime(770): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.satyamdswt.agreader/com.satyamdswt.agreader.ContactsListActivity}: java.lang.IllegalArgumentException: The layout specified in contacts does not exist 
    04-09 17:40:02.894: E/AndroidRuntime(770): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at android.os.Handler.dispatchMessage(Handler.java:99) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at android.os.Looper.loop(Looper.java:123) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at android.app.ActivityThread.main(ActivityThread.java:3683) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at java.lang.reflect.Method.invokeNative(Native Method) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at java.lang.reflect.Method.invoke(Method.java:507) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at dalvik.system.NativeStart.main(Native Method) 
    04-09 17:40:02.894: E/AndroidRuntime(770): Caused by: java.lang.IllegalArgumentException: The layout specified in contacts does not exist 
    04-09 17:40:02.894: E/AndroidRuntime(770): at com.satyamdswt.agreader.Adapters$XmlCursorAdapterParser.parse(Adapters.java:219) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at com.satyamdswt.agreader.Adapters.createCursorAdapter(Adapters.java:168) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at com.satyamdswt.agreader.Adapters.createAdapterFromXml(Adapters.java:151) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at com.satyamdswt.agreader.Adapters.loadAdapter(Adapters.java:105) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at com.satyamdswt.agreader.Adapters.loadAdapter(Adapters.java:92) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at com.satyamdswt.agreader.ContactsListActivity.onCreate(ContactsListActivity.java:12) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
    04-09 17:40:02.894: E/AndroidRuntime(770): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
    04-09 17:40:02.894: E/AndroidRuntime(770): ... 11 more 

在logcat中您将看到:

com.satyamdswt.agreader/com.satyamdswt.agreader.ContactsListActivity 

我不知道为什么会这样两次。

因为在这里我越显示我的Manifest.xml: 的Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.satyamdswt.agreader" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="10" /> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.READ_CONTACTS"/> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".ContactsListActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 

     </activity> 

     <activity android:name="PhotosListActivity" 
        android:label="@string/photos_list_activity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <activity android:name=".AGRssReaderActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

    </application> 

</manifest> 

请指引我哪里出错。

ContactListActivity.java

public class ContactsListActivity extends ListActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.contacts_list); 
     setListAdapter(Adapters.loadAdapter(this,R.xml.contacts)); 
    } 

} 

EDITED contacts.xml

<?xml version="1.0" encoding="utf-8"?> 
<cursor-adapter xmlns:android="com.satyamdswt.agreader" 
    xmlns:app="http://schemas.android.com/apk/res/com.satyamdswt.agreader" 
    android:layout_width="@layout/contact_item" 
    app:selection="has_phone_number = 1 " 
    app:uri="content://com.satyamdswt.contacts/contacts" > 



    <bind 
     app:from="display_name" 
     app:to="@id/name" 
     app:as="string"/> 

    <bind 
     app:as="drawable" 
     app:from="starred" 
     app:to="@id/star" > 
     <map 
      app:fromValue="0" 
      app:toValue="@android:drawable/star_big_off" /> 
     <map 
      app:fromValue="1" 
      app:toValue="@android:drawable/star_big_on" /> 
    </bind> 
    <bind 
     app:as="com.satyamdswt.agreader.ContactPhotoBinder" 
     app:from="_id" 
     app:to="@id/name" /> 

</cursor-adapter> 
+0

也发布'res/xml/contacts.xml'文件 – 2012-04-13 12:32:41

回答

1

我recrr消除了你的错误。问题出在你的res/xml/contacts.xml文件

改变这一行:

xmlns:app="com.satyamdswt.agreader" 

这一行:

xmlns:app="http://schemas.android.com/apk/res/com.satyamdswt.agreader" 

这是你的应用程序的XML命名空间的正确格式为:http://schemas.android.com/apk/res/package_name

UPD :您不应更改​​标记中的其他参数。正确的形式:

<cursor-adapter xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res/com.satyamdswt.agreader" 
    app:uri="content://com.android.contacts/contacts" 
    app:selection="has_phone_number=1" 
    app:layout="@layout/contact_item"> 
+0

..我改变了packate name.But它仍然无法正常工作。 我编辑了我的contacts.xm。 请看这是正确的格式? – NovusMobile 2012-04-16 04:55:27

+0

@SDROIDRisk不,它是不正确的。查看答案的更新。 – 2012-04-16 13:07:35

0

把你的布局文件夹 http://developer.android.com/resources/samples/XmlAdapters/res/layout/contacts_list.html

contacts_list.xml从下载文件在这里,并在您的布局文件夹 http://developer.android.com/resources/samples/XmlAdapters/res/layout/index.html

编辑

我认为错误是与此文件 http://developer.android.com/resources/samples/XmlAdapters/res/xml/contacts.html

请检查你是否在你的布局文件夹中有布局“contact_item”

你可以在这里找到它 - http://developer.android.com/resources/samples/XmlAdapters/res/layout/contact_item.html

+0

它已经存在到布局文件夹中。 – NovusMobile 2012-04-11 12:43:49

+0

您是否对ContactListActivity进行过任何更改?如果是这样,请在这里发布 – Slartibartfast 2012-04-11 16:38:23

+0

我添加了ContactListActivity的代码。如果你需要更多请告诉我。你已经做过这种类型的代码了吗? – NovusMobile 2012-04-12 04:45:11