0

Hi!
I'm new to DaniWeb, so I don't really know much. Excuse me if I seem really rude or anything.

Anyways, I'm having trouble with an android app I'm building. My program seems to force close whenever I put in:

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]);
		}

My getFileContents() function is as follows:

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;
	}

I suspect this is because I'm porting Java code directly to Android, but I don't know how to do it otherwise.

If anybody can help me, that would be great.
:D

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by sharathg.satya
0

Well, you could use the NDK for native java, though it's not exactly recommended. You could also try reposting your code with thorough commentary so that we don't have to interpret every single line ourselves <3

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.