2012-08-15 123 views
0

我想调用一个方法来创建将位图转换为Base64字符串,并且出于某种原因,encode()方法对我不起作用。位图到Base64转换不起作用

这里是我创建将图像转换成字节数组的方法,包括:

public byte[] getImageBytes() { 
    byte[] picBytes = null; 
    try{ 
     //ImageButton ppView = (ImageButton) findViewById(R.id.icon); 
     String base64 = profileMap.get("WHOOZNEAR_PROFILEPIC"); 
     picBytes = Base64.decode(base64, Base64.DEFAULT); //works with android 2.2 and higher 
     //byte[] picBytes = Base64.decode(base64); 
     //Bitmap bitmap = BitmapFactory.decodeByteArray(picBytes, 0, picBytes.length); 
     //if (bitmap != null) 
      //ppView.setImageBitmap(bitmap); 
    }  
    catch (Exception e) 
    { 
     Log.e(TAG, "unhandled exception when attempting to set profile image"); 
     //Toast.makeText(getBaseContext(), "No profile image selected", Toast.LENGTH_LONG).show(); 
    } 

    return picBytes; 
} 

这里是我创建位图转换为Base64字符串的方法:

public String BitMapToString(Bitmap bitmap){ 
    String temp = ""; 
    Bitmap temp_Bitmap = bitmap; 
    if (temp_Bitmap != null) { 
     try { 
       ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
       temp_Bitmap.compress(Bitmap.CompressFormat.PNG, 0, baos); 
       byte[] b=baos.toByteArray(); 
       temp=Base64.encodeToString(getImageBytes(), Base64.DEFAULT); 
     } 
     catch(Exception e){ 
       Log.e(LOG_TAG,"[ONACTIVITYRESULT] Could not bind input to the bytearray: " + e.getMessage()); 
     } 
    } 
    return temp; 
} 

这是整个文件:

import java.io.ByteArrayOutputStream; 

import java.io.FileInputStream; 

import java.util.ArrayList; 

import java.util.HashMap; 

import java.util.LinkedHashMap; 

import java.util.Set; 

import java.util.Map.Entry; 



/*import javax.jmdns.ServiceEvent; 

import javax.jmdns.ServiceInfo;*/ 




import android.app.Activity; 

import android.content.Context; 

import android.content.Intent; 

import android.graphics.Bitmap; 

import android.graphics.BitmapFactory; 

import android.os.Bundle; 

import android.util.Base64; 

import android.util.Log; 

import android.view.LayoutInflater; 

import android.view.Menu; 

import android.view.MenuItem; 

import android.view.View; 

import android.view.ViewGroup; 

import android.widget.BaseAdapter; 

import android.widget.ImageButton; 

import android.widget.ListView; 

import android.widget.TextView; 

import android.widget.Toast; 



public class ProfileActivity extends Activity { 



private static final int NEAR = Menu.FIRST; 

private final static String LOG_TAG = ProfileActivity.class.getSimpleName(); 

//ServiceInfo info = null; 

private static final String TAG = "ProfileActivity"; 

protected LinkedHashMap<String, String> profileMap; 

protected static ArrayList<Entry<String, String>> profileArrayList; 

private Set<Entry<String, String>> profileSet; 

//private Context context; 

protected static final boolean D = false; 

protected static byte[] input; 



protected ListView profileList; 

private TextView nameView; 

private TextView tagLineView; 

protected ProfileAdapter customAdapter; 

private ImageButton buttonReturnToNearby; 

private TextView screenNameView; 

private Profile profile = new Profile(); 

private Bitmap profBitmap; 



protected static class ProfileAdapter extends BaseAdapter { 



    private LayoutInflater mInflater; 



    public ProfileAdapter(Context context) { 

     mInflater = LayoutInflater.from(context); 

    } 



    public int getCount() { 

     return profileArrayList.size(); 

    } 



    public Object getItem(int arg0) { 

     return profileArrayList.get(arg0); 

    } 



    public long getItemId(int position) { 



     return position; 

    } 



