1

Android アプリで XML コンテンツを取得する簡単な方法を見つけようとしています。XOMを試してみました。XML の作成は問題ありませんが、一部を解析しようとすると、エミュレーターが強制終了してクラッシュします。どこを見たらいいのかわからない。

マニフェストにインターネット アクセス許可を設定しました。

デバッグ/変数で「適切な SAX2 パーサーが見つかりませんでした」と表示され、logcat で同じことがわかります

07-22 12:27:51.565: INFO/System.out(683): debugger has settled (1337)
07-22 12:27:52.034: INFO/dalvikvm(683): Could not find method org.apache.xerces.impl.Version.getVersion, referenced from method nu.xom.Builder.<clinit>
07-22 12:27:52.034: WARN/dalvikvm(683): VFY: unable to resolve static method 2371: Lorg/apache/xerces/impl/Version;.getVersion ()Ljava/lang/String;
07-22 12:27:52.044: DEBUG/dalvikvm(683): VFY: replacing opcode 0x71 at 0x000f
07-22 12:27:52.044: DEBUG/dalvikvm(683): VFY: dead code 0x0012-0049 in Lnu/xom/Builder;.<clinit> ()V
07-22 12:27:52.094: WARN/dalvikvm(683): Unable to resolve superclass of Lnu/xom/XML1_0Parser; (402)
07-22 12:27:52.094: WARN/dalvikvm(683): Link of class 'Lnu/xom/XML1_0Parser;' failed
07-22 12:27:52.104: ERROR/dalvikvm(683): Could not find class 'nu.xom.XML1_0Parser', referenced from method nu.xom.Builder.findParser
07-22 12:27:52.104: WARN/dalvikvm(683): VFY: unable to resolve new-instance 191 (Lnu/xom/XML1_0Parser;) in Lnu/xom/Builder;
07-22 12:27:52.104: DEBUG/dalvikvm(683): VFY: replacing opcode 0x22 at 0x0000
07-22 12:27:52.114: DEBUG/dalvikvm(683): VFY: dead code 0x0002-0007 in Lnu/xom/Builder;.findParser (Z)Lorg/xml/sax/XMLReader;
07-22 12:27:52.554: WARN/dalvikvm(683): Unable to resolve superclass of Lnu/xom/JDK15XML1_0Parser; (8)
07-22 12:27:52.554: WARN/dalvikvm(683): Link of class 'Lnu/xom/JDK15XML1_0Parser;' failed
07-22 12:27:58.441: WARN/ActivityManager(64): Launch timeout has expired, giving up wake lock!
07-22 12:27:58.996: WARN/ActivityManager(64): Activity idle timeout for HistoryRecord{44fdcb80 com.xb.xomtest/.main}

私が得られないことの1つは、ビルドパスにjarを追加するときの警告です。それと何か関係があるかどうかはわかりません:

[2011-07-22 14:38:13 - XOM] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(nu.xom.Element$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

コード:

package com.xb.xomtest;

import java.io.IOException;

import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.ParsingException;
import android.app.Activity;
import android.os.Bundle;

public class main extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        try {
              Builder parser = new Builder();
              Document doc = parser.build("http://www.cafeconleche.org/");
            }
            catch (ParsingException ex) {
              //System.err.println("Cafe con Leche is malformed today. How embarrassing!");
            }
            catch (IOException ex) {
              //System.err.println("Could not connect to Cafe con Leche. The site may be down.");
            }


    }
}
4

1 に答える 1

4

xom jar 自体には、必要なものがすべて含まれているわけではなく、適切なパーサーのリストに標準の Android パーサーが含まれていないようです。

http://www.xom.nu/install.xhtmlからの抜粋:

「Java 1.3 以前には XML パーサーが組み込まれていないため、これらの環境では XOM のサポート ライブラリもインストールする必要があります。これらには、xalan.jar、xercesImpl.jar、normalizer.jar、および xml-apis.jar が含まれます。 lib ディレクトリにあります。XOM に同梱されているバージョンは、JDK に同梱されているものよりもかなり高速でバグが少ないため、Java 1.4 以降でも使用することをお勧めします。"

基本的な解析では、xercesImpl.jar を xom-1.2.7.jar と共に追加するだけで十分なようです。同じ問題 (sax2 パーサーの欠落について不平を言う) があった私のコードは、入力を正常に解析するようになりました。

内部クラスについて同じ Dx 警告が表示されるため、致命的ではないようです :-)。

于 2011-08-25T10:00:42.597 に答える