title: android read textfile from web
body: <p>Im attempting to read a text file from my <em>onedrive</em>, I need to check the version of the database and update if necessary.</p>
  
  <p>This is an example of my code:</p>
  
  <pre><code> private void checkVersion() {
  
      try {
  
          int dbversion = prefs.getInt("dbversion", 1);
          int dblastversion;
  
  
          URL url = new URL("");
          BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
          String str;
  
          str = in.readLine();
  
          in.close();
  
          System.out.println(str);
  
          dblastversion = Integer.valueOf(str);
  
          if (dbversion &lt; dblastversion)
              System.out.println("updates available");
  
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>When I try to run the app crash and I got this error from logcat:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.example/com.ex.example.ActMenu}: android.os.NetworkOnMainThreadException
  </code></pre>
  
  <p>On this line</p>
  
  <pre><code>BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
  </code></pre>
  
  <p>Somebody know what is the problem? Or its better use another cloud to stor the textfile. Thanks for the help.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Ok as GPRathour said I updated my code to this:</p>
  
  <pre><code>class Getversion_Async extends AsyncTask&lt;Void, Void, Void&gt; {
  
      protected void onPreExecute() {
      }
  
      @Override
      protected Void doInBackground(Void... arg0) {
          System.out.println("starting");
          try {
  
              URL url = new URL("https://onedrive.live.com/redir?resid=b9186f8cb138a030!56556&amp;authkey=!AFmrzOGv_OMArzo&amp;ithint=file%2ctxt");
              BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
              String str;
  
              str = in.readLine();
  
              in.close();
  
              System.out.println(str);
  
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          return null;
      }
  
      @Override
      protected void onPostExecute(final Void unused) {
  
           System.out.println("ended");
  
      }
  }
  </code></pre>
  
  <p>And I call in th onCreate like this to test:</p>
  
  <pre><code> new Getversion_Async().execute();
  </code></pre>
  
  <p>Ok this code runs fine I use a site to host the file and the link ends with <code>.txt</code> and works fine but I cant edit the file. Somebody know how I can do this with onedrive?</p>