为什么我的profileMap为null。它似乎没有保持填充,但我没有在任何地方清除它。我究竟做错了什么?每当我尝试打印出如logcat中的profileMap数据时,它都是null?
这是logcat:
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:24.721: E/AndroidClient(382): Before OnCreate() Try
08-15 07:40:24.731: E/AndroidClient(382): In OnCreate() Try
08-15 07:40:24.842: E/AndroidClient(382): Created Socket
08-15 07:40:24.851: E/AndroidClient(382): Created DataOutputStream
08-15 07:40:24.862: E/AndroidClient(382): Created DataInputStream
08-15 07:40:24.862: E/AndroidClient(382): Created Profile Instance
08-15 07:40:24.872: E/AndroidClient(382): Created Gson InstanceGetProfileJSONStr:{},"profileId":13,"valid":false}
08-15 07:40:25.043: E/AndroidClient(382): Get Profile JSON String:{"nameValues":{},"profileId":0,"valid":false}
08-15 07:40:25.043: E/AndroidClient(382): Converted Profile to JSON
08-15 07:40:25.053: E/AndroidClient(382): Before: outputJSON = gson.toJson(p);
08-15 07:40:25.053: E/AndroidClient(382): Created outputJSON:{},"profileId":13,"valid":false}
08-15 07:40:25.074: E/AndroidClient(382): Print Profile JSON String:{"nameValues":{},"profileId":13,"valid":false}
08-15 07:40:25.074: E/AndroidClient(382): LATER Print Profile JSON String:{},"profileId":13,"valid":false}
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
以下是ProfileActivity.java的代码: 包com.iconnexus.client;
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 com.iconnexus.client.R;
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();
}
}
});
//AndroidClient android = new AndroidClient();
//profile = android.getLocalProfile();
setProfile(profile);
setupAdapter();
//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+profileMap.get("WHOOZNEAR_PROFILEPIC"));
//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);
/*try{
if(input!= null){
Bitmap b = ShrinkBitmap(input, 10,10);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 10, stream);
byte[] byteArray = stream.toByteArray();
String base64Image = Base64.encodeToString(byteArray, Base64.DEFAULT);
//SETS THE PROFILE PIC STRING IN BASE64 TO THE PROFILE CLASS
profile.setProfilePicStr(base64Image);
//Log.i(LOG_TAG, "Image:"+base64Image);
int imageSize = base64Image.length();
Log.i(LOG_TAG, "WholeImage:"+base64Image);
Log.i(LOG_TAG,"Image Size: " + imageSize);
int chunkSize = 200;
int numSplits = imageSize/chunkSize;
Log.i(LOG_TAG,"Num splits: " + numSplits);
int i =0;
int index = 0;
for(index =0; index < numSplits; index++){
String tmp = base64Image.substring(i, i+chunkSize);
i+=chunkSize;
Log.i(LOG_TAG,"Index = " +i);
Log.i(LOG_TAG,"Breaking image into pieces of size : " + tmp.length());
profileMap.put("ProfilePic"+ index, tmp);
}
String tmp = base64Image.substring(i);
profileMap.put("ProfilePic"+index, tmp);
}
}catch(Exception e){
Log.e(LOG_TAG,"Image parsing error: " +e.getMessage());
e.printStackTrace();
}*/
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;
}
}
答案 0 :(得分:1)
基于LogCat和您的代码,看起来profileMap.get(String)返回null,然后传递给Base64。 Base64(显然)无法处理null参数。