Android XML提要类中的最终结果是错误的

Android XML提要类中的最终结果是错误的,android,eclipse,xml-parsing,rss,Android,Eclipse,Xml Parsing,Rss,因此,我试图为汽油价格创建一个XML提要程序,但是我认为类中存在som错误,而不是显示正确的结果,这是我选择的URL XML提要。我收到的错误消息表明出现了问题。这是我的班级 package org.me.myandroidstuff; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import ja

因此,我试图为汽油价格创建一个XML提要程序,但是我认为类中存在som错误,而不是显示正确的结果,这是我选择的URL XML提要。我收到的错误消息表明出现了问题。这是我的班级

package org.me.myandroidstuff;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

//import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class PetrolPriceActivity extends Menu 
{
    private TextView response;
    private TextView errorText;
    private String result;
    private String petrolPriceURL;
    private static final String TAG = "PetrolPrice";
    /** Called when the activity is first created. */
    @Override

    public void onCreate(Bundle savedInstanceState) 
    {

        response = (TextView)findViewById(R.id.title);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.list);

        Bundle extras = getIntent().getExtras();
        if(extras!=null){
        petrolPriceURL =extras.getString("URLString");
        }
        Log.v(TAG, "index=" + petrolPriceURL);

        // Get the TextView object on which to display the results


        try
        {
            // Get the data from the RSS stream as a string
            result =  petrolPriceString(petrolPriceURL);

            // Do some processing of the data to get the individual parts of the RSS stream
            // At some point put this processing into a separate thread of execution
            // Display the string in the TextView object just to demonstrate this capability
            // This will need to be removed at some point
            response.setText(result);
        }
        catch(Exception ae)
        {
             //Handle error
            response = (TextView)findViewById(R.id.title);
            response.setText("Error");
             //Add error info to log for diagnostics
        } 

    }

    // End of onCreate

    // Method to handle the reading of the data from the RSS stream
    private static String petrolPriceString(String urlString)throws IOException
    {
        String result = "";
        InputStream anInStream = null;
        int response = -1;
        URL url = new URL(urlString);
        URLConnection conn = url.openConnection();

        // Check that the connection can be opened
        if (!(conn instanceof HttpURLConnection))
                throw new IOException("Not an HTTP connection");
        try
        {
            // Open connection
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod("GET");
            httpConn.connect();
            response = httpConn.getResponseCode();
            // Check that connection is Ok
            if (response == HttpURLConnection.HTTP_OK)
            {
                // Connection is OK so open a reader 
                anInStream = httpConn.getInputStream();
                InputStreamReader in= new InputStreamReader(anInStream);
                BufferedReader bin= new BufferedReader(in);

                // Read in the data from the RSS stream
                String line = new String();
                while (( (line = bin.readLine())) != null)
                {
                    result = result + "\n" + line;
                }
            }
        }
        catch (Exception ex)
        {
                throw new IOException("Error connecting");
        }

        // Return result as a string for further processing
        return result;
    }
    // End of petrolPriceString
 // End of Activity class
}
我的日志在我的logcat中显示,已成功地从我的其他类areaURL传递了正确的URL,但当我运行应用程序时,它并不正确。如果有任何帮助,我将不胜感激,因为我无法找出问题所在。谢谢

这是我的日志,显示URL是正确的

08-11 14:47:07.750: D/dalvikvm(889): GC_FOR_ALLOC freed 51K, 5% free 2943K/3076K, paused 37ms, total 39ms
08-11 14:47:07.760: I/dalvikvm-heap(889): Grow heap (frag case) to 3.553MB for 635812-byte allocation
08-11 14:47:07.950: D/dalvikvm(889): GC_FOR_ALLOC freed 0K, 4% free 3564K/3700K, paused 33ms, total 33ms
08-11 14:47:08.400: D/dalvikvm(889): GC_FOR_ALLOC freed <1K, 4% free 3569K/3700K, paused 25ms, total 26ms
08-11 14:47:08.430: I/dalvikvm-heap(889): Grow heap (frag case) to 7.220MB for 3840016-byte allocation
08-11 14:47:08.870: D/dalvikvm(889): GC_FOR_ALLOC freed 2K, 2% free 7316K/7452K, paused 187ms, total 187ms
08-11 14:47:09.430: I/Choreographer(889): Skipped 58 frames!  The application may be doing too much work on its main thread.
08-11 14:47:09.450: D/gralloc_goldfish(889): Emulator without GPU emulation detected.
08-11 14:47:11.690: I/Choreographer(889): Skipped 163 frames!  The application may be doing too much work on its main thread.
08-11 14:48:04.135: I/Choreographer(889): Skipped 43 frames!  The application may be doing too much work on its main thread.
08-11 14:48:16.055: I/Choreographer(889): Skipped 47 frames!  The application may be doing too much work on its main thread.
08-11 14:48:17.525: V/AreaURL(889): index=http://www.petrolprices.com/feeds/averages.xml?search_type=town&search_value=Glasgow
08-11 14:48:17.755: I/Choreographer(889): Skipped 67 frames!  The application may be doing too much work on its main thread.
08-11 14:48:18.615: V/PetrolPrice(889): index=http://www.petrolprices.com/feeds/averages.xml?search_type=town&search_value=Glasgow
08-11 14:48:20.215: I/Choreographer(889): Skipped 146 frames!  The application may be doing too much work on its main thread.
08-11 14:47:07.750:D/dalvikvm(889):全部释放51K,5%释放2943K/3076K,暂停37ms,总计39ms
08-11 14:47:07.760:I/dalvikvm堆(889):为635812字节分配将堆(frag案例)增长到3.553MB
08-11 14:47:07.950:D/dalvikvm(889):释放0千分之0,释放4%3564K/3700千分之0,暂停33毫秒,总计33毫秒

08-11 14:47:08.400:D/dalvikvm(889):GC_FOR_ALLOC freed您正在UI线程上下载提要。那是行不通的。使用线程或异步任务进行网络操作

    MvAsyncDownload dl = 
         new MvAsyncDownload(
              "http://www.example.com/rss.xml", 
              "/mnt/sdcard/rss.xml") { 
        Override 
        protected void onPostExecute(MvException result) { 
            if (result.mbSuccess) { 
              MvMessages.showMessage(this, "Downloaded"); 
            } else { 
              MvMessages.showMessage(this, "Failed " + result.msProblem );
            } 
            super.onPostExecute(result); 
        } 
    }; 

您是否从网站上收到错误消息?这是什么?您好,这个petrolPriceString()必须是一个线程或异步任务。不,我的代码中没有,我有一个try-and-catch块,错误来自这个抱歉的用户3586222,您能举个例子吗?如果您有TeamViewer将您的用户和pwd发送给我testeo080@gmail.com