954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Android Force Close help?

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

iandr0idos
Newbie Poster
2 posts since May 2011
Reputation Points: 10
Solved Threads: 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

hithirdwavedust
Newbie Poster
3 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 

better once check logcat
this even helps u

sharathg.satya
Posting Whiz in Training
264 posts since Oct 2010
Reputation Points: 0
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: