У меня проблемы с приложением для Android.Кажется, приложение принудительно закрывается всякий раз, когда я вставляю:
String fileContents = getFileContents("http://www.youtube.com/watch?v="+code);
fileContents = fileContents.substring(fileContents.indexOf("\'VIDEO_ID\': "+"\""+code+"\""),fileContents.indexOf("yt.setMsg({"));
String[] settings = fileContents.split("fmt_url_map");
settings = settings[settings.length-1].split("\"");
String map = settings[2];
map = map.replace("\\/", "/").replace("\\u0026", "&");
fmtMap = map.split("[,|]+");
hash = new HashMap<Integer, String>();
for(int i = 0; i< fmtMap.length/2; i ++) {
hash.put(new Integer(Integer.parseInt(fmtMap[2*i])),fmtMap[2*i+1]);
}
Моя функция getFileContents ():
public static String getFileContents(String path) {
InputStreamReader instream = null;
URL url = null;
URLConnection urlConn = null;
try {
url = new URL(path);
try {
urlConn = url.openConnection();
instream = new InputStreamReader(urlConn.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String separator = System.getProperty("line.separator");
StringBuffer contents = new StringBuffer();
try {
BufferedReader f = new BufferedReader(instream);
try {
String line = null;
while((line = f.readLine()) != null) {
contents.append(line);
contents.append(separator);
}
}
finally {
f.close();
}
}
catch (IOException ex) {
System.out.println(ex.toString());
}
String text = contents.toString();
return text;
}
Я подозреваю, что это не работает, потому что я скопировал это прямо с одногоПроекты Java, но я не понимаю, почему.
Если кто-то может помочь, это было бы здорово!: D