2016-11-09 7 views
0

で、インターネット上のアマゾンのドキュメントと様々なチュートリアルを、以下のにもかかわらず、まだ私はこれらのエラーを把握することができないよ:ここストアユーザの名前と姓DynamoDBの

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 
        Process: com.creation.shud, PID: 19262 
        java.lang.RuntimeException: An error occured while executing doInBackground() 
         at android.os.AsyncTask$3.done(AsyncTask.java:304) 
         at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) at java.util.concurrent.FutureTask.setException(FutureTask.java:222) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)at java.lang.Thread.run(Thread.java:818) 
        Caused by: java.lang.SecurityException: ConnectivityService: Neither user 10244 nor current process has android.permission.ACCESS_NETWORK_STATE. 
         at android.os.Parcel.readException(Parcel.java:1553) 
         at android.os.Parcel.readException(Parcel.java:1505) 
         at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:964)at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:622)at com.amazonaws.mobileconnectors.cognito.DefaultDataset.isNetworkAvailable(DefaultDataset.java:580)at com.amazonaws.mobileconnectors.cognito.DefaultDataset.synchronize(DefaultDataset.java:128)at com.creation.shud.Manager.getCredentials(Manager.java:41)at com.creation.shud.EnterUser$UpdateTable.doInBackground(EnterUser.java:44)at com.creation.shud.EnterUser$UpdateTable.doInBackground(EnterUser.java:38)at android.os.AsyncTask$2.call(AsyncTask.java:292)at java.util.concurrent.FutureTask.run(FutureTask.java:237)at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818)  I/Process: Sending signal. PID: 19262 SIG: 9 Application terminated. 

は私のコードです:

EnterUser.java

public class EnterUser extends AppCompatActivity { 
    EditText editText_name, editText_lastname; 
    Button button_submit; 
    String name, lastname; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_enter_user); 
    editText_name = (EditText) findViewById(R.id.et_name); 
    editText_lastname = (EditText) findViewById(R.id.et_lastname); 
    button_submit = (Button) findViewById(R.id.btn_submit); 
    name = editText_name.getText().toString(); 
    lastname = editText_lastname.getText().toString(); 
    button_submit.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      new UpdateTable().execute(); 
     } 
    }); 
    } 

    private class UpdateTable extends AsyncTask<Void, Integer, Integer> { 

    @Override 
    protected Integer doInBackground(Void... voids) { 
     try { 
      Manager manager = new Manager(); 
      CognitoCredentialsProvider credentialsProvider = manager.getCredentials(EnterUser.this); 
      MapperClass mapperClass = new MapperClass(); 
      mapperClass.setName(name); 
      mapperClass.setLastname(lastname); 
      if (credentialsProvider != null && mapperClass != null) { 
       DynamoDBMapper dynamoDBMapper = manager.initDynamoClient((CognitoCachingCredentialsProvider) credentialsProvider); 
       dynamoDBMapper.save(mapperClass); 
      } else { 
       return 2; 
      } 
      return 1; 

     } catch (AmazonClientException ex) { 
      ex.printStackTrace(); 
      return 9999; 
     } 
    } 

    @Override 
    protected void onPostExecute(Integer integer) { 
     super.onPostExecute(integer); 
     if(integer==1){ 
      Toast.makeText(EnterUser.this, "Entered successfully :) ", Toast.LENGTH_SHORT).show(); 
     }else if(integer==2){ 
      Toast.makeText(EnterUser.this, "TRY AGAIN!!!.YOU are going to do it", Toast.LENGTH_SHORT).show(); 
     }else{ 
      Toast.makeText(EnterUser.this, "**Exception Caught**", Toast.LENGTH_SHORT).show(); 
     } 
    } 
    } 
} 

これは、ユーザー入力を取得し、DynamoDBの

01に保存することです

ここMapperClass.java

@DynamoDBTable(tableName = "shtable") 
public class MapperClass { 
    String name; 
    String lastname; 

    public String getName() { 
    return name; 
    } 

    public void setName(String name) { 
    this.name = name; 
    } 

    public String getLastname() { 
    return lastname; 
    } 

    public void setLastname(String lastname) { 
    this.lastname = lastname; 
    } 
} 

であり、ここでManager.javaクラス

によって引き起こさ
public class Manager { 
    CognitoCredentialsProvider credentialsProvider =null; 
    CognitoSyncManager syncManager = null; 

    public static AmazonDynamoDBClient dynamoDBClient =null; 
    public static DynamoDBMapper dynamoDBMapper = null; 


    public CognitoCredentialsProvider getCredentials(Context context){ 
    // Initialize the Amazon Cognito credentials provider 
    CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
      context, 
      "us-west-2:######-$$$$-!!!!-8795-!!f#####9###", // Identity  Pool ID 
      Regions.US_WEST_2 // Region 
    ); 
    syncManager = new CognitoSyncManager(context,Regions.US_WEST_2,credentialsProvider); 
    Dataset dataset = syncManager.openOrCreateDataset("Mydataset"); 
    dataset.put("mykey","myvalue"); 
    dataset.synchronize(new DefaultSyncCallback()); 
    return credentialsProvider; 
    } 
} 

public DynamoDBMapper initDynamoClient(CognitoCachingCredentialsProvider credentialsProvider){ 
    if(dynamoDBClient==null){ 
    dynamoDBClient = new AmazonDynamoDBClient(credentialsProvider); 
     dynamoDBClient.setRegion(com.amazonaws.regions.Region.getRegion(Regions.US_WEST_2)); 
    dynamoDBMapper =new DynamoDBMapper(dynamoDBClient); 
    } 

    return dynamoDBMapper; 
} 

答えて

0

」されている間:java.lang.SecurityException:ConnectivityService:ユーザー10244も現在のプロセスのいずれもが を持っていますandroid.permission.ACCESS_NETWORK_STATE "重要な問題です。

アプリは、サイドノートとしてACCESS_NETWORK_STATE権限(チェックアウトhttps://developer.android.com/guide/topics/manifest/uses-permission-element.html

を宣言していない、私はあなたがgetCredentialsメソッド内CognitoSyncマネージャを初期化している理由はわからないんだけど...しかし、あなたはおそらくしたいですそれを分離してください。

+0

ありがとうございます。しかし、これは 'dynamoDBMapper.save(mapperClass);'文にエラーを表示します。 – ManveenT

関連する問題