GithubHelp home page GithubHelp logo

sunshine-version-2's Introduction

Archival Note

We are archiving this repository because we do not want learners to push personal development to the current repository. If you have any issues or suggestions to make, feel free to:

Sunshine

Sunshine is the companion Android app for the Udacity course Developing Android Apps: Android Fundamentals.

Take the course to find out how to build this app a step at a time, and eventually create your own Android App!

This is the second version of the Sunshine code. The repository has been updated on:

  • October 18th, 2015 - Updated to support use of the openweathermap.org API key.
  • February 13th, 2015 - Major update
  • February 25, 2015 - Minor bug fixes
  • March 4th, 2015 - Minor bug fixes

Open Weather Map API Key is required.

In order for the Sunshine app to function properly as of October 18th, 2015 an API key for openweathermap.org must be included with the build.

We recommend that each student obtain a key via the following instructions, and include the unique key for the build by adding the following line to [USER_HOME]/.gradle/gradle.properties

MyOpenWeatherMapApiKey="<UNIQUE_API_KEY">

For help migrating an existing repo (fork or clone prior to 10/18/15), please check out this guide.

======== For the original version, please go here.

A changelog for the course can be found here.

sunshine-version-2's People

Contributors

cdlei avatar dagalpin avatar sarahudacity avatar sdspikes avatar sudkul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sunshine-version-2's Issues

Unable to build and run the project

I tried to build and run the app and got this error. Cannot find symbol variable a829e78b3d3559e6bc1eafde8e8419f5

When I double click on it, it points to this line in SunshineSyncAdapter.java file:
import android.content.SyncRequest;

I have no idea how to fix it.

The layout is not the same as one from the end of lesson 1?

Hi, I am not sure what I did wrong, I basically copied and paste the code from the lesson when I was doing my project. The turn out of my code does not look like what the class has so far? Is it the version of my simulation? I am currently doing this in Jelly Bean, while the lesson is using Gingerbread. My simulation does not have settings implemented when I already have done what the code should be?

untitled

This is my MainActivity.java

package com.dev.xxxxx.sunshine;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
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 ForecastFragment())
                .commit();
    }
}

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

/**
 * A placeholder fragment containing a simple view.
 */

}

untitled2

Gradle build error with OPEN_WEATHER_MAP_API_KEY

I am getting error in BuildConfig.java when I add this code

buildTypes.each {
            it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', '239d9c7bc3c3c59947d0ce1a566c3d9a'
        }

In BuildConfig.java, the line is being generated as public static final String OPEN_WEATHER_MAP_API_KEY = 239d9c7bc3c3c59947d0ce1a566c3d9a;
This is without the quotes. on the key.

assertEquals order wrong in several places of TestProvider

There are several places in TestProvider class where the expected and actual values are switched, like:
line 119-121:
assertEquals("Error: WeatherProvider registered with authority: " + providerInfo.authority +
" instead of authority: " + WeatherContract.CONTENT_AUTHORITY,
providerInfo.authority, WeatherContract.CONTENT_AUTHORITY);

line 222-223:
assertEquals("Error: Location Query did not properly set NotificationUri",
locationCursor.getNotificationUri(), LocationEntry.CONTENT_URI);

line 263:
assertEquals(count, 1);

line 493:
assertEquals(insertCount, BULK_INSERT_RECORDS_TO_INSERT);

line 505:
assertEquals(cursor.getCount(), BULK_INSERT_RECORDS_TO_INSERT);

Network Code

Network code in this branch is not working, giving "Network on main thread" exception. Is there any correction in code where network code is separated from UI using async tasks?

Can not launch Sunshine app on Mac OS X

Uploading file
local path: /Users/vchepeli/Documents/AndroidStudioProjects/Sunshine-Version-2/app/build/outputs/apk/app-debug.apk
remote path: /data/local/tmp/com.example.android.sunshine.app
Installing com.example.android.sunshine.app
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.sunshine.app"
pkg: /data/local/tmp/com.example.android.sunshine.app
Success