    public View getView(int position, View convertView, ViewGroup parent) { 

     // A ViewHolder keeps references to children views to avoid unnecessary calls 

     // to findViewById() on each row. 

     ViewHolder holder; 



     // When convertView is not null, we can reuse it directly, there is no need 

     // to reinflate it. We only inflate a new View when the convertView supplied 

     // by ListView is null. 

     if (convertView == null) { 

      convertView = mInflater.inflate(R.layout.peer_profile_row, null, false); 



      // Creates a ViewHolder and store references to the two children views 

      // we want to bind data to. 

      holder = new ViewHolder(); 

      holder.propertyName = (TextView) convertView.findViewById(R.id.propertyName); 

      holder.propertyValue = (TextView) convertView.findViewById(R.id.propertyValue); 

      //TODO: Put a default view here or something if it is a phone or email 

      //holder.icon = (ImageView) convertView.findViewById(); 



      convertView.setTag(holder); 

     } else { 

      // Get the ViewHolder back to get fast access to the TextView 

      // and the ImageView. 

      holder = (ViewHolder) convertView.getTag(); 

     } 



     // Bind the data efficiently with the holder.    

     //TODO: Make this correct 



     holder.propertyName.setText(profileArrayList.get(position).getKey()); 

     holder.propertyValue.setText(profileArrayList.get(position).getValue()); 



     return convertView; 

    } 



    class ViewHolder { 

     TextView propertyName; 

     TextView propertyValue; 

    } 



    public boolean isEmpty() { 



     return profileArrayList.isEmpty(); 

    } 

}; 



/* 

public void onStart(){ 

    super.onStart(); 

    if (D) {Log.i(TAG, "++++ ON START +++++"); } 



} 

    */ 

@Override 

public void onCreate (Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_profile_display); 



    //if (D) {Log.i(TAG, "++++ ON CREATE +++++"); } 



    HashMap<String, String> temp = new HashMap<String, String>(); 



    try 

    { 

     temp = (HashMap<String, String>) profileMap; 



     //THE LINE BELOW NEEDS TO BE UNCOMMENTED TO RECEIVE THE ATTRIBUTES 4/9/12 

     temp = (HashMap<String, String>) this.getIntent().getSerializableExtra("ProfileData"); 

     temp = profile.getAllAttributesIncludingPicture(); 

     profile.setTagLine(temp.get("TagLine")); 

     profile.setProfilePicStr(temp.get("WHOOZNEAR_PROFILEPIC")); 

     profile.setWhatIDo(temp.get("What I Do")); 

    } 

    catch (Exception e) 

    { 

     Log.e(TAG, "Runtime Exceptions suck"); 

    } 



    if (temp != null) { 

     profileMap = new LinkedHashMap<String, String> (temp);  

     //profileMap = profile.getAllAttributesIncludingPicture(); 

    } 

    else 

    { 

     Log.e(TAG, "temp HashMap is NULL"); 

    } 



    setProfile(profile); 



    screenNameView = (TextView) findViewById(R.id.ab_screen_name); 

    screenNameView.setText("Peer Profile"); 



    buttonReturnToNearby = (ImageButton) findViewById(R.id.btn_nearby); 

    buttonReturnToNearby.setOnClickListener(new View.OnClickListener() { 



     public void onClick(View v) { 

      try { 

       Log.e(TAG, "commented out call to WhoozNearActivity"); 

       /* 

       if(profileMap.get("Name") != null && profileMap.get("Name").compareTo("Set a new value") != 0 

         && profileMap.get("Age") != null && profileMap.get("Age").compareTo("Set a new value") != 0 

         && profileMap.get("Looking") != null && profileMap.get("Looking").compareTo("Set a new value") != 0){ 

        float age = Float.parseFloat(profileMap.get("Age")); 

        Intent mainIntent = new Intent(getBaseContext(), WhoozNearActivity.class); 

        startActivity(mainIntent); 

        //finish(); 

       } else { 

        Toast.makeText(getBaseContext(), "Please, enter values for Name, Age and Looking", Toast.LENGTH_LONG).show(); 

       } 

       */ 

      } catch (NumberFormatException nfe) { 

       nfe.printStackTrace(); 

       Toast.makeText(getBaseContext(), "Value Age is not correct", Toast.LENGTH_LONG).show(); 

      } catch (NullPointerException npe) { 

       npe.printStackTrace(); 

       Toast.makeText(getBaseContext(), "Error", Toast.LENGTH_LONG).show(); 

      } 

     } 

    }); 



    setupAdapter(); 

    setProfile(profile); 

    //updateProfileList(); //extra call to update is not required 

    setupViews(); 



    Log.e(TAG, "profile map data after creation: " + profileMap); 



    //Log.e(TAG, "Get Profile Pic STR:"+getProfilePicStr()); 

    //Log.e(TAG, "Get Image STR:"+getImageStr()); 

} 



public void setProfile(Profile profile) { 

    this.profileMap = profile.getAllAttributes(); 

    updateProfileList(); 

    Log.e(TAG, "profile map data after setProfile: " + profileMap); 

} 



public String getTagline() { 

    return profileMap.get("TagLine"); 

} 



public String getName() { 

    Log.e(TAG, "Got the NAME!"); 

    return profileMap.get("Name"); 

} 



/*public void setProfilePic() { 

    Log.e(TAG, "SET THE PROFILE PIC!!"); 



}*/ 



public LinkedHashMap<String, String> getProfileMap() { 

    return profileMap; 

} 



public void setupAdapter() { 

    customAdapter = new ProfileAdapter(this); 

} 



public void setupViews() { 



    if (profileList == null) { 

     profileList = (ListView) findViewById(R.id.profile_list); 

     profileList.setAdapter(customAdapter); 

    } 



    nameView = (TextView) findViewById(R.id.profileNameLine); 

    nameView.setText(profileMap.get("Name")); 

    tagLineView = (TextView) findViewById(R.id.profileTagLine); 

    tagLineView.setText(profileMap.get("TagLine")); 



    //try to set profile pic, otherwise use default 

    try{ 

     ImageButton ppView = (ImageButton) findViewById(R.id.btn_whooznear); 

     String base64 = profileMap.get("WHOOZNEAR_PROFILEPIC"); 

     //base64 = ConvertandSetImagetoBase64(profile.getSelectedImgPath()); 

     //Log.e("LOG_TAG", "ProfileActivity Base64 String:"+base64); 



     //SET THE LOCAL PROFILE PIC STR 

     profile.setProfilePicStr(base64); 



     byte[] picBytes = Base64.decode(base64, Base64.DEFAULT); //works with android 2.2 and higher 

     //byte[] picBytes = Base64.decode(base64); 

     Bitmap bitmap = BitmapFactory.decodeByteArray(picBytes, 0, picBytes.length); 

     if (bitmap != null) { 

      setProfileBitmap(bitmap); 

      ppView.setImageBitmap(bitmap); 

     } 

    }  

    catch (Exception e) 

    { 

     Log.e(TAG, "unhandled exception when attempting to set profile image:" + e.getMessage()); 
     Toast.makeText(getBaseContext(), "No profile image selected", Toast.LENGTH_LONG).show(); 
    } 
} 

/*public String getImageStr() { 

    return profileMap.get("WHOOZNEAR_PROFILEPIC").toString(); 

}*/ 

/*public String getProfilePicStr() { 
    return profileMap.get("ProfilePic").toString(); 
}*/ 

/*public String ConvertandSetImagetoBase64(String imagePath) { 
     String base64 = null; 
     byte[] input = null; 

     try{ 

      FileInputStream fd = new FileInputStream(imagePath); 
      Bitmap bmt = BitmapFactory.decodeFileDescriptor(fd.getFD()); 

      try{     
       ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
       Bitmap tmp = ProfileActivity.scaleDownBitmap(bmt, 10, this); 
       tmp.compress(Bitmap.CompressFormat.JPEG, 10, stream); 
       input = stream.toByteArray(); 
       base64 = Base64.encodeToString(input, Base64.DEFAULT); 

       //LocalProfileActivity.input = input; 

      }catch(Exception e){ 
       Log.e(LOG_TAG,"[ONACTIVITYRESULT] Could not bind input to the bytearray: " + e.getMessage()); 
      } 
     } 
     catch (Exception e){ 
      Log.e("LocalProfile", "Could not load selected profile image"); 
     } 
     return base64; 
    }*/ 

public void setProfileBitmap(Bitmap profBitmap) { 
    this.profBitmap = profBitmap; 
} 

