Jump to content

Tazman192

Member
  • Posts

    543
  • Joined

  • Last visited

Everything posted by Tazman192

  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
  15. Also, for testing the getSongName() method, use a log to print the song name, not a println(). Plenty of resources available on how to use logs. Bottom line is don't use println() for testing variable values
  16. You don't ever use System.out.println in an Android app. I haven't looked at your code in detail, but generally you parse the website (your current mechanism seems fine, but not necessarily robust), and add that text to something like a TextView widget, rather than using System.out.println. System.out.println() is generally used for console applications - something which an Android application isn't. Edit: I see you're using a TextView with setText, but you're never calling the getSongName() method, so songName = null. Call that function first. I don't think it's necessary to also store it in a global variable. Have the getSongName() method return a string, and in your onCreate(), do something like the following: textView.setText(getSongName()) No global variables needed in this case.
  17. The first post I see on this topic is With all due respect to @domandric034, if you actually want to stick at it then don't start with C or C++. Sure they're everywhere. Sure they'll get you a good salary when you get good at it, if you get good at it. Neither C or C++ is a friendly language for a beginner at all. I've been programming in C for 5 years, coming from a Java background (5 years isn't shit, I know), and hell I still suck at it. But you could get real competent at other languages real quick. The problem with C and C++ is that it's such a low level language that you require knowledge of computer science concepts such as a computer's memory system. If you want to truly learn a language, think of a project and learn the language required for that project. There's no "best" language to learn. Want to build a web app? Javascript. Android app? Java. iOS app? Objective C. Game or Windows program? C#. You get the point.
  18. I've personally always used 4 spaces for indentation. It's default in 95% of IDE's and text editor's for a reason. That's interesting that Google uses 2. FWIW, Microsoft use 4. I'm not sure about any of the other big players. In Android dev presentations led by Google employees, I've never seen them use 2.
  19. No problem. If you're just starting out learning how to program, I'd generally advise learning C first. It can get difficult with memory access, pointers, no garbage collections and what not. If you have a choice, program in Python or Java to learn the basics first. If you learn an object-oriented language first, in my opinion learning an imperative language like C is much more straightforward.
  20. I don't program in C much, but generally using "==" to compare strings is bad. It's fine for integers, or chars. Use strcmp() instead - a simple google search will tell you exactly how to use it, and if you still have problems with the condition (or how to use the function), then I'll be happy to assist further. On a side note, one thing I noticed in your code above is the line: printf("%s", val_km); Notice that you use %s, and val_km is of type float. You use %s only for strings, so this shouldn't work. Replace %s with %f instead if you'd like to print floats out
  21. In that case, I would recommend OP learn Java. You can learn everything listed by writing a simple Java app, and could also pick up some important OO concepts such as polymorphism, encapsulation, inheritance, and what not which I would argue are way more benefical to learn than handling memory, especially at the early stages.
  22. I would have to disagree with this. They're nowhere near similar. One's procedural, the other's object oriented. Python is a relaxed version of C for a reason. For C, you have to deal with memory allocation, deallocation, leaks and what not yourself because there's no garbage collector. Let's be honest, anybody learning C for their first language for any good sized project will just get put the hell off. Furthermore, concepts like pointers, addresses and what not can overburden someone who has no experience whatsoever. @OP, start with Python, C# or Java. They're all extremely popular and versatile languages (C# not as much as Java and Python). The best way to learn is with a project in mind. It can be something real simple, but something that you think is doable. Look at sources such as codecademy for the real basics for Python if you fancy learning that first. I'd rarely recommend codecademy, but as a beginner, you can't go wrong with it. After that, look at tutorials from thenewboson or Derek Banas on Youtube. Become somewhat competent in the basics for a few weeks, then work on your project and learn from that.
×