5

Tôi đang phát triển Nguồn cấp dữ liệu RSS ứng dụng từ thư mục tài nguyên google cơ bản. Ngay bây giờ tôi đang hiển thị cả ba nội dung như được đề xuất trong ví dụ.Ví dụ Xmlapter không hoạt động .contains (bộ đọc danh bạ, nguồn cấp dữ liệu Rss, hiển thị ảnh)

1.Liên hệ. 2.Ảnh. 3.RSS Thức ăn

ở đây là liên kết:

RSS FIELD -xmladapters

tôi quản lý mã rất tốt theo yêu cầu của tôi .only thay đổi gói và Tên dự án. Nhưng màn Lỗi Fatal của nó:

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 

Trong LogCat bạn thấy rằng:

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

Tôi không biết tại sao điều này xảy ra hai lần.

Để biết thêm tôi hiển thị manifest.xml tôi ở đây: 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> 

hãy hướng dẫn cho tôi đâu là lỗi.

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

Đăng cũng có tệp 'res/xml/contacts.xml' –

Trả lời

1

Tôi đã truy cập lại ăn lỗi của bạn.Vấn đề là ở res/xml/contacts.xml tập tin của bạn

Thay đổi dòng này:

xmlns:app="com.satyamdswt.agreader" 

đến dòng này:

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

Đó là định dạng phù hợp của không gian tên XML của ứng dụng của bạn: http://schemas.android.com/apk/res/package_name

UPD : Bạn không nên thay đổi các thông số khác trong thẻ <cursor-adapter>. Biểu mẫu bên phải:

<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

..Tôi đã thay đổi tên gói. Nhưng nó vẫn không hoạt động. Tôi đã chỉnh sửa contacts.xm của mình. Xin vui lòng xem đó là định dạng đúng không? – NovusMobile

+0

@SDROIDRisk Không, không đúng. Xem cập nhật câu trả lời. –

0

Đặt contacts_list.xml trong thư mục bố trí của bạn http://developer.android.com/resources/samples/XmlAdapters/res/layout/contacts_list.html

Tải file từ ở đây và đặt trong thư mục bố trí của bạn http://developer.android.com/resources/samples/XmlAdapters/res/layout/index.html

EDIT

Tôi nghĩ rằng lỗi là với tập tin này http://developer.android.com/resources/samples/XmlAdapters/res/xml/contacts.html

Hãy kiểm tra xem bạn có cách bố trí "contact_item" trong thư mục bố trí của bạn

Bạn có thể tìm thấy ở đây - http://developer.android.com/resources/samples/XmlAdapters/res/layout/contact_item.html

+0

Thư mục đã có trong thư mục bố cục. – NovusMobile

+0

Bạn đã thực hiện bất kỳ thay đổi nào đối với ContactListActivity chưa? Nếu vậy, hãy đăng chúng ở đây – Slartibartfast

+0

Tôi đã thêm mã cho ContactListActivity. nếu bạn yêu cầu nhiều hơn xin vui lòng cho tôi biết.Have bạn đã làm loại mã này? – NovusMobile

Các vấn đề liên quan