Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Tazman192

Member
  • Content Count

    543
  • Joined

  • Last visited

Awards


This user doesn't have any awards

About Tazman192

  • Title
    Member
  • Birthday June 12

Contact Methods

  • Steam
    faizy450

Profile Information

  • Gender
    Not Telling
  • Location
    Scotland, UK

System

  • CPU
    Intel i5 4670k @ 3.4GHz
  • Motherboard
    Asus Maximus VII Ranger
  • RAM
    Corsair Vengeance LP - 2x4GB @ 1866Mhz
  • GPU
    MSI Twin Frozr GTX 770 4GB
  • Case
    Fractal Design Define R4 (Windowed)
  • Storage
    Seagate Barraccuda 2TB
  • PSU
    EVGA Supernova G2 750W
  • Display(s)
    Benq GL2460HM
  • Cooling
    Be Quiet! Dark Rock Pro 3 CPU Cooler

Recent Profile Visitors

969 profile views
  1. You could look into Chrome Remote Desktop Very easy to set up and works well for me.
  2. Get outta here telling people not to like Python. It's better than most languages for anything to do with data science or machine learning.
  3. I've been using compressed air to clean my pc for the longest time, and it gets quite expensive. It's especially annoying when the dust just flies everywhere. I've seen some dust vacuums online, but wondering if anybody has any experience with some good brands and can recommend me any for cleaning my pc, keyboard etc? Cheers.
  4. In the line "private class ParseWebsiteTask..." change Long to String, like it is in my original code. I'd recommend you read up a little on android development.
  5. Ah, forgot to add an @Override annotation. Above the doInBackground() and onPostExecute() methods, add @Override e.g: @Override protected String doInBackground(URL... urls) { String songHTML = null; try { // Here we make a URL to the web page URL flare = new URL("http://www.api.flare-radio.com/php/song/"); // Next, we need to get the input stream through the URL connection URLConnection connection = flare.openConnection(); InputStream is = connection.getInputStream(); // Once an input stream is created, the rest is basic Java IO method calling BufferedReader in = new BufferedReader(new InputStreamReader(is)); // Read one line at a time and concatenate to the songHTML string String parsedLine; while ((parsedLine = in.readLine()) != null) { songHTML += parsedLine; } in.close(); } catch (Exception ex) { ex.printStackTrace(); } // The return value is passed as a parameter into onPostExecute return songHTML; } @Override protected void onPostExecute(String result) { // Sanity check - Check if the result was passed correclty Log.i(TAG, result); // Add the result to the textView. If the Log prints null, this won't work TextView textView = (TextView) findViewById(R.id.textView); textView.setText(result); }
  6. package com.flareradio.flareradio; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.TextView; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.io.InputStream; public class MainMenu extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_menu); // Calls the doInBackground and onPostExecute method in the Asynctask new ParseWebsiteTask().execute(); } public String getSongName() { String songHTML = null; try { // Here we make a URL to the web page URL flare = new URL("http://www.api.flare-radio.com/php/song/"); // Next, we need to get the input stream through the URL connection // (you were missing this step) URLConnection connection = flare.openConnection(); InputStream is = connection.getInputStream(); // Once an input stream is created, the rest is basic Java IO method calling BufferedReader in = new BufferedReader(new InputStreamReader(is)); // Read one line at a time and concatenate to the songHTML string while ((parsedLine = in.readLine()) != null) { songHTML += parsedLine; } in.close(); } catch (Exception ex) { ex.printStackTrace(); } return songHTML; } class ParseWebsiteTask extends AsyncTask<Void, Void, String> { protected String doInBackground(URL... urls) { String songHTML = null; try { // Here we make a URL to the web page URL flare = new URL("http://www.api.flare-radio.com/php/song/"); // Next, we need to get the input stream through the URL connection URLConnection connection = flare.openConnection(); InputStream is = connection.getInputStream(); // Once an input stream is created, the rest is basic Java IO method calling BufferedReader in = new BufferedReader(new InputStreamReader(is)); // Read one line at a time and concatenate to the songHTML string String parsedLine; while ((parsedLine = in.readLine()) != null) { songHTML += parsedLine; } in.close(); } catch (Exception ex) { ex.printStackTrace(); } // The return value is passed as a parameter into onPostExecute return songHTML; } protected void onPostExecute(String result) { // Sanity check - Check if the result was passed correclty Log.i(TAG, result); // Add the result to the textView. If the Log prints null, this won't work TextView textView = (TextView) findViewById(R.id.textView); textView.setText(result); } } } Should fix the parsedLine problem. As for the second problem, unsure why findViewById isn't working. Copy that exact code and report back.
  7. package com.flareradio.flareradio; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.TextView; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.io.InputStream; public class MainMenu extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_menu); } public String getSongName() { String songHTML = null; try { // Here we make a URL to the web page URL flare = new URL("http://www.api.flare-radio.com/php/song/"); // Next, we need to get the input stream through the URL connection // (you were missing this step) URLConnection connection = flare.openConnection(); InputStream is = connection.getInputStream(); // Once an input stream is created, the rest is basic Java IO method calling BufferedReader in = new BufferedReader(new InputStreamReader(is)); // Read one line at a time and concatenate to the songHTML string while ((parsedLine = in.readLine()) != null) { songHTML += parsedLine; } in.close(); } catch (Exception ex) { ex.printStackTrace(); } return songHTML; } class DownloadFilesTask extends AsyncTask<Void, Void, String> { protected String doInBackground(URL... urls) { String songHTML = null; try { // Here we make a URL to the web page URL flare = new URL("http://www.api.flare-radio.com/php/song/"); // Next, we need to get the input stream through the URL connection URLConnection connection = flare.openConnection(); InputStream is = connection.getInputStream(); // Once an input stream is created, the rest is basic Java IO method calling BufferedReader in = new BufferedReader(new InputStreamReader(is)); // Read one line at a time and concatenate to the songHTML string while ((parsedLine = in.readLine()) != null) { songHTML += parsedLine; } in.close(); } catch (Exception ex) { ex.printStackTrace(); } // The return value is passed as a parameter into onPostExecute return songHTML; } protected void onPostExecute(String result) { // Sanity check - Check if the result was passed correclty Log.i(TAG, result); // Add the result to the textView. If the Log prints null, this won't work TextView textView = (TextView) findViewById(R.id.textView); textView.setText(result); } } } You want to add something like the above into your MainActivity class. Again, not tested but the complete code is there (subject to any errors).
  8. Ah ok. Haven't worked with android applications in some time so I forgot about this. You have to create a new thread to run network tasks. If you run it on the main (UI) thread, this will ultimately slow down the UI as connecting to a URL can take time. Hence, create something like an Asynctask and add the code I wrote earlier into that task. An Asynctask is essentially a worker thread designed for things like network connection, so the UI thread is not slowed down. https://stackoverflow.com/questions/6343166/how-to-fix-android-os-networkonmainthreadexception explains how to do this.
  9. What do you mean it wasn't being used? It was being set with the line String songName = getSongName(), and that was passed into the setText(). I assume that getSongName() was returning a null string? EDIT: forgot to remove the global songName variable - it must have been referring to that as the unused variable. Does it print the songName in the log correctly?
  10. Can you add a few Logs in the try block to print out the song name, and ensure it's actually going into the try block? The page still doesn't load for me.
  11. Okay. Regarding the parsedLine reference, add String parsedLine; before the while loop in the try block
  12. FWIW, the website where you're scraping from does not load for me.
  13. package com.flareradio.flareradio; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.TextView; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.io.InputStream; public class MainMenu extends AppCompatActivity { String songName; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_menu); TextView textView; String songName = getSongName(); if (songName == null) { Log.i("MainActivity", "Song name is null - parsing failed.") } else { textView = (TextView) findViewById(R.id.textView); textView.setText(songName); } } public String getSongName() { String songHTML = null; try { // Here we make a URL to the web page URL flare = new URL("http://www.api.flare-radio.com/php/song/"); // Next, we need to get the input stream through the URL connection // (you were missing this step) URLConnection connection = flare.openConnection(); InputStream is = connection.getInputStream(); // Once an input stream is created, the rest is basic Java IO method calling BufferedReader in = new BufferedReader(new InputStreamReader(is)); // Read one line at a time and concatenate to the songHTML string while ((parsedLine = in.readLine()) != null) { songHTML += parsedLine; } in.close(); } catch (Exception ex) { ex.printStackTrace(); } return songHTML; } } Don't have any IDE for Java on my laptop so may have some code errors (wrote this on Sublime), but run it and let me know if there are any errors.
  14. Still wrong. Can you pastebin the code and I'll fix it up for you and tell me if it works. I'll explain what I did if it does work
×