dimanche 14 juin 2015

Get value from EditText into table in AWS DynamoDB

I want to put new items from textbox wrote by users into existing table in DynamoDB. However, I have encountered some errors that I dont really understand. Below are my codes:

Add method

public void add()
    {
      
        final EditText title = (EditText)findViewById(R.id.text1);
        String tajuk = title.getText().toString();
      
        logMsg("Putting items into table" + tableName);
        Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();

        try {
           item.put("Id", new AttributeValue().withS(tajuk));

            PutItemRequest itemRequest = new PutItemRequest().withTableName(
                    tableName).withItem(item);
            client.putItem(itemRequest);
            item.clear();

        } catch (Exception e) {
            System.err.println("Create items failed.");
            System.err.println(e.getMessage());
        }
    }

MainActivity

public class Task extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {

            Looper.prepare();

            try
            {
                Add_Item db = new Add_Item();

                db.DynamoDBLoad();
                db.add();
                  
            } catch (Exception e)
            {
                e.printStackTrace();
            }
            Looper.myLooper().quit();
            return null;
        }
        protected void onPostExecute(String page)
        {
            //onPostExecute
        }
    }

Logcat errors

06-15 10:33:33.938  16885-17179/com.af.ftsm.testing W/System.err﹕java.lang.NullPointerException
06-15 10:33:33.938  16885-17179/com.af.ftsm.testing W/System.err﹕ at android.app.Activity.findViewById(Activity.java:1957)
06-15 10:33:33.938  16885-17179/com.af.ftsm.testing W/System.err﹕ at com.af.ftsm.testing.Add_Item.<init>(Add_Item.java:26)
06-15 10:33:33.938  16885-17179/com.af.ftsm.testing W/System.err﹕ at com.af.ftsm.testing.MainActivity$Task.doInBackground(MainActivity.java:50)
06-15 10:33:33.938  16885-17179/com.af.ftsm.testing W/System.err﹕ at com.af.ftsm.testing.MainActivity$Task.doInBackground(MainActivity.java:39)
06-15 10:33:33.938  16885-17179/com.af.ftsm.testing W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
06-15 10:33:33.938  16885-17179/com.af.ftsm.testing W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-15 10:33:33.938  16885-17179/com.af.ftsm.testing W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
06-15 10:33:33.938  16885-17179/com.af.ftsm.testing W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-15 10:33:33.938  16885-17179/com.af.ftsm.testing W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-15 10:33:33.938  16885-17179/com.af.ftsm.testing W/System.err﹕ at java.lang.Thread.run(Thread.java:841)

Is my method of adding items into table wrong or otherwise? Thank you.




Aucun commentaire:

Enregistrer un commentaire