Hey,
I've been working on this bug for a very long time and I am now on a stage where I need some help as I'm a beginner in Java.
I have a small application which fetches source code from a site. This is done via a JavaScript Interface (I've found out that this is the only way to get the source code). Afterwards it has to put the retreived code into a TextView.
The problem is, that when I call .setText at the 2D array in which I stored the TextView, the app crashes. Code explains more so here's a simplified example of my code so far:
As you can see, a .setText() is executed in the MyJavaScriptInterface. This one creates a crash and stops the app. I know that 'timetable' has a value because I used Toasts to show its value.
I hope one of you can help me out.
Ragoune
I've been working on this bug for a very long time and I am now on a stage where I need some help as I'm a beginner in Java.
I have a small application which fetches source code from a site. This is done via a JavaScript Interface (I've found out that this is the only way to get the source code). Afterwards it has to put the retreived code into a TextView.
The problem is, that when I call .setText at the 2D array in which I stored the TextView, the app crashes. Code explains more so here's a simplified example of my code so far:
Code:
public class Moro extends Activity
{
...
TextView timetable_class[][] = new TextView[9][5];
...
public void onCreate(Bundle savedInstanceState)
{
int id_start = 15;
for (int i = 0; i < 9; i ++) //Row
{
for (int i2 = 0; i2 < 5; i2 ++) //Column
{
//Create textviews
timetable_class[i][i2] = new TextView(app);
timetable_class[i][i2].setId(id_start);
layout_params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
...
layout.addView(timetable_class[i][i2], layout_params);
id_start += 1;
}
}
}
class MyJavaScriptInterface
{
@SuppressWarnings("unused")
public void returnHTML(String html)
{
int id_start = 15;
int start = html.indexOf("<td>")+1;
for (int i = 0; i < 1; i ++) //Row
{
for (int i2 = 0; i2 < 1; i2 ++) //Column
{
timetable = html.substring(html.indexOf("<td", start), html.indexOf("</td>", start))
.replace("<td>", "")
.replace("<td class=\"vrij\">", "")
.replace("<span class=\"nobr\">", "")
.replace("</span>", "")
.replace(" ", "")
.trim()
.replace(" W", " ");
start = html.indexOf("</td>", start)+1;
timetable_class[i][i2].setText(timetable);
}
}
}
}
public void setTimetable()
{
...
web.loadUrl("javascript:window.HTMLOUT.returnHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
...
}
As you can see, a .setText() is executed in the MyJavaScriptInterface. This one creates a crash and stops the app. I know that 'timetable' has a value because I used Toasts to show its value.
I hope one of you can help me out.
Ragoune