public Bitmap getProfileBitmap() { 
    return profBitmap; 
} 


public String GetBase64ImgString() { 
    String base64Str = Base64.encodeToString(getImageBytes(), Base64.DEFAULT); 
    return base64Str; 
} 

public String BitMapToString(Bitmap bitmap){ 
    String temp = ""; 
    Bitmap temp_Bitmap = bitmap; 
    if (temp_Bitmap != null) { 
     try { 
       ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
       temp_Bitmap.compress(Bitmap.CompressFormat.PNG, 0, baos); 
       byte[] b=baos.toByteArray(); 
       temp=Base64.encodeToString(getImageBytes(), Base64.DEFAULT); 
     } 

     catch(Exception e){ 

       Log.e(LOG_TAG,"[ONACTIVITYRESULT] Could not bind input to the bytearray: " + e.getMessage()); 

     } 

    } 

    return temp; 

} 



public Bitmap StringToBitMap(String encodedString){ 

    try{ 

     byte[] encodeByte=Base64.decode(encodedString,Base64.DEFAULT); 

     Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length); 

     return bitmap; 

    }catch(Exception e){ 

     e.getMessage(); 

     return null; 

    } 

} 



public byte[] getImageBytes() { 

    byte[] picBytes = null; 

    try{ 

     //ImageButton ppView = (ImageButton) findViewById(R.id.icon); 

     String base64 = profileMap.get("WHOOZNEAR_PROFILEPIC"); 

     picBytes = Base64.decode(base64, Base64.DEFAULT); //works with android 2.2 and higher 

     //byte[] picBytes = Base64.decode(base64); 

     //Bitmap bitmap = BitmapFactory.decodeByteArray(picBytes, 0, picBytes.length); 

     //if (bitmap != null) 

      //ppView.setImageBitmap(bitmap); 

    }  

    catch (Exception e) 

    { 

     Log.e(TAG, "unhandled exception when attempting to set profile image"); 

     //Toast.makeText(getBaseContext(), "No profile image selected", Toast.LENGTH_LONG).show(); 

    } 



    return picBytes; 

} 



public void updateProfileList() { 



    try 

    { 



    LinkedHashMap <String, String> temp = (LinkedHashMap<String, String>) profileMap.clone(); 

    temp.remove("Name"); 

    temp.remove("TagLine"); 

    temp.remove("ProfileName"); 



    profileSet = temp.entrySet(); 



    } 

    catch(NullPointerException e) 

    { 

     e.printStackTrace(); 

     Log.i(TAG, "exception in thread: updateProfileList() ... profile map: " + profileMap); 

    } 







    //Profile personfound = new Profile(); 



      //personfound.addAttribute("age", info.getPropertyBytes("profilePic")); 

      //personfound.addAttribute("name", profileMap.get("name")); 

      //personfound.addAttribute("age", info.getPropertyString("age")); 

      //personfound.addAttribute("gender", info.getPropertyString("gender")); 

      //personfound.addAttribute("name", info.getPropertyString("name")); 

    //getProfile(personfound); 







    //profileArrayList = new ArrayList(Arrays.asList(profileArray)); 

    if (profileArrayList == null) 

     profileArrayList = new ArrayList(); 

    else 

     profileArrayList.clear(); 



    for (Entry<String, String> e : profileSet) { 

     profileArrayList.add(e); 

    } 

    if (profileList != null) 

     if (profileList.getAdapter() != null) 

      customAdapter.notifyDataSetChanged(); 



    Log.e(TAG, "profile map data after update: " + profileMap + profileMap.get("WHOOZNEAR_PROFILEPIC")); 

} 



public Profile getProfile(Profile profilePersonFound) { 

    return profilePersonFound; 

} 



public void onNameClick (View v) { 

    return; 

} 



public boolean onCreateOptionsMenu(Menu menu) { 

    menu.add(0, NEAR, 0, "NearBy").setIcon(android.R.drawable.ic_menu_info_details); 

    return true; 

} 



@Override 

