单击按钮时调用 class (Android)
Calling class on ButtonClick (Android)
我是 Android 开发人员的新手。我有 2 个不同的 class (MainActivity.java & Upload.java)
我无法将 Upload.java 调用到 Main.Activity。
当我点击按钮时,应用程序崩溃了。
我做错了什么吗?
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");
}
}
}
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);
}
}
LOGCAT:
更改方法中的行,如下所示:-
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);
}
}
我是 Android 开发人员的新手。我有 2 个不同的 class (MainActivity.java & Upload.java)
我无法将 Upload.java 调用到 Main.Activity。
当我点击按钮时,应用程序崩溃了。
我做错了什么吗?
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");
}
}
}
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);
}
}
LOGCAT:
更改方法中的行,如下所示:-
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);
}
}