2015-06-03 21 views
4

我是Android開發人員的新手。我有2個不同的類(MainActivity.java & Upload.java)
我有問題可以調用Upload.java到Main.Activity。
當我點擊按鈕時,應用程序崩潰。
有什麼我做錯了嗎?ButtonClick上的調用類(Android)

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; 
 
\t 
 
    public void DynamoDBClient() throws IOException 
 
    { 
 
     AWSCredentials cred = new PropertiesCredentials(Update_Table.class 
 
\t \t \t \t .getResourceAsStream("AwsCredentials.properties")); 
 
\t \t 
 
     client = new AmazonDynamoDBClient(cred); 
 
    } 
 
}

logcat的: logcat

+1

你能提供你的logcat日誌有錯誤嗎? –

+0

是的,當然。我已經爲您提供了logcat – Batman

回答

1

變化像下面的方法中的線: -

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); 

     } 


    } 
+0

我已經嘗試過但是.getResouceAsStream無法識別 – Batman

+0

「AwsCredentials.properties」是一個文件,它駐留在您的src文件夾中,您可以檢查並告訴我 – Pankaj

+0

告訴文件的路徑一個例如: - src/com.pkgname/egfile.txt – Pankaj