J'ai une activité d'enregistrement qui, selon les cases à cocher sélectionnées par l'utilisateur, fait un appel asynchrone au serveur pour aller chercher les compétences pertinentes aux sélectionnés champ. J'utilise la rénovation pour la même chose. J'ai défini une classe SQLQuery
dont le constructeur prend un paramètre String. Maintenant, le problème est que lorsque j'appelle le constructeur avec un argument String, il affiche une erreur Array type expected found java.lang.String
. S'il vous plaît, quelqu'un m'aider à résoudre ce problème.constructeur défini pour prendre la chaîne mais l'invocation de méthode montre l'erreur 'Type de tableau attendu trouvé java.lang.String'
Merci à l'avance ici est mon fichier java
package com.example.vishal.internshipseekerapp;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class StudentRegistration extends AppCompatActivity implements View.OnClickListener {
private final int numFields = 13;
boolean[] checkField = new boolean[13];
String[] field = {"computer vision", "content writing", "data mining", "electrical/electronics", "game development", "image processing", "marketing", "mechanical engineering", "mobile app dev", "programming", "software dev", "web dev"};
Set<Skill> skill = new HashSet<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_registration);
ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
// register onclick listener for all checkboxes
(findViewById(R.id.field0)).setOnClickListener(this);
(findViewById(R.id.field1)).setOnClickListener(this);
(findViewById(R.id.field2)).setOnClickListener(this);
(findViewById(R.id.field3)).setOnClickListener(this);
(findViewById(R.id.field4)).setOnClickListener(this);
(findViewById(R.id.field5)).setOnClickListener(this);
(findViewById(R.id.field6)).setOnClickListener(this);
(findViewById(R.id.field7)).setOnClickListener(this);
(findViewById(R.id.field8)).setOnClickListener(this);
(findViewById(R.id.field9)).setOnClickListener(this);
(findViewById(R.id.field10)).setOnClickListener(this);
(findViewById(R.id.field11)).setOnClickListener(this);
//(findViewById(R.id.field12)).setOnClickListener(this);
// register onclick listener for DONE button
Button done = (Button) findViewById(R.id.field_select_done);
done.setOnClickListener(this);
}
public void onClick(View v){
switch(v.getId()){
case R.id.field0:
if(((CheckBox) v).isChecked())
checkField[0] = true;
case R.id.field1:
if(((CheckBox) v).isChecked())
checkField[1] = true;
case R.id.field2:
if(((CheckBox) v).isChecked())
checkField[2] = true;
case R.id.field3:
if(((CheckBox) v).isChecked())
checkField[3] = true;
case R.id.field4:
if(((CheckBox) v).isChecked())
checkField[4] = true;
case R.id.field5:
if(((CheckBox) v).isChecked())
checkField[5] = true;
case R.id.field6:
if(((CheckBox) v).isChecked())
checkField[6] = true;
case R.id.field7:
if(((CheckBox) v).isChecked())
checkField[7] = true;
case R.id.field8:
if(((CheckBox) v).isChecked())
checkField[8] = true;
case R.id.field9:
if(((CheckBox) v).isChecked())
checkField[9] = true;
case R.id.field10:
if(((CheckBox) v).isChecked())
checkField[10] = true;
case R.id.field11:
if(((CheckBox) v).isChecked())
checkField[11] = true;
case R.id.field_select_done:
displayRelevantSkills();
}
}
private void displayRelevantSkills() {
String field = "field";
String checkBoxName;
final String SKILL_FIELD_URL = "https://data.outfight74.hasura-app.io/";
// OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
// set request options for all requests
Retrofit.Builder builder =
new Retrofit.Builder()
.baseUrl(SKILL_FIELD_URL)
.addConverterFactory(
GsonConverterFactory.create()
);
// create retrofit adapter
Retrofit retrofit =
builder
/*.client(
httpClient.build()
)*/
.build();
// create retrofit REST client
getRelevantSkills skillClient = retrofit.create(getRelevantSkills.class);
// for each checkbox do
for(int i = 0; i < numFields; i++) {
// if checkbox is ticked
if(checkField[i]) {
// fetch relevant skills from server
SQLQuery skillQuery = new SQLQuery(field[i]);
Call<List<Skill>> call =
skillClient.relevantSkills(skillQuery);
// Execute the call asynchronously. Get a positive or negative callback.
call.enqueue(new Callback<List<Skill>>() {
@Override
public void onResponse(Call<List<Skill>> call, Response<List<Skill>> response) {
// The network call was a success and we got a response
// add to skills HashSet
skill.addAll(response.body());
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<List<Skill>> call, Throwable t) {
// the network call was a failure
// TODO: handle error
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
}
});
}
}
// display a drop down menu having all elements of HashSet
for(Skill s : skill)
{
CheckBox skillItem = new CheckBox(getApplicationContext());
skillItem.setText(s.getSkill());
}
}
}
et est ici le getRelevantSkills.java file
package com.example.vishal.internshipseekerapp;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;
class Where{
// this will be given by the user
private String skill;
public Where(String skill) {
this.skill = skill;
}
}
class Args{
final String table = "skill_field_relation";
final String[] columns = {"skill"};
private Where where;
public Args(String field) {
where = new Where(field);
}
}
class SQLQuery{
final String type = "select";
private Args args;
public SQLQuery(java.lang.String field) {
args = new Args(field);
}
}
class Skill{
private String skill;
public String getSkill() {
return skill;
}
public Skill(String skill) {
this.skill = skill;
}
}
public interface getRelevantSkills {
@POST("/v1/query")
Call<List<Skill>> relevantSkills(
@Body SQLQuery fetchSkills
);
}
Salut James, je peux voir que vous utilisez un projet Hasura. Avez-vous essayé le SDK Android sur https://github.com/hasura/android-sdk? Cela pourrait vous aider à construire votre application plus rapidement :) –
@Jaison Titus ce serait vraiment une bonne aide de votre part si vous clarifiez les doutes de vos collègues stagiaires concernant Android SDK. Il y a une réelle confusion concernant le module d'authentification sociale et la méthode HasuraUser.socialLoginType() –