开发者

Android Null-Pointer-Exception can't find a solution

开发者 https://www.devze.com 2023-04-06 06:44 出处:网络
I\'m working on an application which communicates with server and receiving a data stream,which is like 60-80k symbols.So I am splitin\' that string and calculating the stream into a pieces and when I

I'm working on an application which communicates with server and receiving a data stream,which is like 60-80k symbols.So I am splitin' that string and calculating the stream into a pieces and when I get the type of the stream I create an instance of class like this :

BasePacket packet=null; // this is the base packet
if(packetType=1)
    startPacket packet = new startPacket(params) // startPacket class extends BasePacket

if(packetType=2)
    endPacket packet = new endPacket(params) // endPacket class extends BasePacket
......

In startPacket I create instance to userPacket which extends BasePacket too:

userPacket user; // in startPacket

I have another class which is RPCCommunicator where I include all the methods which I need to communicate with server.

In RPCCommnicator I have :

userPacket user;
startPacket startP;
.......

And here is my problem... In RPCCOmmunicator I have a method like this :

    private static Integer localUserIdByServerUserId(int serverUserId, String serverName,Context context){

    try {
        dbHelper = new DataBaseHelper(context, "opa_sys_tpl.sqlite", null, 1);
        dbHelper.checkDatabase("opa_sys_tpl.sqlite");
        dbHelper.copyDataBase("opa_sys_tpl.sqlite");
    } catch (IOException e) {
        e.printStackTrace();
    }
    dbHelper.getDatabase();

    String query = "SELECT id FROM users WHERE objectId = "+serverUserId+" AND serverName = '"+serverName+"' LIMIT 1";
    ArrayList<String> result = new ArrayList<String>();
    cursor = dbHelper.executeSQLQuery(query);
    cursor.moveToFirst();
    while(!cursor.isAfterLast()开发者_如何学JAVA) {
        result.add(cursor.getString(cursor.getColumnIndex("id")));
         cursor.moveToNext();
    }

    Log.i("result ","Result : "+result.toString());
    Log.i("CURSOR ","Cursor Position : "+cursor.getPosition());
    Integer uuid = Integer.parseInt(result.get(cursor.getColumnIndex("id")));
    Log.w("localUSerByIdServerUserId","LocalUserByIdServerUserId result : "+uuid);
    cursor.close();
    return uuid;
}

and I'm calling it in startPacket like this :

int uuId = rpc.lUserIdByServerUserId(userId,newServerName,context);

And the NullPointerException it throws on that last line and I can't find how to fix it.I'm using a helper class for my database so I don't think that the problem is there,but here is a link to my DataBaseHelper.class code : DatabaseHelper.class.

So thanks in advance!!!


If this line

int uuId = rpc.lUserIdByServerUserId(userId,newServerName,context);

is indeed the line that throws the exception, rpc must be null.

Use a debugger to step through the program to find out why this is the case.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号