Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.NullPointerExeption error?
    text
    copied!<p>This is my scrapping algorithm:</p> <pre><code>private StringBuilder inputStreamToString(InputStream is) { String line = ""; StringBuilder total = new StringBuilder(); // Wrap a BufferedReader around the InputStream BufferedReader rd = new BufferedReader(new InputStreamReader(is)); // Read response until the end try{ while ((line = rd.readLine()) != null) { source = source + line; } st = new StringTokenizer(line, "&gt;&lt;"); marker = st.nextToken(); while(st.hasMoreTokens()) { nameLoop: if(marker.equals("Name:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { Name = marker; marker = st.nextToken(); } break nameLoop; } marker = st.nextToken(); } } addressLoop: if(marker.equals("Address:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { Address = marker; marker = st.nextToken(); } break addressLoop; } marker = st.nextToken(); } } sexLoop: if(marker.equals("Sex:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { Sex = marker; marker = st.nextToken(); } break sexLoop; } marker = st.nextToken(); } } birthLoop: if(marker.equals("Birthdate:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { Birthdate = marker; marker = st.nextToken(); } break birthLoop; } marker = st.nextToken(); } } bplaceLoop: if(marker.equals("Birth Place:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { Birthplace = marker; marker = st.nextToken(); } break bplaceLoop; } marker = st.nextToken(); } } citizenLoop: if(marker.equals("Citizen:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { Citizen = marker; marker = st.nextToken(); } break citizenLoop; } marker = st.nextToken(); } } parentLoop: if(marker.equals("Parent:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { Parent = marker; marker = st.nextToken(); } break parentLoop; } marker = st.nextToken(); } } telLoop: if(marker.equals("Tel No.:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { TelNo = marker; marker = st.nextToken(); } break telLoop; } marker = st.nextToken(); } } idLoop: if(marker.equals("ID #: ")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { IDNo = marker; marker = st.nextToken(); } break idLoop; } marker = st.nextToken(); } } courseLoop: if(marker.equals("Course:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { Course = marker; marker = st.nextToken(); } break courseLoop; } marker = st.nextToken(); } } majorLoop: if(marker.equals("Major:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { Major = marker; marker = st.nextToken(); } break majorLoop; } marker = st.nextToken(); } } yearLoop: if(marker.equals("Year:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { Year = marker; marker = st.nextToken(); } break yearLoop; } marker = st.nextToken(); } } sectionLoop: if(marker.equals("Section:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { Section = marker; marker = st.nextToken(); } break sectionLoop; } marker = st.nextToken(); } } schoolLoop: if(marker.equals("High School:")) { while(st.hasMoreTokens()) { if(marker.equals("strong")) { marker = st.nextToken(); while(!(marker.equals("/strong"))) { School = marker; marker = st.nextToken(); } break schoolLoop; } marker = st.nextToken(); } } else marker = st.nextToken(); } } catch (IOException e) { e.printStackTrace(); } return total; } </code></pre> <p>I am planing to show an image in a webview.</p> <pre><code>HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://students.usls.edu.ph/login.cfm"); </code></pre> <p>The program will first connect to a website by logging in. It will pass the content of the username and password edittext to the website and will login. It will then retrieve the url of the picture and show it in the next panel. It will also scrape needed information such as name, address, etc, from the website.</p> <pre><code>private class URLConnect extends AsyncTask&lt;String, Void, Void&gt; { private final ProgressDialog dialog = new ProgressDialog(Login.this); // can use UI thread here protected void onPreExecute() { this.dialog.setMessage("Logging in..."); this.dialog.show(); } // automatically done on worker thread (separate from UI thread) protected Void doInBackground(final String... args) { try { String username = txtUname.getText().toString(); String password = txtPass.getText().toString(); List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2); nameValuePairs.add(new BasicNameValuePair("username",username)); nameValuePairs.add(new BasicNameValuePair("password",password)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); str = inputStreamToString(response.getEntity().getContent()).toString(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } protected void onPostExecute(Void result) { result.setText(str); results = (String) result.getText(); Intent intent = new Intent(Login.this,Main_screen.class); intent.putExtra("result", results); pic = "http://teachers.usls.edu.ph/student_pics/" + txtUname.getText() + ".jpg"; intent.putExtra("pic",pic); startActivity(intent); } } </code></pre> <p>By pressing a button called login. It will execute this code.</p> <pre><code>public void login (View view) { new URLConnect().execute(); } </code></pre> <p>The code in the second panel is this:</p> <pre><code>public class Main_screen extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main2); TextView result = (TextView)findViewById(R.id.txtresult); String stdName; result.setText(""+getIntent().getExtras().getString("result")); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload