0

My application won't run anymore in my tablet and I don't know why. It runs fine in the emulator.

public class TestingActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */

    String uname, pass, pic;
    EditText txtUname, txtPass;
    Button login;
    TextView result, tview2, tview3;
    String nameStartLine = "                                        <td style=\"font:10px verdana; color:#312e25; text-align:right;\">Name:</td>";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        login=(Button)findViewById(R.id.button1);
        result=(TextView)findViewById(R.id.textView1);
        tview2=(TextView)findViewById(R.id.textView2);
        tview3=(TextView)findViewById(R.id.textView3);
        txtUname=(EditText)findViewById(R.id.editText1);
        txtPass=(EditText)findViewById(R.id.editText2);

        login.setOnClickListener(this);

        android.view.Display display = ((android.view.WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();


        //set width and height
        txtUname.setHeight((int)(display.getHeight()*0.079));
        txtUname.setWidth((int)(display.getWidth()/1.2));
        txtPass.setHeight((int)(display.getHeight()*0.079));
        txtPass.setWidth((int)(display.getWidth()/1.2));
        login.setHeight((int)(display.getHeight()*0.079));
        login.setWidth((int)(display.getWidth()/3.2));

        //set position
        RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        RelativeLayout.LayoutParams lp4 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        RelativeLayout.LayoutParams lp5 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        lp1.setMargins((int) display.getWidth()/11, (int) ((int) display.getHeight()/3), 0, 0);
        lp2.setMargins((int) display.getWidth()/11, (int) ((int) display.getHeight()/2.1), 0, 0);
        lp3.setMargins((int) (display.getWidth()/2.7), (int) ((int) display.getHeight()/1.7), 0, 0);
        lp4.setMargins((int) display.getWidth()/11, (int) ((int) display.getHeight()/3.4), 0, 0);
        lp5.setMargins((int) display.getWidth()/11, (int) ((int) display.getHeight()/2.3), 0, 0);

        txtUname.setLayoutParams(lp1);
        txtPass.setLayoutParams(lp2);
        tview2.setLayoutParams(lp4);
        tview3.setLayoutParams(lp5);
        login.setLayoutParams(lp3);
    }

        public void postLoginData()
        {    

             HttpClient httpclient = new DefaultHttpClient();

             HttpPost httppost = new HttpPost("http://students.usls.edu.ph/login.cfm");
             try {

                 String username = txtUname.getText().toString();
                 String password = txtPass.getText().toString();

                 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                 nameValuePairs.add(new BasicNameValuePair("username",username));
                 nameValuePairs.add(new BasicNameValuePair("password",password));
                 httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                 HttpResponse response = httpclient.execute(httppost);

                 String str = inputStreamToString(response.getEntity().getContent()).toString();
                 result.setText(str);

                 Intent intent = new Intent(TestingActivity.this,panel_1.class);
                 intent.putExtra("result",result.getText());
                 pic = "http://teachers.usls.edu.ph/student_pics/" + txtUname.getText() + ".jpg";
                 intent.putExtra("pic",pic);


                 startActivity(intent);

             }

             catch (ClientProtocolException e) {
                 e.printStackTrace();
                } catch (IOException e) {
                 e.printStackTrace();
                }
        }

             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) { 
                      if (line.equals(nameStartLine))
                      {
                          line = rd.readLine();
                          StringTokenizer st = new StringTokenizer(line, ">< ");
                          String marker = st.nextToken();

                          while(st.hasMoreTokens())
                          {

                            if(marker.equals("strong"))
                            {
                                marker = st.nextToken();
                                while(!(marker.equals("/strong")))
                                {
                                    total.append(marker + " ");
                                    marker = st.nextToken();
                                }
                            }
                            marker = st.nextToken();
                          }
                      }
                  }
                }

                    catch (IOException e) {
                        e.printStackTrace();
                    }


                 return total;

             }

             public void onClick(View view) {
                 if(view == login){
                   postLoginData();
                 }

               }
}

The panel class:

public class panel_1 extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);
        TextView result = (TextView)findViewById(R.id.txtresult);

        result.setText(""+getIntent().getExtras().getString("result"));
        WebView myWebView = (WebView) findViewById(R.id.webView1);  

        myWebView.loadUrl(getIntent().getExtras().getString("pic"));
        android.view.Display display = ((android.view.WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    }
}

Edited by ~s.o.s~: Separate out the code snippet in two logical pieces

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by pmark019
0

Here is the logcat error.

Edited by pmark019

Attachments
08-04 10:41:06.218: E/AndroidRuntime(4471): FATAL EXCEPTION: main
08-04 10:41:06.218: E/AndroidRuntime(4471): android.os.NetworkOnMainThreadException
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at java.net.InetAddress.getAllByName(InetAddress.java:220)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at sample.program.TestingActivity.postLoginData(TestingActivity.java:107)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at sample.program.TestingActivity.onClick(TestingActivity.java:174)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at android.view.View.performClick(View.java:3511)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at android.view.View$PerformClick.run(View.java:14105)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at android.os.Handler.handleCallback(Handler.java:605)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at android.os.Handler.dispatchMessage(Handler.java:92)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at android.os.Looper.loop(Looper.java:137)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at android.app.ActivityThread.main(ActivityThread.java:4575)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
08-04 10:41:06.218: E/AndroidRuntime(4471): 	at dalvik.system.NativeStart.main(Native Method)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.