udacity / Sunshine-Version-2

The official repository for Developing Android Apps
Apache License 2.0
2.87k stars 4.4k forks source link

2.01 add the Network Code #325

Open edjata opened 7 years ago

edjata commented 7 years ago

Well, I am very, very new to android development. So please don't laugh. I want to learn at my old age. Went through the Udacity Java class now I'm here. Got through all of part 1 with minimal issues. I even created a second string array in my app just to make sure I got it. yup it worked!! However, now I am stuck!!! After adding the networking code my app won't work. Everything looks right to me, but what do I know, lol. Hopefully someone out there can help me. This is day 3 trying to find out what I'm doing wrong.

MainActivity.java

package com.example.android.sunshine.app;

import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new MainActivityFragment.PlaceholderFragment())
                .commit();
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

MainActivityFragment.java

package com.example.android.sunshine.app;

import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListView;

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List;

/**

}

khaledafify commented 7 years ago

check this https://www.youtube.com/watch?v=f17qe9vZ8RM&feature=youtu.be&t=18m10s