[英]android sorry application has stopped unexpectedly
The following code works fine without any errors but when i try to get the url through intent i get the error the application stopped unexpectedly. 以下代码可以正常运行,没有任何错误,但是当我尝试通过意图获取url时,我得到了错误,应用程序意外停止。 can anyone please help me out.
谁能帮帮我。
public class MjpegSample extends Activity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String URL = "http://121.6.98.160:8081/videostream.cgi?"
+ "user=admin&pwd=admin&resolution=8";
}
}
The following code make the error when i replace the above code: 当我替换上面的代码时,以下代码使错误:
public class MjpegSample extends Activity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String URL;
Bundle extras = getIntent().getExtras();
URL = extras.getString("flink");
}
}
To get the "flink" by intent i use the following 要通过意图获取“ flink”,请使用以下命令
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b1 = (Button) findViewById(R.id.viewcam);
t=(EditText)findViewById(R.id.username);
p=(EditText)findViewById(R.id.password);
i=(EditText)findViewById(R.id.ip);
po=(EditText)findViewById(R.id.port);
b1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
String tt=t.getText().toString();
String pp=p.getText().toString();
String ii=i.getText().toString();
String por=po.getText().toString();
String link="http://"+ii+":"+por
+"/videostream.cgi?user="+tt
+"&pwd="+pp+"resolution=8";
Intent myIntent = new Intent(v.getContext(), MjpegSample.class);
myIntent.putExtra("flink",link);
startActivityForResult(myIntent, 0);
}
});
}
Try to replace v.getContext()
with NameOfCurrentActivity.this
, Also check in the other Activity: 尝试更换
v.getContext()
与NameOfCurrentActivity.this
,同时检查在其他活动:
if (extras != null)
{
// do your thing
}
您应该直接从意图而不是从额外内容获得url:
getIntent().getString("flink")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.