简体   繁体   中英

java.lang.NullPointerException error only from Galaxy samsung

I received some reports of this error, but I have test equipment and everything goes right. Strange is that all error reports are sent from mobile samsung. Any idea what could be if I can not resolve it? error code:

Ú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)

Java:

    @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");
    }
}

I think the problem comes from here:

        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);
        }
    });

but as I said I tried everything on android devices and on the emulator and things are working. But this error appears on Samsung devices. Thank you.

The stack trace seems pretty clearly to point to the anonymous inner class instantiated for variable mOnClickListener . This is the first inner class, in source order, appearing in class TorrentPlayerFragment (as indicated by the stack trace), and it contains an invocation of the method reported as throwing the NPE: android.os.Bundle.getString(java.lang.String) . Specifically,

            Bundle args = getArguments();
            mStreamUrl  = args.getString("url");

It seems pretty likely that getArguments() is returning null in the affected environment. This seems related to Android Fragment getArguments() returns null , but I cannot be confident that the circumstances or solutions are the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM