Calling a class on ButtonClick (Android)

I am new to Android developer. I have 2 different classes (MainActivity.java and Upload.java)
I have a problem to call Upload.java in Main.Activity.
When I click the button, the application crashes.
Is there something I did wrong?

MainActivity.java

Button upload = (Button)findViewById(R.id.upload_Btn);

upload.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(View v) 
    {
        Update_Table dbClient = new  Update_Table();

        try {
            dbClient.DynamoDBClient();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            Log.i("sys", "Success");
        }
    }
}
Run code

Upload.java

public class Update_Table
{
    private String tableName = "Test";
    private AmazonDynamoDBClient client =null;
	
    public void DynamoDBClient() throws IOException
    {
        AWSCredentials cred = new PropertiesCredentials(Update_Table.class
				.getResourceAsStream("AwsCredentials.properties"));
		
        client = new AmazonDynamoDBClient(cred);
    }
}
Run code

LogCat: logcat

+4
source share
1 answer

Change the line in the method as shown below: -

 public class Update_Table
    {
        private String tableName = "Test";
        private AmazonDynamoDBClient client =null;

        public void DynamoDBClient() throws IOException
        {

       //changed the below line 
            AWSCredentials cred = new PropertiesCredentials(ClassLoader.getResourceAsStream("src/com.afdal.ftsmetheses/AwsCredentials.properties"));

//OR try this

AWSCredentials cred = new PropertiesCredentials(ClassLoader.getResourceAsStream("com.afdal.ftsmetheses/AwsCredentials.properties"));

            client = new AmazonDynamoDBClient(cred);

        }


    }
+1
source

All Articles