Launching application: com.example.android.sunshine.app/com.example.android.sunshine.app.MainActivity.
DEVICE SHELL COMMAND: am start -n "com.example.android.sunshine.app/com.example.android.sunshine.app.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -Xlint:deprecation
Error: Unknown option: -X
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getType()' on a null object reference
at com.android.commands.am.Am.runStart(Am.java:701)
at com.android.commands.am.Am.onRun(Am.java:305)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.am.Am.main(Am.java:97)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:249)

Obsolete Gradle version

You could update this project to use Gradle version 2.2.
Gradle sync failed: Gradle version 2.2 is required. Current version is 2.10. If using the gradle wrapper, try editing the distributionUrl

normalize date on query?

4.07_start_code_content_provider

Shouldn't you call normalizeDate on query if you are going to call it on insert?

private Cursor getWeatherByLocationSettingAndDate(
            Uri uri, String[] projection, String sortOrder) {
        String locationSetting = WeatherContract.WeatherEntry.getLocationSettingFromUri(uri);
        String date = WeatherContract.WeatherEntry.getDateFromUri(uri);

        /**** 
          This is a horrible workaround just to demonstrate the bug.
        ***/
        ContentValues bug = new ContentValues();
        bug.put(WeatherContract.WeatherEntry.COLUMN_DATE, Long.parseLong(date));
        normalizeDate(bug);
        date = Long.toString(bug.getAsLong(WeatherContract.WeatherEntry.COLUMN_DATE));

        Cursor cursor = sWeatherByLocationSettingQueryBuilder.query(mOpenHelper.getReadableDatabase(),
                projection,
                sLocationSettingAndDaySelection,
                new String[]{locationSetting, date},
                null,
                null,
                sortOrder
        );
 @Override
    public Uri insert(Uri uri, ContentValues values) {
        final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        final int match = sUriMatcher.match(uri);
        Uri returnUri;

        switch (match) {
            case WEATHER: {
                normalizeDate(values);  // ????
                long _id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, values);
                if ( _id > 0 )
                    returnUri = WeatherContract.WeatherEntry.buildWeatherUri(_id);
                else
                    throw new android.database.SQLException("Failed to insert row into " + uri);
                break;
            }

about onPostExecute on 2.09

i'm still in 2.09 and stuck with it
what the function onPostExecute ?
if that change the mForecastAdapter dumy data, why when i'm debuging it, the dumy data is still there?
sorry for bad english :)
please answer ......

Refresh Button didn't showed up after updating code.

after updating the forcastFragment.java file, string.xml, main.xml, forecastfragment.xml. I still don't see refresh button show up on the menu bar. The menu bar does show up but only have setting button. I've tried to compare my code with codes presented in lesson "Quiz: refresh button behavior " few times now and can not see if I'm missing any code.

build.gradle -- add note for MyOpenWeatherMapApiKey

I am a pretty new user to Android Studio, Gradle and everything else.
I have been having some trouble to get the project starting with the build.gradle file.

ON:

    buildTypes.each {
        it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey
    }

It would be nice to have a note stating that your API Key should be inside single quotes AND double quotes.

LIKE:

    buildTypes.each {
        // Replace MyOpenWeatherMapApiKey with your API Key in the format '"abcdefgh012345"' 
        // Use both single quotes followed by double quotes.
        it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey
    }

Modern two-pane PreferenceActivity requires use of a PreferenceFragment

Hi, I am new to Android development, and I was following this course on Udacity. In the lesson 3, when Settings were introduced and integrated with the Sunshine app, it did not work for me.

Previous to that particular video, I was able to get to the blank Settings page, except for me, it was not entirely blank. Android Studio created a bunch of preference files when the app was created as a new project.

However, I just went ahead and edited the pref_general.xml as shown in the video. And modified SettingsActivity class. Now when I click on Settings, the app crashes.

Logcat error is this:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.sunshine.app/com.example.android.sunshine.app.SettingsActivity}: java.lang.RuntimeException: Modern two-pane PreferenceActivity requires use of a PreferenceFragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2329) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389) at android.app.ActivityThread.access$900(ActivityThread.java:147) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) Caused by: java.lang.RuntimeException: Modern two-pane PreferenceActivity requires use of a PreferenceFragment at android.preference.PreferenceActivity.requirePreferenceManager(PreferenceActivity.java:1441) at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:1511) at com.example.android.sunshine.app.SettingsActivity.onCreate(SettingsActivity.java:43) at android.app.Activity.performCreate(Activity.java:5933) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)             at android.app.ActivityThread.access$900(ActivityThread.java:147)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:135)             at android.app.ActivityThread.main(ActivityThread.java:5254)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java:372)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)

