我收到了一些关于此错误的报告,但我有测试设备,一切顺利。奇怪的是,所有错误报告都是从移动三星发送的。 知道如果我无法解决它可能会是什么? 错误代码:
Último informe
18 de jun. 4:57
Informes de esta semana
1
Informes totales
1
Versión de la aplicación
25
1
Versión de Android
Android 5.1
1
Dispositivo
Galaxy S6 Edge+ (zenlte) 1
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
at ro.vrt.videoplayerstreaming.TorrentPlayerFragment$1.onClick(TorrentPlayerFragment.java:107)
at android.view.View.performClick(View.java:5254)
at android.widget.TextView.performClick(TextView.java:10557)
at android.view.View$PerformClick.run(View.java:21203)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6897)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
爪哇:
@SuppressLint("SetTextI18n")
public class TorrentPlayerFragment extends Fragment implements TorrentListener {
private Button button2;
private Button button;
private ProgressBar progressBar;
private TorrentStream torrentStream;
String mStreamUrl;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.activity_torrent_player_fragment, container, false);
mStreamUrl = ((EditText) v.findViewById(R.id.bTorrentUrl)).getText().toString();
String action = getActivity().getIntent().getAction();
Uri data = getActivity().getIntent().getData();
if (action != null && action.equals(Intent.ACTION_VIEW) && data != null) {
try {
mStreamUrl = URLDecoder.decode(data.toString(), "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
TorrentOptions torrentOptions = new TorrentOptions.Builder()
.saveLocation(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS))
.removeFilesAfterStop(true)
.build();
torrentStream = TorrentStream.init(torrentOptions);
torrentStream.addListener(this);
button2 = (Button) v.findViewById(R.id.button2);
button2.setVisibility(View.GONE);
button = (Button) v.findViewById(R.id.button);
button.setOnClickListener(mOnClickListener);
progressBar = (ProgressBar) v.findViewById(R.id.progress);
progressBar.setMax(100);
return v;
}
@Override
public void onResume() {
super.onResume();
}
View.OnClickListener mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
progressBar.setProgress(0);
if(torrentStream.isStreaming()) {
torrentStream.stopStream();
button.setText("Start stream");
button2.setVisibility(View.GONE);
return;
}
Bundle args = getArguments();
mStreamUrl = args.getString("url");
torrentStream.startStream(mStreamUrl);
button2.setVisibility(View.GONE);
button.setText("Stop stream");
}
};
@Override
public void onStreamPrepared(Torrent torrent) {
Log.d("Torrent", "OnStreamPrepared");
torrent.startDownload();
}
@Override
public void onStreamStarted(Torrent torrent) {
Log.d("Torrent", "onStreamStarted");
}
@Override
public void onStreamError(Torrent torrent, Exception e) {
Log.e("Torrent", "onStreamError", e);
button.setText("Start stream");
}
@Override
public void onStreamReady(Torrent torrent) {
progressBar.setProgress(100);
Log.d("Torrent", "onStreamReady: " + torrent.getVideoFile());
final String UrlFinalTorrent = torrent.getVideoFile().toString();
button2.setVisibility(View.VISIBLE);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.putExtra("url", UrlFinalTorrent);
startActivity(intent);
}
});
}
@Override
public void onStreamProgress(Torrent torrent, StreamStatus status) {
if(status.bufferProgress <= 100 && progressBar.getProgress() < 100 && progressBar.getProgress() != status.bufferProgress) {
Log.d("Torrent", "Progress: " + status.bufferProgress);
progressBar.setProgress(status.bufferProgress);
}
}
@Override
public void onStreamStopped() {
Log.d("Torrent", "onStreamStopped");
}
}
我认为问题来自这里:
final String UrlFinalTorrent = torrent.getVideoFile().toString();
button2.setVisibility(View.VISIBLE);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.putExtra("url", UrlFinalTorrent);
startActivity(intent);
}
});
但正如我所说,我在Android设备和模拟器上尝试了一切,事情正在发挥作用。但是这个错误出现在三星设备上。 谢谢。
答案 0 :(得分:2)
堆栈跟踪似乎非常清楚地指向为变量mOnClickListener
实例化的匿名内部类。这是源类顺序中的第一个内部类,出现在类TorrentPlayerFragment
中(如堆栈跟踪所示),它包含对报告为抛出NPE的方法的调用:android.os.Bundle.getString(java.lang.String)
。具体地,
Bundle args = getArguments();
mStreamUrl = args.getString("url");
getArguments()
很可能在受影响的环境中返回null
。这似乎与Android Fragment getArguments() returns null有关,但我不能确信情况或解决方案是相同的。