-2

我正在从服务器读取文件。我的应用程序崩溃并且我的 logcat 也没有显示任何错误。在此之前我遇到了窗口泄漏错误,但是当我评论我的对话框代码时,我的 logcat 中没有任何错误。

服务器代码如下:

public class serv extends ListActivity {
    private String m_urlString="http://192.168.1.30/muneem/muneem.php?path=./";
//    private String result;

    private List<String> m_item = null;
    private List<String> m_path = null;
    private String m_root="http://192.168.1.30/muneem/muneem.php?path=./";
    private String m_result;
    private TextView m_myPath;
    static private String m_pos;
    private String m_backposition;
    private String m_fileURL;


    int m_downloadedSize = 0;
    int m_totalSize = 0;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.file_chooser);

        View v= findViewById(R.id.rowtext);


        m_myPath = (TextView)findViewById(R.id.path);
        m_fileURL="http://192.168.1.30/muneem/";
        Http_connection f=new Http_connection();
        f.execute("");


    }

    class Http_connection extends AsyncTask<String, Void, Void> {

        private Exception exception;

        protected Void  doInBackground(String... urls)
        {

            try
            {
                URL url= new URL(m_urlString);
                HttpURLConnection con=(HttpURLConnection)url.openConnection();
                con.setRequestMethod("GET");
                con.connect();
                int statusCode=con.getResponseCode();
                if (statusCode==HttpURLConnection.HTTP_OK){
                    BufferedReader in= new BufferedReader(new InputStreamReader(con.getInputStream()));
                    String line;
                    m_result="";
                    while ((line=in.readLine())!=null)
                    {
                        m_result=m_result+"\n"+line;
                    }
                    in.close();
                    con.disconnect();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            getDir(m_urlString);


                        }
                    });

                }
            }
            catch (MalformedURLException e)
            {
                //            bundle.putString("Error","Problem with URL");

            }
            catch (IOException e)
            {
                //              bundle.putString("Error","Problem with connection");

            }


            return null;
        }
    }


    private void getDir(String dirPath)
    {


        String[] r=m_result.split("/");
        m_myPath.setText("Location: " + dirPath);
        m_item = new ArrayList<String>();
        m_path = new ArrayList<String>();

        for (int k=0;k<r.length;k++)
        {
            if (r[k].contains("."))
            {
                m_item.add(r[k]);

            }
            else
            {
                m_item.add(r[k]+"/");
            }
        }


        ArrayAdapter<String> fileList =
                new ArrayAdapter<String>(serv.this, R.layout.row, m_item);
        setListAdapter(fileList);

    }


    class getfile extends AsyncTask<String, Void, Void> {

        private Exception exception;

        protected Void  doInBackground(String... urls)
        {
            int count=0;
            try {
                //  urlSt="http://192.168.1.30/muneem/oglPrahova/prahova.GIS";

//                    URL uurl = new URL("http://192.168.1.30/muneem/oglPrahova/prahova.GIS");
                URL uurl = new URL(m_fileURL);

                BufferedReader in = new BufferedReader(new InputStreamReader(uurl.openStream()));
                String text_file="";
                String str;
                while ((str = in.readLine()) != null) {
                    text_file=text_file+str;

                }
                in.close();

                AppFuncs.g_path=text_file;
                AppFuncs.g_urlstring=m_urlString;



}

MapActivity调用服务器代码如下:

public class Map extends Activity
{
   //
    private GraphicsView mGLView;

    //private GisGLRenderer m_GisRenderer;

    final static String RESULT_KEY="result";
    final static int REQ_CODE=1001;
     AlertDialog m=null;



    public class LoadFile  extends AsyncTask<String,String,String>
    {

        ProgressDialog Asycdialog = new ProgressDialog(Map.this);

        @Override
        protected void onPreExecute() {
            //set message of the dialog
            Asycdialog.setMessage("Loading File");
            Asycdialog.setButton(DialogInterface.BUTTON_NEGATIVE,"Cancel",new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    //To change body of implemented methods use File | Settings | File Templates.
                }
            });
            super.onPreExecute();
        }

        protected void onProgressUpdate(String ... progress)
        {

        }

        protected String  doInBackground(String ... Params)
        {
            Map.this.mGLView.LoadProjectFile(AppFuncs.g_path);
            Map.this.mGLView.requestRender();
            return null;
        }
        protected void onPostExecute(String result)
        {
           }
    }




    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        mGLView =  (GraphicsView) findViewById(R.id.glview);


    }



  public void bt_Open(View v)
    {

        AlertDialog.Builder builder=new AlertDialog.Builder(this);
        builder.setTitle("Load File");
        builder.setMessage("Choose an option to load file")
                .setCancelable(false)
                .setNegativeButton("Server",new DialogInterface.OnClickListener(){
                   public void onClick(DialogInterface dialog,int which)
                   {
                       Intent i= new Intent(Map.this,serv.class);
                       startActivityForResult(i,REQ_CODE);

                   }

                }

                )
                .setPositiveButton("SDcard",new DialogInterface.OnClickListener()
                {
                    public void onClick(DialogInterface dialog, int which)
                    {

                        Intent i= new Intent(Map.this,FileChooser.class);
                        startActivityForResult(i,REQ_CODE);

                    }

                }

                );

        final AlertDialog a=builder.create();
        a.show();
}
 protected void onActivityResult(int requestCode, int resultCode,Intent data)
    {
        //super.onActivityResult(requestCode,resultCode,data);
        if(requestCode==REQ_CODE)
        {
            if(resultCode==RESULT_OK && data.getExtras().containsKey(RESULT_KEY))
            {

            //    Toast.makeText(this,data.getExtras().getString(RESULT_KEY),Toast.LENGTH_SHORT).show();
           //     this.mGLView.m_SelectedProjectPath =  AppFuncs.path;

                LoadFile f= new LoadFile();
                f.execute("");


             //   this.mGLView.LoadProjectFile(AppFuncs.path);
            }
        }
    }
4

2 回答 2

0

添加以下使用权限,1. 写入外部存储 2. 清单中的 Internet 权限

于 2013-08-20T11:43:59.550 回答
0

在 Manifest 中添加了 Internet 的使用权限?

<uses-permission android:name="android.permission.INTERNET" />

于 2013-08-20T11:23:20.337 回答