Skip to main content

Android http request crash fix executing getInputStream()


The Problem:

In my Android app, I needed to make a simple call to a REST endpoint. I created a separate class extending the AysyncTask class like I am supposed to and as far as I was concerned, my code was clean and compiled just fine. Unfortunately, a runtime error occurred when getInputStream() was executed.  It jumped right to my “finally” block and the process ended suddenly.

My Research:

I added printStackTrace() to my finally block. When I caught and examined the stack trace, this is what I found:

SecurityException: Permission denied (missing INTERNET permission?)

The Solution:

After extensive googling, I realized I needed to add a setting to my AndroidManifest.xml file:

    <uses-permission android:name="android.permission.INTERNET" />

After running debugger, I finally made a successful htttp request. Here’s my code.

     String json = "";     

      try {
            MyRequests mr = new MyRequests();

            mr.execute("http://www.myendpoint.com");
            json = mr.get();
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }

        setContentView(R.layout.activity_name);
        TextView tv = (TextView) findViewById(R.id.lblResponse);
        tv.setText(json);

More Reading:


http://stackoverflow.com/questions/17360924/securityexception-permission-denied-missing-internet-permission

Comments

Popular posts from this blog

Resolved Sitecore "If you publish now, the selected version will not be visible on the web site" warning

The Problem:   Unable to publish any Sitecore item within a particular site, even out of the workflow. Rather, a warning reads " If you publish now, the selected version will not be visible on the web site " What I've Discovered: I couldn't publish any item in the site, not just one or two I viewed all parent items of the items in question The main home page displayed a different warning " This item will never be published because it's publishable option is disabled " Another sitecore developer reminded me of the standard fields option View --> check standard fields to show all standard page fields Found out that somebody checked Never Publish within the publishing section The Fix: After I unchecked the checkbox and saved the change, I was able to publish again.  :) Conclusion: Looks like another Sitecore user thought the children items would not be affected by this change.  Lesson  learned.

[Resolved] Sitecore ParseException: End of string expected at position...

Problem:  I have a line of code that uses Sitecore Fast Query to pull all items + children starting with a site item, like so: Item [] allItems = db.SelectItems( "fast:" + sitecorePath + "//*" ); Unfortunately, I would get a Sitecore parsing error at runtime: ParseException: End of string expected at position... Turns out Sitecore doesn't like hyphens ('-') in any sitecore path when using fast query, which I have a few distributor sites in a folder which contained hyphens. Solution: I create a simple method that resolves a sitecore path to be Sitecore fast query friendly:             string sitecorePath = "" ;             if (siteItem.Paths.FullPath.Contains( "-" ))             {                 String [...

Create a File Upload Service using Node.js / Express / Multer

Problem:    I needed to create a form that essentially uploads a file to a server, then posts the rest of the form data to a second server with the new file name. In other words, post the image to an “Image” server, then posts the form data (with the file URL) to a “Form Data” server. Solution:  Create an Express server that uses the “Multer” library to accomplish this. The Code: Create the express server and have it listen on a specific port var express = require( 'express' ); var app = express (); app . listen ( 3313 , function (){     console . log ( 'listening on port 3313' ); }); Install Multer.  Read here: https://www.npmjs.com/package/multer Include Multer to your express app.  We’ll be tweaking the storage properties so you can name the file whatever you like. At the end, you should have an “upload” object you’ll be using in the next step. be sure to change the file destination of your choice. var expre...