trying to parse a fetched xml file from one class to another












0














im using android studio for a school project and im in the final stages now. the only thing i have left is for one class that has 2 spinners, one determining the program, and the other determining the semester, and a button that will then take those two spinners and spit out a URL pertaining to the schedule of that program and semester. The problem is, i dont know how to then take that spit out URL, and parse it into the other java class that displays a schedule. Below you will find the code attached, that works but doesnt display the correct schedule(since its hardcoded)



   StringBuffer sb = new StringBuffer();
sb.append("http://branko-cirovic.appspot.com/etcapp/timetables/timetable_"); sb.append(cid); sb.append(semester); sb.append(".xml");
loc = sb.toString();

Toast.makeText(ScheduleMainActivity.this,"You Selected : "
+ loc, Toast.LENGTH_SHORT).show();

Intent toy7 = new Intent(ScheduleMainActivity.this, TimetableMainActivity.class);
toy7.putExtra("Name", loc);
startActivity(toy7);


That is the activity where im creating the intent and using the putExtra to use the data in the next activity



 public class GetXML extends AsyncTask<String, Void, String> {
String src = null;
String loc = (String) getIntent().getExtras().get("Name");

@Override
protected String doInBackground(String... params) {
try {
URL url = new URL(loc);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
src = readStream(con.getInputStream());

} catch (Exception e) {
e.printStackTrace();
}

return src;
}

@Override
protected void onPostExecute(String result) {
if (src == null)
new AlertDialog.Builder(TimetableMainActivity.this).
setTitle("Error").setMessage("No Schedule Found").
setNeutralButton("Close", null).show();
else {
parseXML(src);
}

setContentView(R.layout.activity_main_timetable);

days = new String[5][10];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 10; j++) {
int k = i * 10 + j;
days[i][j] = schedule.get(k);
}
}

for (int i = 0; i < 5; i++)
list[i] = new ArrayList<Map<String, String>>();

int count = hours.length;

for (int j = 0; j < 5; j++) {
for (int i = 0; i < count; i++) {
map = new HashMap<String, String>();
map.put("time", hours[i]);
map.put("description", days[j][i]);
list[j].add(map);
}
}

Calendar cal = Calendar.getInstance();
int today = cal.get(Calendar.DAY_OF_WEEK) - 2;

pos = 0;
if (today >= 0 && today <= 4)
pos = today;

ViewPager viewPager = findViewById(R.id.ViewPager);
CustomPagerAdapter adapter = new CustomPagerAdapter(TimetableMainActivity.this, list);
PagerTabStrip pagerTabStrip = findViewById(R.id.pager_tab);

int color = Color.parseColor("#33b7ee");
pagerTabStrip.setTabIndicatorColor(color);

viewPager.setAdapter(adapter);
viewPager.setCurrentItem(pos);
}


This is where im getting an error. Im getting an IndexOut of bounds error and the app is crashing



2018-11-20 22:35:19.126 20681-20681/com.example.mr_ru.listview E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mr_ru.listview, PID: 20681
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:437)
at com.example.mr_ru.listview.TimetableMainActivity$GetXML.onPostExecute(TimetableMainActivity.java:100)
at com.example.mr_ru.listview.TimetableMainActivity$GetXML.onPostExecute(TimetableMainActivity.java:66)
at android.os.AsyncTask.finish(AsyncTask.java:695)
at android.os.AsyncTask.access$600(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


This is the error btw










share|improve this question
























  • hi Shannon, you need to post the code as text in the question and not attached as image ;) is easier to assist you by simulating the question if needed
    – oetoni
    Nov 20 at 23:43










  • fixed it for you
    – Shannon Edwards
    Nov 21 at 2:08
















0














im using android studio for a school project and im in the final stages now. the only thing i have left is for one class that has 2 spinners, one determining the program, and the other determining the semester, and a button that will then take those two spinners and spit out a URL pertaining to the schedule of that program and semester. The problem is, i dont know how to then take that spit out URL, and parse it into the other java class that displays a schedule. Below you will find the code attached, that works but doesnt display the correct schedule(since its hardcoded)



   StringBuffer sb = new StringBuffer();
sb.append("http://branko-cirovic.appspot.com/etcapp/timetables/timetable_"); sb.append(cid); sb.append(semester); sb.append(".xml");
loc = sb.toString();

Toast.makeText(ScheduleMainActivity.this,"You Selected : "
+ loc, Toast.LENGTH_SHORT).show();

Intent toy7 = new Intent(ScheduleMainActivity.this, TimetableMainActivity.class);
toy7.putExtra("Name", loc);
startActivity(toy7);


That is the activity where im creating the intent and using the putExtra to use the data in the next activity



 public class GetXML extends AsyncTask<String, Void, String> {
String src = null;
String loc = (String) getIntent().getExtras().get("Name");

@Override
protected String doInBackground(String... params) {
try {
URL url = new URL(loc);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
src = readStream(con.getInputStream());

} catch (Exception e) {
e.printStackTrace();
}

return src;
}

@Override
protected void onPostExecute(String result) {
if (src == null)
new AlertDialog.Builder(TimetableMainActivity.this).
setTitle("Error").setMessage("No Schedule Found").
setNeutralButton("Close", null).show();
else {
parseXML(src);
}

setContentView(R.layout.activity_main_timetable);

days = new String[5][10];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 10; j++) {
int k = i * 10 + j;
days[i][j] = schedule.get(k);
}
}

for (int i = 0; i < 5; i++)
list[i] = new ArrayList<Map<String, String>>();

int count = hours.length;

for (int j = 0; j < 5; j++) {
for (int i = 0; i < count; i++) {
map = new HashMap<String, String>();
map.put("time", hours[i]);
map.put("description", days[j][i]);
list[j].add(map);
}
}

Calendar cal = Calendar.getInstance();
int today = cal.get(Calendar.DAY_OF_WEEK) - 2;

pos = 0;
if (today >= 0 && today <= 4)
pos = today;

ViewPager viewPager = findViewById(R.id.ViewPager);
CustomPagerAdapter adapter = new CustomPagerAdapter(TimetableMainActivity.this, list);
PagerTabStrip pagerTabStrip = findViewById(R.id.pager_tab);

int color = Color.parseColor("#33b7ee");
pagerTabStrip.setTabIndicatorColor(color);

viewPager.setAdapter(adapter);
viewPager.setCurrentItem(pos);
}


This is where im getting an error. Im getting an IndexOut of bounds error and the app is crashing



2018-11-20 22:35:19.126 20681-20681/com.example.mr_ru.listview E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mr_ru.listview, PID: 20681
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:437)
at com.example.mr_ru.listview.TimetableMainActivity$GetXML.onPostExecute(TimetableMainActivity.java:100)
at com.example.mr_ru.listview.TimetableMainActivity$GetXML.onPostExecute(TimetableMainActivity.java:66)
at android.os.AsyncTask.finish(AsyncTask.java:695)
at android.os.AsyncTask.access$600(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


This is the error btw










share|improve this question
























  • hi Shannon, you need to post the code as text in the question and not attached as image ;) is easier to assist you by simulating the question if needed
    – oetoni
    Nov 20 at 23:43










  • fixed it for you
    – Shannon Edwards
    Nov 21 at 2:08














0












0








0







im using android studio for a school project and im in the final stages now. the only thing i have left is for one class that has 2 spinners, one determining the program, and the other determining the semester, and a button that will then take those two spinners and spit out a URL pertaining to the schedule of that program and semester. The problem is, i dont know how to then take that spit out URL, and parse it into the other java class that displays a schedule. Below you will find the code attached, that works but doesnt display the correct schedule(since its hardcoded)



   StringBuffer sb = new StringBuffer();
sb.append("http://branko-cirovic.appspot.com/etcapp/timetables/timetable_"); sb.append(cid); sb.append(semester); sb.append(".xml");
loc = sb.toString();

Toast.makeText(ScheduleMainActivity.this,"You Selected : "
+ loc, Toast.LENGTH_SHORT).show();

Intent toy7 = new Intent(ScheduleMainActivity.this, TimetableMainActivity.class);
toy7.putExtra("Name", loc);
startActivity(toy7);


That is the activity where im creating the intent and using the putExtra to use the data in the next activity



 public class GetXML extends AsyncTask<String, Void, String> {
String src = null;
String loc = (String) getIntent().getExtras().get("Name");

@Override
protected String doInBackground(String... params) {
try {
URL url = new URL(loc);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
src = readStream(con.getInputStream());

} catch (Exception e) {
e.printStackTrace();
}

return src;
}

@Override
protected void onPostExecute(String result) {
if (src == null)
new AlertDialog.Builder(TimetableMainActivity.this).
setTitle("Error").setMessage("No Schedule Found").
setNeutralButton("Close", null).show();
else {
parseXML(src);
}

setContentView(R.layout.activity_main_timetable);

days = new String[5][10];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 10; j++) {
int k = i * 10 + j;
days[i][j] = schedule.get(k);
}
}

for (int i = 0; i < 5; i++)
list[i] = new ArrayList<Map<String, String>>();

int count = hours.length;

for (int j = 0; j < 5; j++) {
for (int i = 0; i < count; i++) {
map = new HashMap<String, String>();
map.put("time", hours[i]);
map.put("description", days[j][i]);
list[j].add(map);
}
}

Calendar cal = Calendar.getInstance();
int today = cal.get(Calendar.DAY_OF_WEEK) - 2;

pos = 0;
if (today >= 0 && today <= 4)
pos = today;

ViewPager viewPager = findViewById(R.id.ViewPager);
CustomPagerAdapter adapter = new CustomPagerAdapter(TimetableMainActivity.this, list);
PagerTabStrip pagerTabStrip = findViewById(R.id.pager_tab);

int color = Color.parseColor("#33b7ee");
pagerTabStrip.setTabIndicatorColor(color);

viewPager.setAdapter(adapter);
viewPager.setCurrentItem(pos);
}


This is where im getting an error. Im getting an IndexOut of bounds error and the app is crashing



2018-11-20 22:35:19.126 20681-20681/com.example.mr_ru.listview E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mr_ru.listview, PID: 20681
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:437)
at com.example.mr_ru.listview.TimetableMainActivity$GetXML.onPostExecute(TimetableMainActivity.java:100)
at com.example.mr_ru.listview.TimetableMainActivity$GetXML.onPostExecute(TimetableMainActivity.java:66)
at android.os.AsyncTask.finish(AsyncTask.java:695)
at android.os.AsyncTask.access$600(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


This is the error btw










share|improve this question















im using android studio for a school project and im in the final stages now. the only thing i have left is for one class that has 2 spinners, one determining the program, and the other determining the semester, and a button that will then take those two spinners and spit out a URL pertaining to the schedule of that program and semester. The problem is, i dont know how to then take that spit out URL, and parse it into the other java class that displays a schedule. Below you will find the code attached, that works but doesnt display the correct schedule(since its hardcoded)



   StringBuffer sb = new StringBuffer();
sb.append("http://branko-cirovic.appspot.com/etcapp/timetables/timetable_"); sb.append(cid); sb.append(semester); sb.append(".xml");
loc = sb.toString();

Toast.makeText(ScheduleMainActivity.this,"You Selected : "
+ loc, Toast.LENGTH_SHORT).show();

Intent toy7 = new Intent(ScheduleMainActivity.this, TimetableMainActivity.class);
toy7.putExtra("Name", loc);
startActivity(toy7);


That is the activity where im creating the intent and using the putExtra to use the data in the next activity



 public class GetXML extends AsyncTask<String, Void, String> {
String src = null;
String loc = (String) getIntent().getExtras().get("Name");

@Override
protected String doInBackground(String... params) {
try {
URL url = new URL(loc);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
src = readStream(con.getInputStream());

} catch (Exception e) {
e.printStackTrace();
}

return src;
}

@Override
protected void onPostExecute(String result) {
if (src == null)
new AlertDialog.Builder(TimetableMainActivity.this).
setTitle("Error").setMessage("No Schedule Found").
setNeutralButton("Close", null).show();
else {
parseXML(src);
}

setContentView(R.layout.activity_main_timetable);

days = new String[5][10];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 10; j++) {
int k = i * 10 + j;
days[i][j] = schedule.get(k);
}
}

for (int i = 0; i < 5; i++)
list[i] = new ArrayList<Map<String, String>>();

int count = hours.length;

for (int j = 0; j < 5; j++) {
for (int i = 0; i < count; i++) {
map = new HashMap<String, String>();
map.put("time", hours[i]);
map.put("description", days[j][i]);
list[j].add(map);
}
}

Calendar cal = Calendar.getInstance();
int today = cal.get(Calendar.DAY_OF_WEEK) - 2;

pos = 0;
if (today >= 0 && today <= 4)
pos = today;

ViewPager viewPager = findViewById(R.id.ViewPager);
CustomPagerAdapter adapter = new CustomPagerAdapter(TimetableMainActivity.this, list);
PagerTabStrip pagerTabStrip = findViewById(R.id.pager_tab);

int color = Color.parseColor("#33b7ee");
pagerTabStrip.setTabIndicatorColor(color);

viewPager.setAdapter(adapter);
viewPager.setCurrentItem(pos);
}


This is where im getting an error. Im getting an IndexOut of bounds error and the app is crashing



2018-11-20 22:35:19.126 20681-20681/com.example.mr_ru.listview E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mr_ru.listview, PID: 20681
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:437)
at com.example.mr_ru.listview.TimetableMainActivity$GetXML.onPostExecute(TimetableMainActivity.java:100)
at com.example.mr_ru.listview.TimetableMainActivity$GetXML.onPostExecute(TimetableMainActivity.java:66)
at android.os.AsyncTask.finish(AsyncTask.java:695)
at android.os.AsyncTask.access$600(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


This is the error btw







java xml parsing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 2:08

























asked Nov 20 at 23:17









Shannon Edwards

112




112












  • hi Shannon, you need to post the code as text in the question and not attached as image ;) is easier to assist you by simulating the question if needed
    – oetoni
    Nov 20 at 23:43










  • fixed it for you
    – Shannon Edwards
    Nov 21 at 2:08


















  • hi Shannon, you need to post the code as text in the question and not attached as image ;) is easier to assist you by simulating the question if needed
    – oetoni
    Nov 20 at 23:43










  • fixed it for you
    – Shannon Edwards
    Nov 21 at 2:08
















hi Shannon, you need to post the code as text in the question and not attached as image ;) is easier to assist you by simulating the question if needed
– oetoni
Nov 20 at 23:43




hi Shannon, you need to post the code as text in the question and not attached as image ;) is easier to assist you by simulating the question if needed
– oetoni
Nov 20 at 23:43












fixed it for you
– Shannon Edwards
Nov 21 at 2:08




fixed it for you
– Shannon Edwards
Nov 21 at 2:08

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403064%2ftrying-to-parse-a-fetched-xml-file-from-one-class-to-another%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403064%2ftrying-to-parse-a-fetched-xml-file-from-one-class-to-another%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen