您好,我倾向于使用YouTubePlayerView小部件夸大布局,但是我遇到了以下错误:
$(anchor).on('click', click);
可能出错的是什么?有人能帮我吗 ? 以下是我的课程。
ListaVideosTeste.java
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pedro.masterwc, PID: 770
android.view.InflateException: Binary XML file line #10: Error inflating class com.google.android.youtube.player.YouTubePlayerView
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at com.example.pedro.masterwc.Adapters.VideoAdapter.getView(VideoAdapter.java:45)
at android.widget.AbsListView.obtainView(AbsListView.java:2347)
at android.widget.ListView.makeAndAddView(ListView.java:1864)
at android.widget.ListView.fillDown(ListView.java:698)
VideoAdapter.java
class ListaVideosTeste extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {
ArrayList<Videos> videosList;
VideoAdapter adapter;
public static final String API_KEY = "AIzaSyDveKkSzopPSk7ck4ZDbR9YGBe4Mm35DYY";
private YouTubePlayer youTubePlayer;
private YouTubePlayerView youTubePlayerView;
private YouTubeThumbnailView youTubeThumbnailView;
private YouTubeThumbnailLoader youTubeThumbnailLoader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rows);
videosList = new ArrayList<Videos>();
new ListaVideosTeste.JSONAsyncTask().execute("http://www.masterwebchef.com.br/wsmwc/teste/get_videos_channel4.php");
//cria a lista e exibi os dados retornados do json
ListView listview = (ListView)findViewById(R.id.list_v);
adapter = new VideoAdapter(getApplicationContext(), R.layout.teste, videosList);
listview.setAdapter(adapter);
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult result) {
Toast.makeText(getApplicationContext(),
"Houve um erro ao carregar o video!",
Toast.LENGTH_LONG).show();
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
youTubePlayer = player;
Toast.makeText(getApplicationContext(),
"Video carregado com sucesso!",
Toast.LENGTH_LONG).show();
if (!wasRestored) {
player.cueVideo(VIDEO_ID);
}
}
//faz a conexao com a URL do Json
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(ListaVideosTeste.this);
dialog.setMessage("Por favor, aguarde...");
dialog.setTitle("Conectando ao servidor");
dialog.show();
dialog.setCancelable(false);
}
//Recebe os dados do Json
@Override
protected Boolean doInBackground(String... urls) {
try {
//------------------>>
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray("channel1");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
Videos v = new Videos();
v.setTitle(object.getString("title"));
v.setDescription(object.getString("description"));
v.setLink_to_youtube(object.getString("youtube_embed"));
//v.setCountry(object.getString("country"));
//v.setHeight(object.getString("height"));
//v.setSpouse(object.getString("spouse"));
//v.setChildren(object.getString("children"));
v.setImage(object.getString("image"));
videosList.add(v);
}
return true;
}
//------------------>>
} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
dialog.cancel();
adapter.notifyDataSetChanged();
if(result == false)
Toast.makeText(getApplicationContext(), "Não foi possivel acessar o servidor...", Toast.LENGTH_LONG).show();
}
}
布局teste.xml