public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ParseObject.registerSubclass(MyFirstClass.class);
        Parse.initialize(this, "Id", "Id");

        Button button = (Button)findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                    callSearch();
            }
        });

        ParseUser user = new ParseUser();
        user.setUsername("username");
        user.setPassword("password");

        /*user.signUpInBackground(new SignUpCallback() {

            @Override
            public void done(ParseException arg0) {
                // TODO Auto-generated method stub
                Toast.makeText(MainActivity.this, "signed in", Toast.LENGTH_LONG).show();
            }
        });*/

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        MyFirstClass object = new MyFirstClass();
        object.add("one", "1000");
        object.add("two", "22");
        object.saveInBackground();

        Toast.makeText(this, "saved in server", Toast.LENGTH_SHORT).show();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }


    protected void callSearch() {
         ParseQuery<MyFirstClass> query = MyFirstClass.getQuery();
         query.whereEqualTo("one", "1000");
         query.findInBackground(new FindCallback<MyFirstClass>() {

            @Override
            public void done(List<MyFirstClass> arg0, ParseException arg1) {
                if(arg0 ==null || arg0.isEmpty()) {
                    Toast.makeText(MainActivity.this,"  <-- hi this is the string. " ,Toast.LENGTH_LONG).show();
                } else {
                    for(MyFirstClass myFirstClass : arg0) {
                        int str = myFirstClass.getInt("two");
                        System.out.print(str);
                    Toast.makeText(MainActivity.this, "not null " + str + " " + arg0.size() + " " + myFirstClass.getString("one") + " " + myFirstClass.getObjectId() + " " + myFirstClass.getOne() + " " + myFirstClass.toString(), Toast.LENGTH_LONG).show();
                    break;
                    }
                }

            }
        })  ;   
    }

I m using parse here. I am able to get the list size correctly in callSearch() function. But when I retrieving the values for the fields like one, two. they are coming as null. Can someone help me in this?
Class Name: MyFirstClass
Fields: one, two (both strings)
Thanks in advance.
P.S Sorry for the code style and variable names. It's just a rough code to check something.

Is your MyFirstClasssome sort of map? Please share that class or we will not be able to help...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.