I am not sure what to do. I googled the error message, but it did not seem like anyone ever faced this error, because no relevant stack overflow thread was there.

Please help. I am not sure what I am doing wrong. Should I use a separate PreferenceFragment class? If you need to take a look at my code, lease let me know. I can share code snippet via gist or pastebin.

Confusing error messages in test cases

The tests in app/src/androidTest/java/com/example/android/sunshine/app/data/TestUriMatcher.java have the wrong order of arguments.

This is the signature of assertEquals: public static void assertEquals (String message, int expected, int actual)
The expected value should go first. This leads to confusing error messages.

My app is getting Crashed and I am getting these errors

05-22 21:03:55.570 9880-9880/com.example.android.sunshine.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.sunshine.app, PID: 9880
android.view.InflateException: Binary XML file line #2: Error inflating class
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
at android.view.LayoutInflater.inflate(Native Method)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.example.android.sunshine.app.ForecastAdapter.newView(ForecastAdapter.java:64)
at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:252)
at android.widget.AbsListView.obtainView(AbsListView.java:2338)
at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
at android.widget.AbsListView.obtainView(Native Method)
at android.widget.ListView.makeAndAddView(ListView.java:1813)
at android.widget.ListView.fillDown(ListView.java:698)
at android.widget.ListView.fillFromTop(ListView.java:759)
at android.widget.ListView.layoutChildren(ListView.java:1632)
at android.widget.AbsListView.onLayout(AbsListView.java:2149)
at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
at android.widget.AbsListView.onLayout(Native Method)
at android.view.View.layout(View.java:15140)
at android.view.ViewGroup.layout(ViewGroup.java:4867)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15140)
at android.view.ViewGroup.layout(ViewGroup.java:4867)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15140)
at android.view.ViewGroup.layout(ViewGroup.java:4867)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:435)
at android.view.View.layout(View.java:15140)
at android.view.ViewGroup.layout(ViewGroup.java:4867)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15140)
at android.view.ViewGroup.layout(ViewGroup.java:4867)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15140)
at android.view.ViewGroup.layout(ViewGroup.java:4867)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15140)
at android.view.ViewGroup.layout(ViewGroup.java:4867)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2480)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2175)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6420)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at andr

Typo in Readme.md

The Readme.md file contains the line

MyOpenWeatherMapApiKey="<UNIQUE_API_KEY">

I think what was meant was

MyOpenWeatherMapApiKey="<UNIQUE_API_KEY>"

Cursor populated with phantom-like data

In branch 4.06_test_weather_table with the file:
app/src/androidTest/java/com/example/android/sunshine/app/data/TestDb.java
Where are these android_metadata, and the sqlite_sequence entries coming from in the Cursor? Additional entries/deletions are needed to get the HashSet to empty and resolve the test.

final HashSet<String> tableNameHashSet = new HashSet<String>();
        tableNameHashSet.add("android_metadata");
        tableNameHashSet.add(WeatherContract.LocationEntry.TABLE_NAME);
        tableNameHashSet.add("sqlite_sequence");
        tableNameHashSet.add(WeatherContract.WeatherEntry.TABLE_NAME);

main activity . Java file mis matches with the tutorial

Hi

i have the latest version of andriod studio and while making the project it didnt showed the option to create the project with fragment. Instead it created a blacnk project only. later i added a fragment to it.

the main activity file has a great difference with the one being used. I copied my blank fragment.java code to main acitivity. and i think its a bit messed up.

Any how the project so far i had reached is to add faek data. My fragment_blank.xml already contained the changes that were made in the tutotial. By addin the ID in the list view it populated a list for items but i geus it is an infinite loop. any how i am unable to move furthur here is the code for my main acitivity.java

