[Java for Android App Development] punticci:
Hi i'm trying to make an app to change governor and drop the cache..all things goes well and the app it's ok but when i try to inserta part of code to see the meminfo and cpu info it crash on startup.. i don't know which is the problem..here's my code:

package eu.lucazanini.swipeviews;

import android.annotation.TargetApi;
import android.app.ActionBar;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends FragmentActivity {

CollectionPagerAdapter mCollectionPagerAdapter;
ViewPager mViewPager;
TextView textOut;
private TextView cpuInfo;
private TextView memoryInfo;
// Notification code
private static final int SIMPLE_NOTIFICATION_ID = 1;

NotificationManager mNotificationManager;
// fine
[MENTION=273171]target[/MENTION]Api(Build.VERSION_CODES.HONEYCOMB)
[MENTION=439709]override[/MENTION]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Readcpuinfo
TextView CPUinfo = (TextView) findViewById(R.id.CPUinfo);
CPUinfo.setText(getCPUinfo());
TextView Memoryinfo = (TextView) findViewById(R.id.memoryinfo);
Memoryinfo.setText(getMemoryInfo());
//fine readcpuinfo
// Notification code
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

View btnradio_hindi = findViewById(R.id.radio_hindi);
// fine
mCollectionPagerAdapter = new CollectionPagerAdapter(
getSupportFragmentManager());

// Set up action bar.
final ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

// Set up the ViewPager, attaching the adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mCollectionPagerAdapter);
}

/// Inizio creazione funzioni
private String getMemoryInfo(){
ProcessBuilder cmd;
String result = new String();

try{
String[] args = {"/system/bin/cat", "/proc/meminfo"};
cmd = new ProcessBuilder(args);

Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while(in.read(re) != -1){
System.out.println(new String(re));
result = result + new String(re);
}
in.close();
} catch(IOException ex){
ex.printStackTrace();
}
return result;
}
private String getCPUinfo()
{
ProcessBuilder cmd;
String result="";

try{
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
cmd = new ProcessBuilder(args);

Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while(in.read(re) != -1){
System.out.println(new String(re));
result = result + new String(re);
}
in.close();
} catch(IOException ex){
ex.printStackTrace();
}
return result;
}

public Boolean execCommands(String... command) {
try {
Runtime rt = Runtime.getRuntime();
Process process = rt.exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());

for(int i = 0; i < command.length; i++) {
os.writeBytes(command[i] + "\n");
os.flush();
}
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (IOException e) {
return false;
} catch (InterruptedException e) {
return false;
}
return true;
}

/**
* A {@link android.support.v4.app.FragmentStatePagerAdapter} that returns a
* fragment representing an object in the collection.
*/
public class CollectionPagerAdapter extends FragmentStatePagerAdapter {

final int NUM_ITEMS = 3; // number of tabs

public CollectionPagerAdapter(FragmentManager fm) {
super(fm);
}

[MENTION=439709]override[/MENTION]
public Fragment getItem(int i) {
Fragment fragment = new TabFragment();
Bundle args = new Bundle();
args.putInt(TabFragment.ARG_OBJECT, i);
fragment.setArguments(args);
return fragment;
}

[MENTION=439709]override[/MENTION]
public int getCount() {
return NUM_ITEMS;
}

[MENTION=439709]override[/MENTION]
public CharSequence getPageTitle(int position) {

String tabLabel = null;
switch (position) {
case 0:
tabLabel = getString(R.string.label1);
break;
case 1:
tabLabel = getString(R.string.label2);
break;
case 2:
tabLabel = getString(R.string.label3);
break;
}

return tabLabel;
}
}

/**
* A dummy fragment representing a section of the app, but that simply
* displays dummy text.
*/
public static class TabFragment extends Fragment {

public static final String ARG_OBJECT = "object";

[MENTION=439709]override[/MENTION]
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

Bundle args = getArguments();
int position = args.getInt(ARG_OBJECT);

int tabLayout = 0;
switch (position) {
case 0:
tabLayout = R.layout.tab1;
break;
case 1:
tabLayout = R.layout.tab2;
break;
case 2:
tabLayout = R.layout.tab3;
break;
}

View rootView = inflater.inflate(tabLayout, container, false);

return rootView;
}
}
public void onRadioButtonClicked(View view) {

((RadioButton) view).isChecked();

// Check which radio button was clicked
// switch(view.getId()) {
// case R.id.radio_hindi:
// if (checked)

switch (view.getId())
{
case R.id.radio_hindi:
String[] commands = {
"echo 3 > /proc/sys/vm/drop_caches",
"cat /proc/meminfo | awk 'NR == 2'"

};
sendSimpleNotification();
Toast.makeText(this, "Hai liberato memoria! Hai: " + Runtime.getRuntime().freeMemory() + "", Toast.LENGTH_LONG).show();
execCommands(commands);

String commandText = "echo 'foo' >> /sdcard/foo.txt\necho 'bar' >> /sdcard/foo.txt";

execCommands(commandText.split("\n"));
break;

case R.id.radio_english:
String[] commands1 = {"echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor",
"/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor",
"/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor",
"/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"};
execCommands(commands1);
sendSimpleNotificationOndemand();
Toast.makeText(this, "Hai selezionato il governor Ondemand", Toast.LENGTH_LONG).show();
break;
case R.id.interactive_btn:
String[] commands2 = {"echo interactive > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor",
"/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor",
"/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor",
"/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"};
execCommands(commands2);
sendSimpleNotificationInteractive();
Toast.makeText(this, "Hai selezionato il governor: Interactive", Toast.LENGTH_LONG).show();
break;
case R.id.conservative_btn:
String[] commands3 = {"echo conservative > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor",
"/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor",
"/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor",
"/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"};
execCommands(commands3);
sendSimpleNotificationConservative();
Toast.makeText(this, "Hai selezionato il governor: Conservative", Toast.LENGTH_LONG).show();
break;
}
}
protected void cancelSimpleNotification() {
mNotificationManager.cancel(SIMPLE_NOTIFICATION_ID);
}
private void sendSimpleNotification() {

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
MainActivity.this);