public boolean onOptionsItemSelected(MenuItem item) { 



    switch (item.getItemId()) { 

    case NEAR: 

     try { 



      /*if(profileMap.get("Name") != null && profileMap.get("Name").compareTo("Set a new value") != 0 

        && profileMap.get("Age") != null && profileMap.get("Age").compareTo("Set a new value") != 0 

        && profileMap.get("Looking") != null && profileMap.get("Looking").compareTo("Set a new value") != 0){ 

       float age = Float.parseFloat(profileMap.get("Age")); 

       Intent mainIntent = new Intent(this, WhoozNearActivity.class); 

       startActivity(mainIntent); 

       //finish(); 

      } else { 

       Toast.makeText(this, "Please, enter values for Name, Age and Looking", Toast.LENGTH_LONG).show(); 

      }*/ 

      String tagline = profileMap.get("TagLine"); 

      /*NeighborViewModel nv = new NeighborViewModel(); 

      nv.setNeighborDesc(profileMap.get("TagLine")); //Try setServiceDesc(); 

      String name = profileMap.get("Name"); 

      NeighborViewModel nv = null; 

      nv.setNeighborName(name);*/ 

      Profile profile = new Profile(); 

      profile.setProfileName(profileMap.get("Name")); 

      profile.setTagLine(profileMap.get("TagLine")); 



      if (profileMap.get("Name") != null) { 

       //Toast.makeText(this, "In If Statement", Toast.LENGTH_LONG).show(); 

       //Toast.makeText(this, tagline, Toast.LENGTH_LONG).show(); 

       //Intent Call 

       //Intent intent = new Intent(this, WhoozNearActivity.class); 

       //startActivity(intent); 



       //Pass the profile data so that it can be broadcasted in ConnectActivity.java 

       Intent myIntent = new Intent(ProfileActivity.this, 
        AndroidClient.class); 

       Toast.makeText(getBaseContext(), "In ProfileActivity", Toast.LENGTH_SHORT); 
       myIntent.putExtra("Props", profileMap); 
       startActivity(myIntent); 
      } 

      else { 
      Toast.makeText(this, "Please, enter values for Name", Toast.LENGTH_LONG).show(); 

     } 

     } catch (NumberFormatException nfe) { 

      nfe.printStackTrace(); 

      Toast.makeText(this, "Value Age is not correct", Toast.LENGTH_LONG).show(); 

     } catch (NullPointerException npe) { 

      npe.printStackTrace(); 

      Toast.makeText(this, "Error", Toast.LENGTH_LONG).show(); 

     } 
     break; 
    } 
    return true; 
} 
Bitmap ShrinkBitmap(byte[] file, int width, int height){ 
    BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options(); 
     bmpFactoryOptions.inJustDecodeBounds = true; 
     Bitmap bitmap; 
     int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)height); 
     int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)width); 

     if (heightRatio > 1 || widthRatio > 1) 
     { 
     if (heightRatio > widthRatio) 
     { 
     bmpFactoryOptions.inSampleSize = heightRatio; 
     } else { 
     bmpFactoryOptions.inSampleSize = widthRatio; 
     } 
     } 
     bmpFactoryOptions.inJustDecodeBounds = false; 
     bitmap = BitmapFactory.decodeByteArray(file, 0, file.length, bmpFactoryOptions); 
    return bitmap; 
    } 


public static Bitmap scaleDownBitmap(Bitmap photo, int newHeight, Context context) { 
    final float densityMultiplier = context.getResources().getDisplayMetrics().density;   

    int h= (int) (newHeight*densityMultiplier); 
    int w= (int) (h * photo.getWidth()/((double) photo.getHeight())); 

    photo=Bitmap.createScaledBitmap(photo, w, h, true); 

    return photo; 
    } 
} 

这是来自ProfileDBUtilities.java的getProfile()方法:

public Profile getProfile(int pId) { 
    Profile profile = null; 
    try { 
     // int profileID = pId; 
     // profileName = pName; 
     Cursor cursor = _activity.managedQuery(
       ProfileDBObject.Profile.CONTENT_URI, new String[] { 
         ProfileDBObject.Profile._ID, 
         ProfileDBObject.Profile.NAME, 
         ProfileDBObject.Profile.PROFILE_NAME }, "_ID = '" 
         + pId + "'", null, ProfileDBObject.Profile._ID); 

     profile = new Profile(); 
     profile.setProfileId(pId); 

     cursor.moveToFirst(); 
     int nameCol = cursor 
       .getColumnIndex(ProfileDBObject.Profile.PROFILE_NAME); 
     String profileName; 
     try { 
      profileName = cursor.getString(nameCol); 
     } 
     // If the profile ID doesn't exist, return the first profile in the 
     // DB 
     catch (Exception e) { 
      cursor = _activity.managedQuery(
        ProfileDBObject.Profile.CONTENT_URI, new String[] { 
          ProfileDBObject.Profile._ID, 
          ProfileDBObject.Profile.NAME, 
          ProfileDBObject.Profile.PROFILE_NAME }, null, 
        null, ProfileDBObject.Profile._ID); 
      cursor.moveToFirst(); 
      nameCol = cursor 
        .getColumnIndex(ProfileDBObject.Profile.PROFILE_NAME); 
      profileName = cursor.getString(nameCol); 
     } 

     profile.setProfileName(profileName); 

     cursor.close(); 
     // Start grabbing the related attributes 
     cursor = _activity.managedQuery(
       AttributeDBObject.Attribute.CONTENT_URI, new String[] { 
         AttributeDBObject.Attribute.ATTR_NAME, 
         AttributeDBObject.Attribute.ATTR_VALUE }, 
       "PROFILE_ID = '" + pId + "'", null, 
       AttributeDBObject.Attribute._ID); 
     cursor.moveToFirst(); 
     int aNameIndex = cursor 
       .getColumnIndex(AttributeDBObject.Attribute.ATTR_NAME); 
     int aValIndex = cursor 
       .getColumnIndex(AttributeDBObject.Attribute.ATTR_VALUE); 
     String aName; 
     String aValue; 
     // If there are attributes, add them to the profile 
     if (cursor.getCount() != 0) { 
      do { 
       aName = cursor.getString(aNameIndex); 
       aValue = cursor.getString(aValIndex); 
       profile.addAttribute(aName, aValue); 

      } while (cursor.moveToNext()); 
     } 
     cursor.close(); 
    } catch (Exception e) { 
     Log.e(LOG_TAG,"Error when getting profile from the db: " + e.getMessage()); 
    } 

    return profile; 
} 

这里是堆栈跟踪:

08-15 07:34:37.141: I/ActivityThread(382): Pub com.iconnexus.client: com.iconnexus.client.ProfileProvider 
08-15 07:34:37.351: D/dalvikvm(382): GC_EXTERNAL_ALLOC freed 57K, 53% free 2566K/5379K, external 1625K/2137K, paused 78ms 
08-15 07:34:41.581: E/ProfileDBUtilities(382): Error when getting profile from the db: Index 0 requested, with a size of 0 
08-15 07:34:41.651: E/ProfileActivity(382): profile map data after update: {}null 
08-15 07:34:41.651: E/ProfileActivity(382): profile map data after setProfile: {} 
08-15 07:34:41.651: E/ProfileActivity(382): profile map data after update: {}null 
08-15 07:34:41.661: E/ProfileActivity(382): profile map data after setProfile: {} 
08-15 07:34:41.671: E/ProfileActivity(382): unhandled exception when attempting to set profile image:null 
08-15 07:34:41.711: E/ProfileActivity(382): profile map data after creation: {} 
08-15 07:34:41.711: E/ProfileActivity(382): profile map data after update: {}null 
08-15 07:34:41.721: E/ProfileActivity(382): profile map data after setProfile: {} 
08-15 07:34:41.721: E/ProfileActivity(382): unhandled exception when attempting to set profile image:null 
08-15 07:34:41.991: E/ProfileActivity(382): LocalProfileActivity profileJSON: {"nameValues":{},"profileId":13,"valid":false} 
08-15 07:34:42.061: E/LocalProfile(382): ConvertandSetImagetoBase64: Could not load selected profile image 
08-15 07:34:42.071: E/LocalProfile(382): ConvertandSetImagetoBase64: Could not load selected profile image 
08-15 07:40:23.171: W/KeyCharacterMap(382): No keyboard for id 0 
08-15 07:40:23.193: W/KeyCharacterMap(382): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 
08-15 07:40:24.161: E/ProfileDBUtilities(382): Error when getting profile from the db: Index 0 requested, with a size of 0 
08-15 07:40:24.161: E/ProfileActivity(382): profile map data after update: {}null 
08-15 07:40:24.161: E/ProfileActivity(382): profile map data after setProfile: {} 
08-15 07:40:24.592: E/ProfileActivity(382): profile map data after update: {}null 
08-15 07:40:24.621: E/ProfileActivity(382): profile map data after setProfile: {} 
08-15 07:40:24.621: E/ProfileActivity(382): profile map data after update: {}null 
08-15 07:40:24.632: E/ProfileActivity(382): profile map data after setProfile: {} 
08-15 07:40:24.641: E/ProfileActivity(382): unhandled exception when attempting to set profile image:null 
08-15 07:40:24.691: E/ProfileActivity(382): profile map data after creation: {} 
08-15 07:40:24.711: E/AndroidClient(382): Before initEventHandlers 
08-15 07:40:24.711: E/AndroidClient(382): After initEventHandlers 
08-15 07:40:24.721: E/AndroidClient(382): Local Profile Map is null from intent in ConnectActivity 
08-15 07:40:25.101: E/AndroidClient(382): TAGLINE: null 
08-15 07:40:25.101: E/AndroidClient(382): WHOOZNEAR PIC:null 
08-15 07:40:25.111: E/AndroidClient(382): REGEX REPLACEALL:"Ryan" 
08-15 07:40:25.111: E/AndroidClient(382): temp_Bitmap is NULL!! 
08-15 07:40:25.141: E/ProfileActivity(382): unhandled exception when attempting to set profile image 
08-15 07:40:25.141: D/AndroidRuntime(382): Shutting down VM 
08-15 07:40:25.151: W/dalvikvm(382): threadid=1: thread exiting with uncaught exception (group=0x40015560) 
08-15 07:40:25.181: E/AndroidRuntime(382): FATAL EXCEPTION: main 
08-15 07:40:25.181: E/AndroidRuntime(382): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.iconnexus.client/com.iconnexus.client.AndroidClient}: java.lang.NullPointerException 
08-15 07:40:25.181: E/AndroidRuntime(382):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at android.os.Handler.dispatchMessage(Handler.java:99) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at android.os.Looper.loop(Looper.java:123) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at android.app.ActivityThread.main(ActivityThread.java:3683) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at java.lang.reflect.Method.invokeNative(Native Method) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at java.lang.reflect.Method.invoke(Method.java:507) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at dalvik.system.NativeStart.main(Native Method) 
08-15 07:40:25.181: E/AndroidRuntime(382): Caused by: java.lang.NullPointerException 
08-15 07:40:25.181: E/AndroidRuntime(382):  at android.util.Base64.encode(Base64.java:494) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at android.util.Base64.encodeToString(Base64.java:456) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at com.iconnexus.client.ProfileActivity.GetBase64ImgString(ProfileActivity.java:315) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at com.iconnexus.client.AndroidClient.onCreate(AndroidClient.java:266) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
08-15 07:40:25.181: E/AndroidRuntime(382):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
08-15 07:40:25.181: E/AndroidRuntime(382):  ... 11 more 
08-15 07:40:27.442: I/Process(382): Sending signal. PID: 382 SIG: 9 
+0

那么,你在哪里调用'BitMapToString(Bitmap)'? – martijno 2012-08-15 08:05:14

+0

您的logcat描述了在ProfileActivity类“ProfileActivity.java:315”中的315行号存在空指针异常 – rajpara 2012-08-15 08:19:49

回答

0

我认为这个问题是在你的BitMapToString(Bitmap bitmap)方法。

您将参数位为字节数组(B),然后没有使用它......

byte[] b=baos.toByteArray(); 
temp=Base64.encodeToString(getImageBytes(), Base64.DEFAULT); 

也许你应该使用bincodeToString方法...所以它应该是这样的。 ..

byte[] b=baos.toByteArray(); 
temp=Base64.encodeToString(b, Base64.DEFAULT); 

总之,不要在encodeToString方法调用getImageBytes()

希望这有助于...

如果您认为这个回答你的问题,请标记为“接受”。这会提高你的和我的声望得分。