`package com.example.apache.sunshine_demo;

import android.content.Context;
import android.net.Uri;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.Arrays;

public class MainActivity extends AppCompatActivity {

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

}

/**

  • A simple {@link Fragment} subclass.

  • Activities that contain this fragment must implement the

  • {@link BlankFragment.OnFragmentInteractionListener} interface

  • to handle interaction events.

  • Use the {@link BlankFragment#newInstance} factory method to

  • create an instance of this fragment.
    */
    public class BlankFragment extends Fragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    private OnFragmentInteractionListener mListener;

    public BlankFragment() {
    // Required empty public constructor
    }

    // /**
    // * Use this factory method to create a new instance of
    // * this fragment using the provided parameters.
    // *
    // * @param param1 Parameter 1.
    // * @param param2 Parameter 2.
    // * @return A new instance of fragment BlankFragment.
    // */
    // TODO: Rename and change types and number of parameters
    public static BlankFragment newInstance(String param1, String param2) {
    BlankFragment fragment = new BlankFragment();
    Bundle args = new Bundle();
    args.putString(ARG_PARAM1, param1);
    args.putString(ARG_PARAM2, param2);
    fragment.setArguments(args);
    return fragment;
    }

    @OverRide
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
    mParam1 = getArguments().getString(ARG_PARAM1);
    mParam2 = getArguments().getString(ARG_PARAM2);
    }
    }

    @OverRide
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    String[] forecastArray = {
    " Today - Sunny - 88/63"
    " Today - Sunny - 88/63"
    " Today - Sunny - 88/63"
    " Today - Sunny - 88/63"
    " Today - Sunny - 88/63"
    };

    list<string> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray));
    

    }

    return inflater.inflate(R.layout.fragment_blank,container,false);

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
    if (mListener != null) {
    mListener.onFragmentInteraction(uri);
    }
    }

    @OverRide
    public void onAttach(Context context) {
    super.onAttach(context);
    if (context instanceof OnFragmentInteractionListener) {
    mListener = (OnFragmentInteractionListener) context;
    } else {
    throw new RuntimeException(context.toString()
    + " must implement OnFragmentInteractionListener");
    }
    }

    @OverRide
    public void onDetach() {
    super.onDetach();
    mListener = null;
    }

    /**

    • This interface must be implemented by activities that contain this
    • fragment to allow an interaction in this fragment to be communicated
    • to the activity and potentially other fragments contained in that
    • activity.
    • See the Android Training lesson <a href=
    • "http://developer.android.com/training/basics/fragments/communicating.html"
    • Communicating with Other Fragments for more information.
      */
      public interface OnFragmentInteractionListener {
      // TODO: Update argument type and name
      void onFragmentInteraction(Uri uri);
      }
      }

`

i am unable to past the screen shot for the mobile display but my fragment_blank.xml is as below
`

<!-- TODO: Update blank fragment layout -->
<ListView
    android:id="@+id/listview_forecast"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

`

Wrong parameters in Utility.formatTemperature()

367a6fb

Lines 336 - 337 are:

Utility.formatTemperature(context, high),
Utility.formatTemperature(context, low);

I believe they should be:

Utility.formatTemperature(context, high, Utility.isMetric(context)),
Utility.formatTemperature(context, low, Utility.isMetric(context)));

So that the arguments match the parameters of the Utility function.

Test fails

While running test on testWeatherTable in TestDb it is producing error. When I commented insertlocation() form testLocationTable it worked properly. Existing code is trying to insert same location entry twice because of which primary key is getting failed and raising the error. Please correct me if am wrong. :)

public void testLocationTable() {
insertLocation();
}

public void testWeatherTable() {
long locationRowId = insertLocation();

Empty activity since 3.10

All branches starting 3.10 doesn't work for me. The last working one is 3.09 with dummy data. When i checkout next branches, list is empty. JSON in logcat is ok, data is there. What's the problem?

You must supply a resource ID for a TextView

I am getting an error message in logcat after the Sunshine app fails to open in my Nexus emulator that shuts down.

The error message causes the application to crash with a fatal exception:
05-04 17:59:12.130 2388-2388/com.example.android.sunshine.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.sunshine.app, PID: 2388
java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView

I have written the code according to the example provided here: 1.04_add_dummy_data...1.05_create_arrayadapter

My code is as follows:

package com.example.android.sunshine.app;

import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment())
                .commit();
    }
}

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

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    ArrayAdapter<String> mForecastAdapter;

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        //Create some dummy data for the ListView. Here's a sample weekly forecast
        String[] forecastArray = {
                "Today - Sunny - 88/63",
                "Tomorrow - Foggy - 70/40",
                "Weds - Cloudy - 72/63",
                "Thurs - Hemorrhoids - 75/65",
                "Fri - Heavy Rain - 65/56",
                "Sat - Flooding Get Out the Boat - 60/55",
                "Sun - Sunny - 80/72"
        };

        List<String> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray));

        // Now that we have some dummy forecast data, create an ArrayAdapter.
        //The ArrayAdapter will take data from a source (like our dummy forecast data) and
        //use it to populate the ListView it's attached to.

        mForecastAdapter = new ArrayAdapter<String>(
                //The current context (this activity)
                getActivity(),
                //ID of List item layout
                R.layout.list_item_forecast,
                //ID of the textview to populate
                R.id.list_item_forecast_textview,
                //Forecast data
                weekForecast);

        View rootView = inflater.inflate(R.layout.fragment_main, container, false);

        // Get a reference to the ListView, and attach this adapter to it.
        ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
        listView.setAdapter(mForecastAdapter);

        return rootView;
    }

}

}

Can anyone tell me what I'm doing wrong.
If by any chance I have forgotten something please reply with what additional information is needed.
Your help is much appreciated.

Data doesn't get loaded on my phone

The data is not loading up in my phone when i hit refresh button...although the logcat shows the JSON string which Catherine is showing in the tutorial. Why is that so?? The code is exactly similar even.

lack of quotes on API key throws error in 2.01_add_network_code

in the app.gradle file this line

it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey

should be

it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', '"MyOpenWeatherMapApiKey"'

otherwise gradle compile will throw error. Please note the double quotes within single quotes. Which is again necessary otherwise the OPEN_WE~ string constant is supplied with a non-string value.

Invalid argument order for assertEquals

At TestUriMatcher.java#L48:

    assertEquals("Error: The WEATHER URI was matched incorrectly.",
            testMatcher.match(TEST_WEATHER_DIR), WeatherProvider.WEATHER);

Produces confusing assertion message. The argument order is wrong. Should be:

assertEquals(String message, int expected, int actual)

TestUtilities.validateCurrentRecord assertEquals prints expected value twice instead of actual value

TestUtilities.validateCurrentRecord prints the expectedValue twice in the assertEquals instead of printing the actual value:


            String expectedValue = entry.getValue().toString();
            assertEquals("Value '" + entry.getValue().toString() +
                    "' did not match the expected value '" +
                    expectedValue + "'. " + error, expectedValue, valueCursor.getString(idx));

It should be:

            String expectedValue = entry.getValue().toString();
            String actualValue = valueCursor.getString(idx);
            assertEquals("Value '" + actualValue +
                    "' did not match the expected value '" +
                    expectedValue + "'. " + error, expectedValue, actualValue);

Also note that this validation method fails if the record is a boolean since the database stores booleans as 0 or 1 so you will be comparing strings like "false" to "0". Sunshine does not have any boolean values, so it is not currently an issue.

