java array type expected_构造函数定义为取String但方法调用显示错误'Array type expected found found java.lang.String' (...

2017-07-12 06:20:01

0

I have a registration activity which depending on user's selected check boxes, makes an asynchronous call to the server to fetch skills relevant to selected field. I am using retrofit for the same. I have defined a SQLQuery class whose constructor takes a String parameter. Now the problem is, when I invoke the constructor with a String argument it shows an error Array type expected found java.lang.String. Please someone help me fix this.

Thanks in advance here is my java file

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 = 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> call =

skillClient.relevantSkills(skillQuery);

// Execute the call asynchronously. Get a positive or negative callback.

call.enqueue(new Callback>() {

@Override

public void onResponse(Call> call, Response> 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> 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());

}

}

}

and here is the 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> relevantSkills(

@Body SQLQuery fetchSkills

);

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值