这是我的第一堂课的一些代码
result = "ok&rent##18##20000000##80##500000##2##shofaj --- kaf parkeet ....##http://www.studentuniverse.com/student-blog/wp-content/uploads/2013/07/iStock_000017716462Medium-e1374689640445.jpg##http://www.studentuniverse.com/student-blog/wp-content/uploads/2013/07/apps.jpeg## " ;
String []respon = result.split("&");
Intent in = new Intent(getApplicationContext(), Show_item_select.class);
in.putExtra("url", respon[1]);
in.putExtra("code", Select_Data.get_id());
in.putExtra("itm",itm);
in.putExtra("urls", urls);
startActivity(in);
这是我的secend类的一些代码
String s= getIntent( ).getStringExtra("url");
code = getIntent().getStringExtra("code");
itm =getIntent().getIntExtra("itm",0);
urls = s.split("##");
urls_all = getIntent().getStringExtra("urls");
当progrom转到secend类并读取第一行程序stoped并显示写入Source not found的页面时,这是主题:
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2032.
DalvikVM[localhost:8602]
Thread [<1> main] (Suspended)
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2032
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2135
ActivityThread.access$700(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 140
ActivityThread$H.handleMessage(Message) line: 1237
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 137
ActivityThread.main(String[]) line: 4921
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 511
ZygoteInit$MethodAndArgsCaller.run() line: 1038
ZygoteInit.main(String[]) line: 805
NativeStart.main(String[]) line: not available [native method]
Thread [<10> Binder_2] (Running)
Thread [<9> Binder_1] (Running)
Thread [<11> Binder_3] (Running)
Thread [<12> AsyncTask #1] (Running)
Thread [<13> AsyncTask #2] (Running)
Thread [<14> AsyncTask #3] (Running)
任何人都知道为什么会这样?
答案 0 :(得分:2)
尝试并更改
String s = getIntent().getStringExtra("url");
的
String s = getIntent().getExtras().getString("url");
检查 extras 捆绑包是否已初始化也是一种很好的做法,如下所示.-
String s = null;
Bundle extras = getIntent().getExtras();
if (extras != null) {
s = extras.getString("url");
}
最后,您应该考虑使用常量作为额外名称,以确保将来不会出现拼写错误。