My workaround was to check if the expected value is a boolean and convert it to the expected database value:

            if (entry.getValue() instanceof Boolean) {
                expectedValue = (boolean) entry.getValue() ? "1" : "0";
            } else {
                expectedValue = entry.getValue().toString();

error message might be wrong in the TestDb.java

In the TestDb.java Line 70
` // verify that the tables have been created
do {
tableNameHashSet.remove(c.getString(0));
} while( c.moveToNext() );

    // if this fails, it means that your database doesn't contain both the location entry
    // and weather entry tables
    assertTrue("Error: Your database was created without both the location entry and weather entry tables",
            tableNameHashSet.isEmpty());`

I was wondering if there was only one table in the database, then the assertTrue would still fail. In that case the error message "both tables are not created" might not be informative, and this----"Error: Your database was created without the location entry table or the weather entry table or both" would be better.

Error error message for TestUtilities.validateCurrentRecord()

Line 33 of TestUtilities.java:

static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
    Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();
    for (Map.Entry<String, Object> entry : valueSet) {
        String columnName = entry.getKey();
        int idx = valueCursor.getColumnIndex(columnName);
        assertFalse("Column '" + columnName + "' not found. " + error, idx == -1);
        String expectedValue = entry.getValue().toString();
        assertEquals("Value '" + entry.getValue().toString() +
                "' did not match the expected value '" +
                expectedValue + "'. " + error, expectedValue, valueCursor.getString(idx));
    }
}

The first parameter of assertEquals() is

"Value '" + entry.getValue().toString() + 
"' did not match the expected value '" +
expectedValue + "'. " + error

However expectedValue == entry.getValue().toString()

The believe the first parameter of assertEquals() should be

"Value '" + valueCursor.getString(idx) + 
"' did not match the expected value '" +
expectedValue + "'. " + error

force close when click the listview

sometime i got the force close when click the listview
and go to the detail view.
it says
"FATAL EXCEPTION: main
Process: com.example.root.nav_exc, PID: 28568
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.ShareActionProvider.setShareIntent(android.content.Intent)' on a null object reference
"

how to fix this??

ArrayAdapter in lesson 1.04

ArrayAdapter is not declared properly.

In the example code mForecastAdapter is not declared correctly

it should be ArrayAdapter mForecastAdapter= <...>

right now it is just mForecastAdapter=

Getting OpenWeatherMapApi error while building

I am getting an error in build.gradle in the line below after downloading the final project. This is the first time I am building the project after downloading the zip file.

    buildTypes.each {
        it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey
    }

The error is:

Error:(21, 0) Could not find property 'MyOpenWeatherMapApiKey' on com.android.build.gradle.AppExtension_Decorated@28a8005d.

Share Action not working

Hi, I am coding to implement Share Action Provider to Activity.but it does not work.

My application does not throw any error but in logcat it shows like this.

screenshot 1

save me from this issue.I am stuck here since so many days.Thank you in advance.

I clone sunshine project and run it on my android studio.when i click to share button,nothing happens.same logcat error is showing as [screenshot 1].
but another button near share is showing.i do not understand this.

screenshot 2

no suitable method for execute

i got error in this line :(
weatherTask.execute("94043");
and
.appendQueryParameter(QUERY_PARAM, params[0]) (<- it says wrong 2nd argument type. found java lang void requires java ang string)

please help...

how to provide auto complete list of city or postal code ?

Hi,

i am trying to get data of Hawthorn,Australia. so I have passed postal code 3122. but it gives weather data of Gemeente Schiedam,NL. but when i have passed parameter like this 3122,au.it gives perfect result.
1)so how can i pass this kind of parameter q="{postalcode}{country}" in code?
2)why this two urls give different data?

http://api.openweathermap.org/data/2.5/forecast/daily?q=3122&mode=json&units=metric&cnt=7&appid=your app id

http://api.openweathermap.org/data/2.5/forecast/daily?q=3122,au&mode=json&units=metric&cnt=7&appid=your app id

Pass your Preferred Appid.

README file

file README.md line:21 is saying you should provide your API KEY in the following format:

MyOpenWeatherMapApiKey="<UNIQUE_API_KEY">

The angular brackets and double quotation marks arent nested properly. Consider changing it to:

MyOpenWeatherMapApiKey="<UNIQUE_API_KEY>"

styles.xml

I wonder what happened to the styles.xml file. I was following along the Udacity Android tutorial for several days now and just noticed that the styles.xml has been changed. Where there used to be lines of code on different themes, it now contains just this:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

TESTCREATEDB method always fails.

i followed the code for test create db line by line but it the testcreatedb method fails everytime, please any help will be highly appreciated.

Thanks

Set repo URL

The URL of this repo could be set to the Udacity course.

Example setting a repo URL:

screen shot 2015-12-03 at 6 24 42 pm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.