Two problems, 1 cannot download image under a specific set of conditions
<p>I am running com.powerupt app on Samsung. And I get this error in the log file.
E/PackageInfoItemFactory(1304): android.content.pm.PackageManager$NameNotFoundException: com.powerupt</p>

<p>Why is that? Help</p>

<p>I have one more puzzling situation.</p>

<p>The app , in About screen asks for a selection of a coach. Once a coach is selected I reload the page to get the coach image and his/her bio etc.
If the coach is selected in the about screen all seems to work.
But if I rerun the app, the coach is already selected (saved on the server also) and go to About screen the image does not appear. Except I see a dark screen. and the log says (at the moment of dark screen):I/PackageInfo(1304): getRunningAppPackageList(), pid:32175, task:true, service:false, memUsage:8835, cpuUsage:0.0, packageName:com.powerupt</p>

<p>App does not ask for the list.
Here is the code for the about page:</p>

<pre><code>    package com.powerupt;

        import java.io.IOException;
        import java.io.InputStreamReader;
        import java.io.Reader;
        import java.io.UnsupportedEncodingException;
        import java.net.MalformedURLException;
        import java.net.URL;
        import java.net.URLEncoder;

        import org.json.JSONArray;
        import org.json.JSONException;
        import org.json.JSONObject;
        import org.json.JSONTokener;

        import android.app.Activity;
        import android.app.AlertDialog;
        import android.app.Dialog;
        import android.content.ComponentName;
        import android.content.Context;
        import android.content.Intent;
        import android.database.Cursor;
        import android.database.sqlite.SQLiteDatabase;
        import android.graphics.Canvas;
        import android.graphics.Paint;
        import android.net.Uri;
        import android.os.Bundle;
        import android.text.Layout;
        import android.text.SpannableString;
        import android.text.style.LeadingMarginSpan.LeadingMarginSpan2;
        import android.util.Log;
        import android.view.Display;
        import android.view.KeyEvent;
        import android.view.LayoutInflater;
        import android.view.Menu;
        import android.view.MenuItem;
        import android.view.View;
        import android.view.View.OnClickListener;
        import android.view.View.OnLongClickListener;
        import android.view.ViewGroup;
        import android.view.WindowManager;
        import android.widget.AdapterView;
        import android.widget.AdapterView.OnItemSelectedListener;
        import android.widget.Button;
        import android.widget.EditText;
        import android.widget.ImageButton;
        import android.widget.ImageView;
        import android.widget.RelativeLayout;
        import android.widget.SimpleCursorAdapter;
        import android.widget.Spinner;
        import android.widget.TextView;
        import android.widget.Toast;

        import com.mylibrary.std.ServerException;
        import com.powerupt.Database.DBHandler;
        import com.powerupt.Database.TermsRecord;
        import com.powerupt.Database.TermsTable;

        public class LeadingMarginSpanActivity extends Activity {
            /**
             * @see android.app.Activity#onCreate(Bundle)
             */
            AlertDialog alertDialog;
            Dialog dialog;
            ImageView topImg;
            ImageView coachImg;
            byte terms[] = new byte [7];
            RelativeLayout topstuff;
            TermsRecord userAcct;
            TermsTable tt;
            DBHandler dbHandler = null;
            String[] mycoach;
            Uri result;
            SQLiteDatabase db;
            Button btnAccept;
            Button btnReject;
            EditText coachtext;
            int myindex;
            TextView phoneTxt;
            TextView coachTxt;
            String namofcoach[];
            String phoneNumber[];
            String emailAddress[];
            String pathtoimage[];
            String pathtocoach[];
            TermsRecord oldrecord;
            TermsRecord throwaway;
            TermsRecord myrecord;
            String[] nameonly;
            String filespec;
            boolean doregister=false;
            boolean dofixcoach=false;
            int width, height, leftMargin;
            public static String response = null;
            public static final String NAME_OF_APP = "Powerupt";
            String ServerFileSpec="http://&lt;server ip address&gt;/tracker/upload/documents/employees/";
            public static URL SCRIPT_URL; //= MainActivity.SCRIPT_URL;
            static {
                try {
                    SCRIPT_URL = new URL("http://&lt;server ip 
    address&gt;/register/cgi-bin/");
                }catch (MalformedURLException e) {
                    Log.i(LeadingMarginSpanActivity.class.getName(), 
    "Can't build URL", e);
                }
            }
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.about);
                coachTxt = (TextView) findViewById(R.id.coachTxt);
                phoneTxt = (TextView) findViewById(R.id.phoneTxt);
                Log.i("poweruptcoach:aboutx000",MainActivity.pathtocoach);
                if(MainActivity.pathtocoach != null &amp;&amp; 
    !MainActivity.pathtocoach.isEmpty()){
                    filespec = ServerFileSpec + 
    MainActivity.pathtocoach;
                }
                topstuff = (RelativeLayout)findViewById(R.id.topstuff);
                Button coachesBtn = (Button)findViewById(R.id.coachesBtn);
                Button disclaimerBtn = 
    (Button)findViewById(R.id.disclaimerBtn);
                Log.i("poweruptcoach:aboutx00","?" 
    +MainActivity.pathtocoach+"?");
                userAcct = new TermsRecord();
                Log.i("poweruptcoach:aboutx0",MainActivity.pathtocoach);
                if(!MainActivity.coach.isEmpty() &amp;&amp; MainActivity.coach != 
    null){

    Log.i("poweruptcoach:aboutx",MainActivity.pathtocoach);
                    coachImg = (ImageView)findViewById(R.id.coachImg);
                    String picture=null;
                    if(MainActivity.pathtocoach != null &amp;&amp; 
    !MainActivity.pathtocoach.isEmpty()){

                        Log.i("poweruptcoach:aboutx2",filespec);
                        try {
                            URL url = new URL(filespec);
                            try {

`coachImg.setImageDrawable(android.graphics.drawable.Drawable.createFromStream(   

    `(java.io.InputStream) url.getContent(),picture));

                            }catch(IOException e){
                                Log.e(About.class.getName(), "Can't 
    get picture", e);
                            }
                        } catch (MalformedURLException e) {
                            Log.e(About.class.getName(), "Can't 
    build URL", e);
                        } 
                    }else{
                        coachImg.setImageResource(R.drawable.noimage);

                    }
                    phoneTxt.setText(MainActivity.phonedisplay);
                    coachTxt.setText(MainActivity.coach);
                    Display display = ((WindowManager) 
    this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
                    width = display.getWidth();
                    height = display.getHeight();

                    DBHandler dbHandler = new DBHandler(this);
                    dbHandler.open();
                    db = dbHandler.getDB();
                    tt = new TermsTable(dbHandler.getDB());
                    myrecord = tt.findByApp(NAME_OF_APP);
                    //Log.i("powerupt recordY", myrecord.initialize + 
    "?" + myrecord.name);
                    TextView nameofcoachTxt = (TextView) 
    findViewById(R.id.nameofcoachTxt);
                    TextView bioTxt = (TextView) findViewById(R.id.bioTxt);
                    TextView wellnessTxt = (TextView) 
    findViewById(R.id.wellnessTxt);
                    TextView hobbiesTxt = (TextView) 
    findViewById(R.id.hobbiesTxt);
                    TextView smoothieTxt = (TextView) 
    findViewById(R.id.smoothieTxt);

                    TextView wellnesshdrTxt = (TextView) 
    findViewById(R.id.wellnesshdrTxt);
                    TextView hobbieshdrTxt = (TextView) 
    findViewById(R.id.hobbieshdrTxt);
                    TextView smoothiehdrTxt = (TextView) 
    findViewById(R.id.smoothiehdrTxt);

                    ///////////////////////


                    if(width &lt;= 480){
                        leftMargin = 152 + 102;

                    }else{
                        leftMargin = 304 + 102;
                    }

                    try{
                        response = doquery("getprofile.cgi", myrecord.name, 
    myrecord.accountID,  "92782", MainActivity.coachfullname);
                        //Log.i("JSONpowerupt", "173Response: " + response);
                        int i;
                        try
                        {
                            JSONArray jarray = (JSONArray) new 
    JSONTokener(response).nextValue();

                            for( i=0; i&lt;jarray.length(); i++) {
                                JSONObject categoryObj =    
    (JSONObject) jarray.get(i);
                                String nameofcoach = 
    categoryObj.getString("nameofcoachTxt");
                                String bio = 
    categoryObj.getString("bioTxt");
                                String wellness = 
    categoryObj.getString("wellnessTxt");
                                String hobbies = 
    categoryObj.getString("hobbiesTxt");
                                String smoothie = 
    categoryObj.getString("smoothieTxt");
                                /*  SpannableString ss = new 
    SpannableString(nameofcoach);*/

                                SpannableString ss2 = new 
    SpannableString(bio);
                                ss2.setSpan(new 
    MyLeadingMarginSpan2(8, leftMargin), 0, ss2.length(), 0);
                                //TextView messageView = 
    (TextView) findViewById(R.id.bioTxt);
                                bioTxt.setText(ss2);

    nameofcoachTxt.setText(nameofcoach);


    smoothieTxt.setText(smoothie);
                                //}


                           }


                        }catch (JSONException e) {
                         throw new ServerException("Problem connecting with 
    server. Please try again.");
                       }
                    }catch (ServerException e) {

    Toast.makeText(LeadingMarginSpanActivity.this, "" + " INTERNAL ERROR: Unable to parse 

    server `response." , Toast.LENGTH_LONG).show(); ;
                        ////dbHandler.close();
                        finish();
                    }

                    if(db.isOpen()){

                        dbHandler.close();
                    }


                }else{

                    goshowspinner();

                }




            }
            public static String doquery(String cgiscript, String ContactName, 
    String phoneNumber, String zipCode, String EmployeeName) throws ServerException {
                try {
                    String params = String.format("%s?
    ContactName=%s&amp;MobilePhone=%s&amp;AppsSupported=%s&amp;Zip=%s&amp;EmployeeName=%s",
                        escape(cgiscript),
                        escape(ContactName),
                        escape(phoneNumber),
                        "Powerful",
                        escape(zipCode),
                        escape(EmployeeName));
                  //NAME_OF_APP is forced to Powerful for test only
                    URL url = new URL(SCRIPT_URL, params);
                    //Log.i("JSON-", "363Response: " +  url);
                    InputStreamReader in = null;
                    in = new InputStreamReader(url.openStream());
                    response = readFully(in);
                    //Log.i("JSON", "363Response: " + response + " " + 
    url);
                    in.close();
                    JSONTokener tok = new JSONTokener(response);
                    //Log.i("JSON", "363Response: " + response + " " + 
    url);
                    return response;

                } catch (MalformedURLException e) {
                    Log.i(MainActivity.class.getName(), "Can't build 
    URL", e);
                    throw new ServerException("INTERNAL ERROR: Can't 
    build URL due to "+e.getMessage());
                } catch (IOException e) {
                    Log.w(MainActivity.class.getName(), "Unable to 
    contact server", e);
                    throw new ServerException("Unable to contact 
    server.");
                }
            }
            public static String escape(String s) {
                try {
                    return URLEncoder.encode(s, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    throw new RuntimeException(e);
                }
            }
            public static String readFully(Reader in) throws IOException {
                char[] arr = new char[8 * 1024]; // 8K at a time
                StringBuffer buf = new StringBuffer();
                int numChars;
                //Log.i("READ", "Response: " );
                while ((numChars = in.read(arr, 0, arr.length)) &gt; 0) {
                    buf.append(arr, 0, numChars);
                }

                return buf.toString();
            }
            public void goshowspinner(){
                if(!MainActivity.coach.isEmpty() &amp;&amp; MainActivity.coach != 
    null){

                    return; // bypass coaches
                }


                dbHandler = new DBHandler(this);
                dbHandler.open();
                db = dbHandler.getDB();
                tt = new TermsTable(dbHandler.getDB());
                oldrecord = tt.findByApp(NAME_OF_APP);
                dialog = new Dialog(LeadingMarginSpanActivity.this);
                dialog.setContentView(R.layout.coachesdialog);
                /*lets get the coaches from the server and populate the 
    spinner*/
                coachtext = (EditText) dialog.findViewById(R.id.coachtext);
                Spinner spinner = (Spinner) 
    dialog.findViewById(R.id.spinner);
                populateSpinner();

                Cursor c = db.rawQuery("SELECT _ID AS _id, coach, 
    phoneNumber,  emailAddress FROM Account", null);

                String[] from = new String[] {"coach"};
                int[] to = new int[] {android.R.id.text1};
                SimpleCursorAdapter sca = new SimpleCursorAdapter(this, 
    android.R.layout.simple_spinner_item, c, from, to);

    sca.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

                //Spinner spinner = (Spinner) findViewById(R.id.spinner);
                //spinner.setAdapter(sca);

                //mContext = this;
                spinner.setOnItemSelectedListener(new 
    MyOnItemSelectedListener());
                spinner.setAdapter(sca);

                //dialog.setTitle(R.string.title);
                dialog.setCancelable(true);
                btnAccept = (Button) dialog.findViewById(R.id.btnAccept);

                dialog.show();

                btnAccept.setOnClickListener(new OnClickListener() {// 
    Submit button
                    public void onClick(View v) {
                        //
                        //if (check.equals("Yes")) {
                        if (1 == 1) {
                            String code="";
                            dialog.cancel();

                                //oldrecord = 
    tt.findByApp(MainActivity.NAME_OF_APP);
                                /*tt = new 
    TermsTable(dbHandler.getDB());*/
                                //tt.deleteAll();

                                ///////////userAccount = new 
    TermsRecord();
                                userAcct.appID = 
    NAME_OF_APP;
                                userAcct.accountID = 
    oldrecord.accountID;
                                userAcct.name = 
    oldrecord.name;
                                userAcct.termsAccepted = 
    true;
                                userAcct.coach = 
    namofcoach[myindex];
                                userAcct.phoneNumber = 
    phoneNumber[myindex];
                                userAcct.emailAddress = 
    emailAddress[myindex];
                                userAcct.pathtoimage = 
    pathtoimage[myindex];
                                userAcct.pathtocoach = 
    pathtocoach[myindex];

    userAcct.date=oldrecord.date;



                                String[]mycoach = 
    namofcoach[myindex].split(" "); 

                                MainActivity.pathtoimage = 
    pathtoimage[myindex];
                                MainActivity.pathtocoach = 
    pathtocoach[myindex];
                                MainActivity.coachonly= mycoach[0];//first 
    name



    MainActivity.coachfullname=namofcoach[myindex];

                                phoneTxt.setText(MainActivity.phonedisplay);

                                coachTxt.setText("Coach " + 
    mycoach[0]);//coach firstname
                                MainActivity.coach = "Coach " + mycoach[0];
                                Log.i("poweruptabt", 
    MainActivity.pathtoimage );

                                /*update customer's record 
    on the server with the name of the coach*/


                                try{


    PunchFree.registerUser("updatecoach.cgi",oldrecord.name,oldrecord.accountID,"99999", 

    NAME_OF_APP,namofcoach[myindex]);


                                }catch (ServerException e) {

    Toast.makeText(LeadingMarginSpanActivity.this, "" + " Problem connecting with server. 
    Please 

    try again." , Toast.LENGTH_LONG).show(); ;  



                                }
                                doregister=true;                    

                        }else{

                            dialog.cancel();
                            finish();
                        }

                        final Intent intent = new 
    Intent(Intent.ACTION_MAIN, null);

    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                        final ComponentName cn = new 
    ComponentName("com.powerupt", "com.powerupt.LeadingMarginSpanActivity");
                        intent.setComponent(cn);


    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity( intent);
                    }
                });
                dbHandler.close();

                return;
            }
            public void populateSpinner(){

                oldrecord = tt.findByApp(NAME_OF_APP);

                    try{
                        response = 
    PunchCard.doquery("getcoaches.cgi", "", "",  "92782");
                        JSONTokener tok = new JSONTokener(response);

                        tt.deleteAll();
                        try
                         {
                            JSONArray jarray = (JSONArray) new 
    JSONTokener(response).nextValue();

                            namofcoach = new String [jarray.length()] ;
                            phoneNumber = new String [jarray.length()] ;
                            emailAddress = new String [jarray.length()] ;
                            pathtoimage = new String [jarray.length() ] ;
                            pathtocoach = new String [jarray.length()] ;


                            for(int i=0; i&lt;jarray.length(); i++) {

                              JSONObject customerObj =  (JSONObject) 
    jarray.get(i);
                              TermsRecord record = new TermsRecord();
                              String valuebn = 
    customerObj.getString("EmployeeName");
                              String valuepn = 
    customerObj.getString("phoneNumber");
                              String valuead = 
    customerObj.getString("emailAddress");
                              String freebiepath = 
    customerObj.getString("Path1");
                              String coachimage = 
    customerObj.getString("Path2");

                             record.accountID = oldrecord.accountID;
                             record.name = oldrecord.name;
                             record.appID = NAME_OF_APP;
                             record.coach = valuebn;
                             record.phoneNumber = valuepn;
                             record.emailAddress= valuead;
                             record.pathtoimage= freebiepath;
                             record.pathtocoach= coachimage;
                             record.termsAccepted = true;
                             record.totalpoints = 
    oldrecord.totalpoints;
                             record.initialize = 

    oldrecord.initialize;
                             record.prize=oldrecord.prize;
                             tt.insertTerms(record);
                             namofcoach[i]= valuebn; // keep the name 
    but add coach when displaying
                              phoneNumber[i] = valuepn;
                              emailAddress[i]= valuead; 
                              pathtoimage[i]=freebiepath;
                              pathtocoach[i]=coachimage;


                           }
                            throwaway = tt.findByApp(NAME_OF_APP);
                         }catch (JSONException e) {
                             throw new ServerException("INTERNAL ERROR: Unable 
    to parse server response.");
                        }

                    }catch (ServerException e) {
    Toast.makeText(LeadingMarginSpanActivity.this, "" + " Problem connecting with server. 
    Please 
    try again." , Toast.LENGTH_LONG).show(); ;




                    }




            }
            public class MyOnItemSelectedListener implements 
    OnItemSelectedListener {

                public void onItemSelected(AdapterView&lt;?&gt; parent,
                    View view, int pos, long id) {
                    String idstring =  pos + "";
                    //Log.i("bakup powerupcoach itemselect", idstring + "," 
    +namofcoach[pos]);
                    coachtext.setText(namofcoach[pos]);
                    myindex= pos; // myindex is global
                }

                public void onNothingSelected(AdapterView parent) {
                  // Do nothing.
                }
            } 
            @Override
            public void onDestroy(){

                ///////savestate();
                if(dofixcoach){
                    MainActivity.coach="";
                    MainActivity.coachfullname="";
                    MainActivity.phoneTxt.setText("999");
                    MainActivity.coachTxt.setText("My Coach");
                    dbHandler = new DBHandler(this);
                    dbHandler.open();
                    tt = new TermsTable(dbHandler.getDB());
                    db = dbHandler.getDB();
                    oldrecord = tt.findByApp(NAME_OF_APP);
                    tt.deleteAll();
                    TermsRecord record = new TermsRecord();
                    record.accountID = oldrecord.accountID;
                     record.name = oldrecord.name;
                     record.appID = NAME_OF_APP;
                     record.totalpoints = oldrecord.totalpoints;
                     record.initialize = oldrecord.initialize;
                     record.prize=oldrecord.prize;
                     tt.insertTerms(record);
                     dbHandler.close();


                }else if(doregister ){                  
                    dbHandler = new DBHandler(this);
                    dbHandler.open();
                    db = dbHandler.getDB();
                    tt = new TermsTable(dbHandler.getDB());
                    tt.deleteAll();
                    tt.insertTerms(userAcct);
                    dbHandler.close();
                    MainActivity.coachTxt.setText(MainActivity.coach);
                    coachTxt.setText(MainActivity.coach);
                    MainActivity.dofixcoach=false;

                }


                super.onDestroy();

            }
            class MyLeadingMarginSpan2 implements LeadingMarginSpan2 {
                private int margin;
                private int lines;

                MyLeadingMarginSpan2(int lines, int margin) {
                    this.margin = margin;
                    this.lines = lines;


                }


                @Override
                public int getLeadingMargin(boolean first) {
                    if (first) {

                        return margin;
                    } else {

                        return 0;
                    }
                }


                @Override
                public int getLeadingMarginLineCount() {
                    return lines;
                }
            };
            @Override
            protected void onResume() {
                //does not come at the desired 
    timeToast.makeText(LeadingMarginSpanActivity.this, "" + " I am resuming About." , 
    Toast.LENGTH_LONG).show(); ;
                if(dofixcoach){
                    ////finish();
                }
                super.onResume();
            }
            @Override
            public boolean onKeyDown(int keyCode, KeyEvent event) {

                if ((keyCode == KeyEvent.KEYCODE_BACK)) {

                    if( MainActivity.coach ==null ||  
    MainActivity.coach.isEmpty() ){
                        dofixcoach=true;

                        coachTxt.setText("");   
                        MainActivity.coach="";
                        MainActivity.coachfullname="";
                        MainActivity.phoneTxt.setText("");
                        MainActivity.coachTxt.setText("My Coach");
                        MainActivity.dofixcoach=true;
                        MainActivity.coachonly="";


                    }else{
                        MainActivity.dofixcoach=false;
                    }
                }
                MainActivity.coach=MainActivity.coach;

                return super.onKeyDown(keyCode, event);
            }

            @Override 
            public boolean onCreateOptionsMenu(Menu menu) {  
                super.onCreateOptionsMenu(menu); 
                menu.add(0, MainActivity.SHAREAPP_ID, 0, "Share App");
                return true;
            }


            public boolean onMenuItemSelected(int featureId, MenuItem item) {

                switch(item.getItemId()) {
                case MainActivity.SHAREAPP_ID:
                    Intent i = new Intent(LeadingMarginSpanActivity.this, 
    Share.class);
                    startActivity(i);
                    break;
                }

                return true;
            }
        }
</code></pre>
