我收到错误:
Error:(109, 18) error: non-static method getIntent() cannot be referenced from a static context
Run Code Online (Sandbox Code Playgroud)
在线上:
init(getIntent().getSerializableExtra(Const.EXTRA_DATA));
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
public static class Upper_fragment extends Fragment {
private static final String TAG = "PlayActivity";
private Video vid;
int mSavedVideoPosition;
protected VideoPlayerInterface vidp;
private LocalSingleHttpServer mServer;
// to be implemented in concrete activities
public Cipher getCipher() throws GeneralSecurityException {
final Cipher c = Cipher.getInstance("AES"); // NoSuchAlgorithmException, NoSuchPaddingException
c.init(Cipher.DECRYPT_MODE, new SecretKeySpec("abcdef1234567890".getBytes(), "AES")); // InvalidKeyException
return c;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View upperView = inflater.inflate(R.layout.upper_fragment, container, false);
vidp = (VideoPlayerInterface) upperView.findViewById(R.id.vid);
getRTSPUrl();
init(getIntent().getSerializableExtra(Const.EXTRA_DATA));
return upperView;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是什么?怎么解决?
这是下一个代码的另一个错误错误:(120,21)错误:非静态方法runOnUiThread(Runnable)无法从静态上下文引用.我该如何纠正呢.请帮忙
public static class Upper_fragment extends Fragment {
private static final String TAG = "PlayActivity";
private Video vid;
int mSavedVideoPosition;
protected VideoPlayerInterface vidp;
private LocalSingleHttpServer mServer;
// to be implemented in concrete activities
public Cipher getCipher() throws GeneralSecurityException {
final Cipher c = Cipher.getInstance("AES"); // NoSuchAlgorithmException, NoSuchPaddingException
c.init(Cipher.DECRYPT_MODE, new SecretKeySpec("abcdef1234567890".getBytes(), "AES")); // InvalidKeyException
return c;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View upperView = inflater.inflate(R.layout.upper_fragment, container, false);
vidp = (VideoPlayerInterface) upperView.findViewById(R.id.vid);
getRTSPUrl();
init(getActivity().getIntent().getSerializableExtra(Const.EXTRA_DATA));
return upperView;
}
public void getRTSPUrl() {
final ProgressDialog dia = ProgressDialog
.show(getActivity(), null, "Loading...");
new Thread(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
dia.dismiss();
try {
mServer = new LocalSingleHttpServer();
final Cipher c = getCipher();
if (c != null) {// null means a clear video ; no need to set a decryption processing
mServer.setCipher(c);
}
mServer.start();
String path = getPath();
path = mServer.getURL(path);
vidp.setVideoPath(path);
vidp.play();
} catch (Exception e) {
startActivity(new Intent(getActivity(), MainActivity.class));
}
}
});
}
}).start();
}
Run Code Online (Sandbox Code Playgroud)
问题是什么?
你正在呼唤getIntent()一个Fragment
怎么解决?
你必须在getActivity()之前打电话getIntent()
例如 :
init(getActivity().getIntent().getSerializableExtra(Const.EXTRA_DATA));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2468 次 |
| 最近记录: |