I am beginning at creating Android apps and I have been playing with a
hello world app and attempting to add a username and password editbox
and print it out to the screen.  I have no error or warnings in the
problem window, but when I run it on a android 3.0 tablet, it
crashes.........

here is the java file:  Can anyone help?

package com.example.atprint;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class HelloAndroid extends Activity {

        private TextView outputView;
        private Button localRunButton;
        private EditText localPathEdit;
        private EditText username;
        private EditText password;
        private Handler handler = new Handler();

        /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                outputView = (TextView)findViewById(R.id.outputView);
                localPathEdit = (EditText)findViewById(R.id.localPathEdit);
                localRunButton = (Button)findViewById(R.id.localRunButton);
                username = (EditText)findViewById(R.id.localUser);
                password = (EditText)findViewById(R.id.localPassword);
                localRunButton.setOnClickListener(onLocalRunButtonClick);
            }

        private OnClickListener onLocalRunButtonClick = new OnClickListener()
{
                public void onClick(View v) {
                        String output = 
exec(localPathEdit.getText().toString());
                        output(output);
                }
        };
        // Executes UNIX command.
            private String exec(String command) {
                try {
                    Process process = Runtime.getRuntime().exec(command);
                    BufferedReader reader = new BufferedReader(
                            new InputStreamReader(process.getInputStream()));
                    int read;
                    char[] buffer = new char[4096];
                    StringBuffer output = new StringBuffer();
                    while ((read = reader.read(buffer)) > 0) {
                        output.append(buffer, 0, read);
                    }
                    output.append(username);
                    output.append(password);
                    reader.close();
                    process.waitFor();
                    return output.toString();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

            private void output(final String str) {
             Runnable proc = new Runnable() {
                 public void run() {
                         outputView.setText(str);
                 }
             };
             handler.post(proc);
            }

}



here is the main.xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/localPathLabel" android:text="Local exe path:"/>

<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
        <EditText android:id="@+id/localPathEdit"
android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_weight="1"
android:text="/system/bin/ls"></EditText>

</LinearLayout>

<TextView
        android:layout_width="fill_parent"
    android:layout_height="wrap_content"
        android:title="Account Information"/>

<EditText android:title="User Name" android:id="@+id/localUser"
android:summary="SSH User name"></EditText>
<EditText android:title="Password / Passphrase" android:id="@+id/
localPassword" android:summary="SSH Password"
android:password="true"></EditText>
<Button android:id="@+id/localRunButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Run"></Button>


<TextView android:id="@+id/outputView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>

</LinearLayout>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to