// Titolo e testo della notifica
notificationBuilder.setContentTitle("Boost RAM");
notificationBuilder.setContentText("Memoria libera: "+ Runtime.getRuntime().freeMemory() + "bytes");

// Testo che compare nella barra di stato non appena compare la notifica
notificationBuilder.setTicker("Memoria liberata con successo");

// Data e ora della notifica
notificationBuilder.setWhen(System.currentTimeMillis());

// Icona della notifica
notificationBuilder.setSmallIcon(R.drawable.ic_launcher);

// Creiamo il pending intent che verrà lanciato quando la notifica
// viene premuta
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);

notificationBuilder.setContentIntent(contentIntent);

// Impostiamo il suono, le luci e la vibrazione di default
notificationBuilder.setDefaults(Notification.DEFAULT_SOUND
| Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

mNotificationManager.notify(SIMPLE_NOTIFICATION_ID,
notificationBuilder.build());
}
// Notification per il governor ondemand
private void sendSimpleNotificationOndemand() {

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
MainActivity.this);

// Titolo e testo della notifica
notificationBuilder.setContentTitle("Governor Changed");
notificationBuilder.setContentText("Hai selezionato il governor Ondemand");

// Testo che compare nella barra di stato non appena compare la notifica
notificationBuilder.setTicker("Governor Ondemand settato");

// Data e ora della notifica
notificationBuilder.setWhen(System.currentTimeMillis());

// Icona della notifica
notificationBuilder.setSmallIcon(R.drawable.ic_launcher);

// Creiamo il pending intent che verrà lanciato quando la notifica
// viene premuta
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);

notificationBuilder.setContentIntent(contentIntent);

// Impostiamo il suono, le luci e la vibrazione di default
notificationBuilder.setDefaults(Notification.DEFAULT_SOUND
| Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

mNotificationManager.notify(SIMPLE_NOTIFICATION_ID,
notificationBuilder.build());
}

//Notification per il governor interactive
private void sendSimpleNotificationInteractive() {

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
MainActivity.this);

// Titolo e testo della notifica
notificationBuilder.setContentTitle("Governor Changed");
notificationBuilder.setContentText("Hai selezionato il governor Interactive");

// Testo che compare nella barra di stato non appena compare la notifica
notificationBuilder.setTicker("Governor Interactive settato");

// Data e ora della notifica
notificationBuilder.setWhen(System.currentTimeMillis());

// Icona della notifica
notificationBuilder.setSmallIcon(R.drawable.ic_launcher);

// Creiamo il pending intent che verrà lanciato quando la notifica
// viene premuta
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);

notificationBuilder.setContentIntent(contentIntent);

// Impostiamo il suono, le luci e la vibrazione di default
notificationBuilder.setDefaults(Notification.DEFAULT_SOUND
| Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

mNotificationManager.notify(SIMPLE_NOTIFICATION_ID,
notificationBuilder.build());
}

//Notification per il governor conservative
private void sendSimpleNotificationConservative() {

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
MainActivity.this);

// Titolo e testo della notifica
notificationBuilder.setContentTitle("Governor Changed");
notificationBuilder.setContentText("Hai selezionato il governor Conservative");

// Testo che compare nella barra di stato non appena compare la notifica
notificationBuilder.setTicker("Governor Conservative settato");

// Data e ora della notifica
notificationBuilder.setWhen(System.currentTimeMillis());

// Icona della notifica
notificationBuilder.setSmallIcon(R.drawable.ic_launcher);

// Creiamo il pending intent che verrà lanciato quando la notifica
// viene premuta
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);

notificationBuilder.setContentIntent(contentIntent);

// Impostiamo il suono, le luci e la vibrazione di default
notificationBuilder.setDefaults(Notification.DEFAULT_SOUND
| Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

mNotificationManager.notify(SIMPLE_NOTIFICATION_ID,
notificationBuilder.build());
}
}

Any helps?Thanks:good: