我真的没有得到我的代码中究竟不起作用的内容。获得以下错误。
lines = sc.textFile("/user/ahouskova/movies/my.data")
columns_data = lines.map(lambda line: line.split("\t"))
ratings = columns_data.map(lambda c: (c[1], (c[2], 1.0)))
movie_ratings_total_counts = ratings.reduceByKey(lambda m1, m2: (m1[0] + m2[0], m1[1] + m2[1]))
avg_ratings = movie_ratings_total_counts.mapValues(lambda total: round(float(total[0])/total[1]))
sorted_by_avg_rtg = avg_ratings.sortBy(lambda x: x[1])
以下是我的代码
以下是MainActivity.java
Process: com.example.pash.myapplication, PID: 10139
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pash.myapplication/com.example.pash.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #25: Binary XML file line #25: Error inflating class com.google.android.exoplayer2.ui.SimpleExoPlayerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
以下是activity_main.xml
package com.example.pash.myapplication;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.SurfaceView;
import android.view.View;
import android.widget.SeekBar;
import com.example.myapplication.PreviewSeekBar;
import com.example.myapplication.PreviewSeekBarLayout;
import com.example.pash.myapplication.exoplayer.ExoPlayerManager;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener,
Toolbar.OnMenuItemClickListener {
private static final int PICK_FILE_REQUEST_CODE = 2;
private ExoPlayerManager exoPlayerManager;
private PreviewSeekBarLayout seekBarLayout;
private PreviewSeekBar seekBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SimpleExoPlayerView playerView = (SimpleExoPlayerView) findViewById(R.id.player_view);
SimpleExoPlayerView previewPlayerView
= (SimpleExoPlayerView) findViewById(R.id.previewPlayerView);
seekBar = (PreviewSeekBar) playerView.findViewById(R.id.exo_progress);
seekBarLayout = (PreviewSeekBarLayout) findViewById(R.id.previewSeekBarLayout);
seekBarLayout.setTintColorResource(R.color.colorPrimary);
seekBar.addOnSeekBarChangeListener(this);
exoPlayerManager = new ExoPlayerManager(playerView, previewPlayerView, seekBarLayout);
exoPlayerManager.play(Uri.parse(getString(R.string.url_hls)));
seekBarLayout.setup(exoPlayerManager);
View view = previewPlayerView.getVideoSurfaceView();
if (view instanceof SurfaceView) {
SurfaceView surfaceView = (SurfaceView) view;
surfaceView.setZOrderMediaOverlay(true);
surfaceView.setZOrderOnTop(true);
surfaceView.setVisibility(View.INVISIBLE);
}
requestFullScreenIfLandscape();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_FILE_REQUEST_CODE && resultCode == RESULT_OK && data != null) {
exoPlayerManager.play(data.getData());
}
}
@Override
public void onStart() {
super.onStart();
exoPlayerManager.onStart();
}
@Override
public void onResume() {
super.onResume();
exoPlayerManager.onResume();
}
@Override
public void onPause() {
super.onPause();
exoPlayerManager.onPause();
}
@Override
public void onStop() {
super.onStop();
exoPlayerManager.onStop();
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
exoPlayerManager.stopPreview();
}
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.action_local) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("video/*.mp4");
startActivityForResult(intent, PICK_FILE_REQUEST_CODE);
} else if (item.getItemId() == R.id.action_toggle) {
if (seekBarLayout.isShowingPreview()) {
seekBarLayout.hidePreview();
exoPlayerManager.stopPreview();
} else {
seekBarLayout.showPreview();
exoPlayerManager.loadPreview(seekBar.getProgress(), seekBar.getMax());
}
}
return true;
}
private void requestFullScreenIfLandscape() {
if (getResources().getBoolean(R.bool.landscape)) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
} else {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.main);
toolbar.setOnMenuItemClickListener(this);
}
}}
这是我的exoplayer_controls.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.pash.myapplication.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/app_name" />
</android.support.design.widget.AppBarLayout>
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="300dp"
app:controller_layout_id="@layout/exoplayer_controls"
/>
</android.support.design.widget.CoordinatorLayout>
它在setContentView(R.layout.activity_main)中显示错误;这一行。