gpt4 book ai didi

java - 单击按钮时调用类 (Android)

转载 作者:太空宇宙 更新时间:2023-11-03 10:42:50 25 4
gpt4 key购买 nike

我是 Android 开发新手。我有 2 个不同的类(MainActivity.java 和 Upload.java)
我在将 Upload.java 调用到 Main.Activity 时遇到问题。
当我点击按钮时,应用程序崩溃了。
我做错了什么吗?

主要 Activity .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");
}
}
}

上传.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);

}


}

关于java - 单击按钮时调用类 (Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30612732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com