0

データを解析してテキストビューに表示しています。マニフェストファイルで作成するすべての変数と必要な権限を初期化しましたが。それでも致命的なエラーが発生します。コードを見てください。前もって感謝します。

Android 2.1 i.ie API-7 を使用すると、アプリケーションは正常に実行されますが、Android 4.0.3 に置き換えると、つまり API-15..logcat ファイルで述べたように、同じ reeor がスローされます。

主な活動

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

View layout = findViewById(R.id.layout);


TextView id[];
TextView Name[];
TextView Email[];
TextView Address[];


try{
    SAXParserFactory saxPF= SAXParserFactory.newInstance();
     SAXParser saxP = saxPF.newSAXParser();
     XMLReader xmlR = saxP.getXMLReader();

     URL url = new URL("http://xyz");

     XMLHandler myXMLHandler = new XMLHandler();
     xmlR.setContentHandler(myXMLHandler);
     xmlR.parse(new InputSource(url.openStream()));

}catch(Exception e){
    e.printStackTrace();
}


data= XMLHandler.data;

id = new TextView[data.getId().size()];
Name = new TextView[data.getName().size()];
Email = new TextView[data.getEmail().size()];


for(int i=0 ; i <data.getName().size(); i++)
{
    id[i] = new TextView (this);
    id[i].setText("Id : " + data.getId().get(i));


    Name[i] = new TextView(this);
    Name[i].setText("Name : " + data.getName().get(i));


    Email[i] = new TextView(this);
    Email[i].setText("Email : " + data.getEmail().get(i));


((ViewGroup)layout).addView(id[i]);
((ViewGroup)layout).addView(Name[i]);   
((ViewGroup)layout).addView(Email[i]);


}

XMLGettersSetters クラス

public class XMLGettersSetters {

    private ArrayList<String> id = new ArrayList<String>();
    private ArrayList<String> Name = new ArrayList<String>();
    private ArrayList<String> Email = new ArrayList<String>();


    public ArrayList<String> getId(){

        return id;
    }

    public void setId(String id){
        this.id.add(id);
    }



    public ArrayList<String> getName(){
        return Name;
    }

    public void setName(String name)
    {
        this.Name.add(name);
    }



    public ArrayList<String> getEmail(){
        return Email;

    }
    public void setEmail(String email){
        this.Email.add(email);

    }




}

XMLHandler クラス

public class XMLHandler extends DefaultHandler {
    String elementValue= null;
    Boolean elementOn = false;
    public static XMLGettersSetters data = null;

    public static XMLGettersSetters getXMLData(){
        return data;
    }

    public static void setXMLData(XMLGettersSetters data)
    {
        XMLHandler.data=data;
    }



    public void startElement(String uri,String localName,String qName,Attributes attributes) throws SAXException{
        elementOn=true;



        if(localName.equals("ExaReceipts")){
            data = new XMLGettersSetters();

        }else if(localName.equals("Organisation")){
    }
    }

    public void endElement(String uri,String localName,String qName)throws SAXException
    {

        elementOn = false;

        if(localName.equalsIgnoreCase("id"))
            data.setId(elementValue);

        else if(localName.equalsIgnoreCase("Name"))
            data.setName(elementValue);

        else if(localName.equalsIgnoreCase("Email"))
        data.setEmail(elementValue);
    }



    public void characters (char[] ch , int start , int length)throws SAXException
    { 
        if(elementOn){
            elementValue= new String(ch,start,length);
            elementOn=false;
        }

    }

}

AndroidManifest.xml

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

    <uses-sdk android:minSdkVersion="15" />
 <uses-permission android:name="android.permission.INTERNET" />"
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".SpinnerTest1Activity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

ログキャット

06-26 17:41:38.482: W/dalvikvm(2129): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 
06-26 17:41:38.492: E/AndroidRuntime(2129): FATAL EXCEPTION: main 
06-26 17:41:38.492: E/AndroidRuntime(2129): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spinnertest1/com.spinnertest1.SpinnerTest1Activity}: java.lang.NullPointerException 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at android.app.ActivityThread.access$600(ActivityThread.java:123) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at android.os.Handler.dispatchMessage(Handler.java:99) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at android.os.Looper.loop(Looper.java:137) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at android.app.ActivityThread.main(ActivityThread.java:4424) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at java.lang.reflect.Method.invokeNative(Native Method) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at java.lang.reflect.Method.invoke(Method.java:511) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at dalvik.system.NativeStart.main(Native Method)
06-26 17:41:38.492: E/AndroidRuntime(2129): Caused by: java.lang.NullPointerException 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at com.spinnertest1.SpinnerTest1Activity.onCreate(SpinnerTest1Activity.java:58) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at android.app.Activity.performCreate(Activity.java:4465) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
06-26 17:41:38.492: E/AndroidRuntime(2129):     ... 11 more
4

1 に答える 1

0

メソッドを呼び出していますexecute()か?

execute(URL);

URL http://exareceipts.exa.com.au/request_queue/invoice_request/get_test_data

あなたが使用しているはXMLタグではありません。

于 2012-06-26T12:01:43.483 に答える