Jump to content
32 minutes ago, EvilCat70 said:

'parsedLine' cannot be resolved.

'findViewById' method cannot be resolved.

 

 

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.

"The only person you are destined to become is the person you decide to be."


CPU: Intel i5 4690K - Motherboard: Asus Maximus VII Ranger - RAM: Corsair Vengeance LP - 2x4GB @ 1866Mhz - GPU: MSI Twin Frozr GTX 770 4GB - CPU Cooler: Be Quiet! Dark Rock Pro 3 CPU Cooler - PSU: EVGA SuperNova G2 750W - Storage: Seagate Barracuda 2TB HDD- Case: Fractal Design Define R4 Windowed (with Red AKASA Led Strips) - Display: Benq GL2460HM 24" Monitor

Link to post
Share on other sites

17 hours ago, Tazman192 said:

 

 


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.

ParseWebsiteTask class must be abstract or implement doInBackground method. What do I need to put there? 

CPU: Intel Core i7 8700  

GPU: Gigabyte GeForce GTX 1070

MOBO: ASUS Z370-F STRIX  

RAM: 16GB Corsair Vengeance DDR4 2133MHz

Link to post
Share on other sites

10 hours ago, EvilCat70 said:

ParseWebsiteTask class must be abstract or implement doInBackground method. What do I need to put there? 

 

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

 

"The only person you are destined to become is the person you decide to be."


CPU: Intel i5 4690K - Motherboard: Asus Maximus VII Ranger - RAM: Corsair Vengeance LP - 2x4GB @ 1866Mhz - GPU: MSI Twin Frozr GTX 770 4GB - CPU Cooler: Be Quiet! Dark Rock Pro 3 CPU Cooler - PSU: EVGA SuperNova G2 750W - Storage: Seagate Barracuda 2TB HDD- Case: Fractal Design Define R4 Windowed (with Red AKASA Led Strips) - Display: Benq GL2460HM 24" Monitor

Link to post
Share on other sites

14 hours ago, Tazman192 said:

 

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

 

3ea31ea47dddaacc5c314107858c2a74.png

Now what do I do? The protected String is returning songHTML which is a string...

CPU: Intel Core i7 8700  

GPU: Gigabyte GeForce GTX 1070

MOBO: ASUS Z370-F STRIX  

RAM: 16GB Corsair Vengeance DDR4 2133MHz

Link to post
Share on other sites

10 hours ago, EvilCat70 said:

3ea31ea47dddaacc5c314107858c2a74.png

Now what do I do? The protected String is returning songHTML which is a string...

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.

"The only person you are destined to become is the person you decide to be."


CPU: Intel i5 4690K - Motherboard: Asus Maximus VII Ranger - RAM: Corsair Vengeance LP - 2x4GB @ 1866Mhz - GPU: MSI Twin Frozr GTX 770 4GB - CPU Cooler: Be Quiet! Dark Rock Pro 3 CPU Cooler - PSU: EVGA SuperNova G2 750W - Storage: Seagate Barracuda 2TB HDD- Case: Fractal Design Define R4 Windowed (with Red AKASA Led Strips) - Display: Benq GL2460HM 24" Monitor

Link to post
Share on other sites

4 hours ago, Tazman192 said:

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.

Well while I was waiting for a reply I did change it but it still said it was clashing 

CPU: Intel Core i7 8700  

GPU: Gigabyte GeForce GTX 1070

MOBO: ASUS Z370-F STRIX  

RAM: 16GB Corsair Vengeance DDR4 2133MHz

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×