-1
class loadhtml extends AsyncTask<String,Void,String>{

    ProgressDialog mProgressDialog;
    public static final String TAG_VIDEO="data";
    JSONArray data = null;


    @Override
    protected void onPreExecute() {

        mProgressDialog=new ProgressDialog(LatestVideoActivity.mContext);
        mProgressDialog.setTitle("Fetech Video...");
        mProgressDialog.setMessage("Please Wait...");
        mProgressDialog.setCancelable(false);
        mProgressDialog.show();
    }


    @Override
    protected String doInBackground(String... params) {
        String response="";

          try{
            String url="http://twominenglish.com/api/getvideo?videoid="+ videoId;
            response = sendRequest(url);


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

        return response;
    }



    @Override
    protected void onPostExecute(String result) {
        //mProgressDialog.dismiss();
          if (!result.equalsIgnoreCase("")) {

                try {

                    JSONObject mainObject = new JSONObject(result);

                    if (mainObject.has("ID")) {
                         id = mainObject.getString("ID");
                            // Toast.makeText(getBaseContext(), ""+id, Toast.LENGTH_SHORT).show();
                    }

                    if (mainObject.has("VideoID")) {
                        mVideoId = mainObject.getString("VideoID");
                    //Toast.makeText(getBaseContext(), ""+videoId, Toast.LENGTH_SHORT).show();
                    }

                    if (mainObject.has("Title")) {
                         title = mainObject.getString("Title");
                        //Toast.makeText(getBaseContext(), ""+title, Toast.LENGTH_SHORT).show();
                    }

                    if (mainObject.has("Description")) {
                        desc = mainObject.getString("Description");
                        //Toast.makeText(getBaseContext(), ""+desc, Toast.LENGTH_SHORT).show();

                    }

                    if (mainObject.has("Script")) {
                        script = mainObject.getString("Script");
                        // Toast.makeText(getBaseContext(), ""+script, Toast.LENGTH_SHORT).show();

                    }

                    if (mainObject.has("Phrases")) {
                         phrases = mainObject.getString("Phrases");
                        //Toast.makeText(getBaseContext(), ""+phrases, Toast.LENGTH_SHORT).show();

                    }

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

                } finally {



                        mProgressDialog.dismiss();



                            Matcher matcher = Pattern.compile("http://www.youtube.com/embed/").matcher(mVideoId);
                            //Exampe of full path of youtube="http://www.youtube.com/embed/4oceDC_w6uY;

                            matcher.find();
                        //  Uri my =Uri.parse("http://www.youtube.com/embed/" +mVideoId);
                            Intent lVideoIntent = new Intent(
                                    null,
                                    Uri.parse("ytv://" + matcher.group(1)),
                                    LatestVideoActivity.mContext,
                                    com.astrobix.youtube.OpenYouTubePlayerActivity.class);
                                    startActivity(lVideoIntent);










                }
            }

        }

        public String sendRequest(String url) {
            String result = "";
            try {

                HttpClient client = new DefaultHttpClient();
                HttpParams httpParameters = client.getParams();
                HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
                HttpConnectionParams.setSoTimeout(httpParameters, 5000);
                HttpConnectionParams.setTcpNoDelay(httpParameters, true);
                HttpGet request = new HttpGet();
                request.setURI(new URI(url));
                HttpResponse response = client.execute(request);
                InputStream ips = response.getEntity().getContent();

                BufferedReader buf = new BufferedReader(new InputStreamReader(ips,
                        "UTF-8"));

                StringBuilder sb = new StringBuilder();
                String s;
                while (true) {
                    s = buf.readLine();
                    if (s == null || s.length() == 0)
                        break;
                    sb.append(s);

                }
                buf.close();
                ips.close();
                result = sb.toString();

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

            return result;
  }

当我运行此代码时,它显示异常:

“java.lang.IllegalStateException:到目前为止没有成功匹配”“在 java.util.regex.Matcher.ensureMatch(Matcher.java:607)”“在 java.util.regex.Matcher.group(Matcher.java:358) "

4

1 回答 1

0

删除您的模式匹配器:

                        Matcher matcher = Pattern.compile("http://www.youtube.com/embed/").matcher(mVideoId);
                        //Exampe of full path of youtube="http://www.youtube.com/embed/4oceDC_w6uY;

                        matcher.find();

并替换Uri.parse("ytv://" + matcher.group(1)),Uri.parse("ytv://" + mVideoId),

于 2013-07-16T06:33:56.523 回答