Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9144569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:18:06+00:00 2026-06-17T10:18:06+00:00

I have been working on a class that uses Runtime.exec and gets its output

  • 0

I have been working on a class that uses Runtime.exec and gets its output , however it wasn’t very stable … Now I used this class to get the output of the command “ls /sdcard/” (knowing that I have the right permissions in my Manifest) … (I will write codes below) My problem is that the Text output from the command can be shown as Toast , and it can be set as a text for a button , but not a text for a TextView ! when I run my TextView.settext() , the TextView shows no text at all! What’s weirder is that if I use settext() like TextView.settext("Hey there , I am reset"); it works and shows that text ! Here are the codes :

MainActivity.class/Button.setOnClickListener:

B1.setOnClickListener(new View.OnClickListener() {          
    public void onClick(View arg0) {
        String sdcard = File.separator+Environment.getExternalStorageDirectory().toString()+File.separator; //unused
        String[] arr = {"ls" , "/sdcard/..ROMS/"};//unused - was for experimentation
        String r = shell.sendSingleCommand("ls /sdcard/"); //"r" should now hold the output (stdin and stderr) of the command - shell is defined as Shells shell = new Shells();
        B3.setText(r); //Text of the button changes to the String r
        text.setText(r); //Text is blank , no text is shown at all , not even what it originally was - "text" is my TextView ... Here's my problem
        Show(r); // a method that shows a Toast for a given String - shows the String r normally in a normal Toast ...

    }
});

Declarations of most variables in MainActivity:

        final Button B1 = (Button) findViewById(R.id.button1);
        final Button B2 = (Button) findViewById(R.id.button2);
        final Button B3 = (Button) findViewById(R.id.button3);
        final SharedPreferences pref = getSharedPreferences("seaskyways.testingproject",0);     
        final TextView text = (TextView) findViewById(R.id.testing_text_view);
        final Shells shell = Shells.Shells(); //which returns new Shells()

Layout/activity_main.xml:

<ScrollView xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="37dp"
            android:text="Button 1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="52dp"
            android:text="Button 2" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/button1"
            android:layout_centerHorizontal="true"
            android:text="Button 3" />

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/button3" >

            <TextView
                android:id="@+id/testing_text_view"
                android:layout_width="222dp"
                android:layout_height="236dp"
                android:gravity="center|top"
                android:padding="10sp"
                android:text="Hey there !"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/abs__primary_text_holo_dark" />

        </ScrollView>
</RelativeLayout>
</ScrollView>

Show() :

public void Show(String a){
    Toast.makeText(getApplicationContext(),a , Toast.LENGTH_SHORT).show();
}

Shells.class/sendSingleCommand():

public String sendSingleCommand(String singlecmd) { 
    String a = "";
    final BufferedReader in ;
    final BufferedReader er;

    final String r;

        try {
            p = Runtime.getRuntime().exec(singlecmd);           
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    er = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    try{
        String n;

        while((n = er.readLine())!=null){
            a = a + n + "\n";
        }

        while((n=in.readLine())!=null){
            a = a +"\n"+ n;
            while((n = er.readLine())!=null){
                a = a +"\n"+ n;
            }
        }
    }catch(Exception e){
        e.printStackTrace();
    }
    p.destroy();
    try {
        in.close();
        er.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    final StringBuilder build = new StringBuilder();
    build.append(a);
    if(a.startsWith("null")){
        build.substring(4);
    }
    a= build.toString();
    return a;
}

AndroidManifest.xml (incase needed):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="seaskyways.testingproject"
    android:versionCode="1"
    android:versionName="beta" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />
    <uses-permission 
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        />

    <application
        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Sherlock" >
        <activity
            android:name="seaskyways.testingproject.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Holo" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="seaskyways.testingproject.MenuActivity"
            android:label="@string/title_activity_menu" >
        </activity>
        <activity
            android:name="seaskyways.testingproject.Splash"
            android:label="@string/title_activity_splash" android:theme="@style/Theme.Sherlock.Dialog" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="seaskyways.testingproject.HorizontalScrollView"
            android:label="@string/title_activity_splash" >
            <intent-filter>
                <action android:name="android.intent.action.HSV" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

if you need to know anything in the comments please !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:18:07+00:00Added an answer on June 17, 2026 at 10:18 am

    ScrollView can host only one direct child

    Try to use this layout:
    Change to the names that you use and try it out.

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="138dp" >
    
                <Button
                    android:id="@+id/button1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Button" />
    
                <Button
                    android:id="@+id/button2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="104dp"
                    android:text="Button" />
    
                <Button
                    android:id="@+id/button3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginRight="43dp"
                    android:text="Button" />
    
                <ScrollView
                    android:id="@+id/scrollView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="50dp"
                    android:layout_marginTop="50dp" >
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >
    
                        <TextView
                            android:id="@+id/textView1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="TextView" />
    
                    </LinearLayout>
                </ScrollView>
    
            </RelativeLayout>
    
        </LinearLayout>
    
    
    </ScrollView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a Android Web Services program that uses a number
For the past few weeks I have been working on an app that uses
So recently I have been working on phonebook project that uses Binary Search Tree.
I have been working on a SOAP Web Service that uses a Caché to
I have been working with NSArray s and NSMutableArray s that store NSDate objects
We have a C# logging class that uses System.Diagnostics.StackTrace and StackFrame to obtain information
I have developed a application that uses appcelerator cloud service and APN everything working
I have an existing java webapp that uses Hibernate for it's persistence. I've been
I've been working on an application that uses xVal's server side validation with data
I am working on a C++ class that uses a rand() in the constructor.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.