0

im developing a app in Android. in this project im using a List of Objects and i need to convert the list object in byte array. but there is a null pointer exception shown in logcat? here is my coading.

class MyContact
{
    String Name;
    Bitmap Image;
    String Number;

    public MyContact(String cName, String cNumber, Bitmap cImage) {

        Name    = cName;
        Number  = cNumber;
        Image   = cImage;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public Bitmap getImage() {
        return Image;
    }

    public void setImage(Bitmap image) {
        Image = image;
    }

    public String getNumber() {
        return Number;
    }

    public void setNumber(String number) {
        Number = number;
    }
}



List<MyContact> list = new ArrayList<MyContact>();

I added some values to the List object, using

MyContact contactObj = new MyContact(name, phoneNo, photo);
 list.add(contactObj);

bla bla bla ....

and i need store the entire list object into the Android Mobiles local file. i used ,

FileOutputStream fos = openFileOutput( fileName, Context.MODE_PRIVATE);
 fos.write(toByteArray(MyTrackList));   // null pointer error occured here
 fos.close();

here is a byte array conversion coding.

public static byte[] toByteArray (Object obj)
    {
      byte[] bytes = null;
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      try {
        ObjectOutputStream oos = new ObjectOutputStream(bos); 
        oos.writeObject(obj);
        oos.flush(); 
        oos.close(); 
        bos.close();
        bytes = bos.toByteArray ();
      }
      catch (IOException ex) {
        //TODO: Handle the exception
      }
      return bytes;
    }

but returns null pointer exception in the line of above i marked in comment how can i resolve this problem. any suggestion? thanks in advance....


Manually schedule a job in sql server 2008

I want to create a schedule to manipulate some data on server. and i have store procedure which have some sql query. Now i want to exec this sp every day.

For that i have created job, schedule using sp_add_job, sp_add_schedule etc.. now all this needs to run on my clients server.

Now problem is that, I cant run these queries in client server as I don't have "sa" (admin) login. So is there any alternate way to run this query?

And also i cant create job from SQ L Server Agent in Object Explorer as I don't have rights to do it.

So Is there any way to create job on server?

4

2 回答 2

4
  catch (IOException ex) {
    //TODO: Handle the exception
  }

你的问题是:如果有一个 IOException,你的方法只会返回 null 而不会告诉你。

不要捕获异常,将方法更改为throws IOException(因为此时无论如何您都无能为力),然后找出导致它的原因。

很可能是因为您的MyContact类没有实现Serializable,因此无法将其写入 ObjectOutputStream。

此外,可以通过不使用中间字节数组并将 ObjectOutputStream 直接连接到 FileOutputStream 来提高性能和内存使用率。

于 2012-06-20T04:40:34.907 回答
0

@Thilo 很好地指出了可能的问题。您可以发布 Logcat 输出吗?

[ 建议 :

我通常推荐使用 JSON/XML 序列化,因为 Android SDK 支持一些非常好的 JSON/XML(DOM/SAX/XML pull) 实现。

  • 它们使您的本地文件可读、可移植。
  • 您甚至可以通过网络传输文件,也可以远程存储。

希望这会有所帮助,干杯!]

于 2012-06-20T04:54:27.917 回答