Q:

Office 365- Accessing lists refers wrong URL (URL/App name)

I'm new to NAPA tool. I started to build simple apps using NAPA tool. And I tried to access a list in office 365 site using below code. After I publish the app it shows an error message: Message: List 'Announcements' does not exist at site with URL
https://URL/sites/DevSite/SharePointApp3

https://URL/sites/DevSite/

is my site and SharePointApp3 is my app name. At glance
https://URL/sites/DevSite/

has Announcements list and
https://URL/sites/DevSite/SharePointApp3

doesn't have. Can anyone suggest to solve this.
<script type="text/javascript">
        //This example gets all the items in the Announcements list that have a title that begins with 'T'.
        //If your site doesn't include a list called Announcements you must make the changes indicated

        //This variable will hold a reference to the Announcements list items collection
        var returnedItems = null;

        //This function loads the list and runs the query asynchronously
        function queryListItems() {
            //Get the current context
            var context = new SP.ClientContext();
            //Get the Announcements list. Alter this code to match the name of your list
            var list = context.get_web().get_lists().getByTitle('Announcements');
            //Create a new CAML query
            var caml = new SP.CamlQuery();
            //Create the CAML that will return only items with the titles that begin with 'T'
            caml.set_viewXml("<View><Query><Where><BeginsWith><FieldRef Name='Title' /><Value Type='Text'>T</Value></BeginsWith></Where></Query></View>");
            //Specify the query and load the list oject
            returnedItems = list.getItems(caml);
            context.load(returnedItems);
            //Run the query asynchronously, passing the functions to call when a response arrives
            context.executeQueryAsync(onSucceededCallback, onFailedCallback);
        }

        //This function fires when the query completes successfully
        function onSucceededCallback(sender, args) {
            //Get an enumerator for the items in the list
            var enumerator = returnedItems.getEnumerator();
            //Formulate HTML from the list items
            var markup = 'Items in the Announcements list that start with "T": <br><br>';
            //Loop through all the items
            while (enumerator.moveNext()) {
                var listItem = enumerator.get_current();
                markup += 'Item Title: ' + listItem.get_item('Title') + '<br>';
                markup += 'Item ID: ' + listItem.get_id() + '<br><br>';
            }
            //Display the formulated HTML in the displayDiv element
            displayDiv.innerHTML = markup;
        }

        //This function fires when the query fails
        function onFailedCallback(sender, args) {
            //Formulate HTML to display details of the error
            var markup = '<p>The request failed: <br>';
            markup += 'Message: ' + args.get_message() + '<br>';
            //Display the details
            displayDiv.innerHTML = markup;
        }
    </script>

A:

You have to get the context of the site where you have your list. The below code should work:
var context = new SP.AppContextSite(SP.ClientContext.get_current(), 'https://URL/sites/DevSite/');
var list = context.get_web().get_lists().getByTitle('Announcements');

Edit: You will also need to give permission for the app on the site (Host Web). You can do that in Napa from Left Ribbon Properties -> Permissions. 

