【问题标题】:What method to add in NearablesDemoActivity.javaNearablesDemoActivity.java中添加什么方法
【发布时间】:2015-10-26 04:54:43
【问题描述】:

我正在使用 estimote 贴纸进行鞋贴项目,但遇到了一些问题。我正在为我的项目使用 android studio

我在 dbRow = stickerdb.getResult(currentNearable.identifier("065473d63cd9d687")); 处有错误;

上面写着 Method call expected

错误日志: 错误:(96, 52) 错误:找不到符号方法标识符(字符串)

public class NearablesDemoActivity extends BaseActivity {

private static final String TAG = NearablesDemoActivity.class.getSimpleName();

private Nearable currentNearable;
private BeaconManager beaconManager;
private String scanId;

TextView Desc;  //description
Spinner spinnerDropDown;  //for size available
String[] size = {
};                   //for size available
Spinner spinnerDropDown2;   //for colours available
String[] colour = {
};                      //for colours available
TextView COO;      //For country of origin
TextView SM; //For Shoe Model
TextView Price; //For price
Button btnRating;  //for button
private Database_sticker stickerdb;
Sresult dbRow;

@Override
protected int getLayoutResId() {
    return R.layout.nearable_demo;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.nearable_demo);


    currentNearable = getIntent().getExtras().getParcelable(ListNearablesActivity.EXTRAS_NEARABLE);
    displayCurrentNearableInfo();

    beaconManager = new BeaconManager(this);

    ArrayAdapter<String> adapter= new ArrayAdapter<>(this,android.R.layout.simple_spinner_dropdown_item ,size);  //for size available
    spinnerDropDown.setAdapter(adapter);
    ArrayAdapter<String> adapter1= new ArrayAdapter<>(this,android.R.layout.simple_spinner_dropdown_item ,colour); //for colours available
    spinnerDropDown2.setAdapter(adapter1);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_action_navigation_arrow_back);
    toolbar.setTitle(getTitle());
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    btnRating=(Button)findViewById(R.id.rd);

    btnRating.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent pageforRatingBar = new Intent(getApplicationContext(), RatingBar_main.class);
            startActivity(pageforRatingBar);
        }
    });

    stickerdb = new Database_sticker(this);
   // dbRow = stickerdb.getResult(1);//currentNearable.identifier()
    dbRow = stickerdb.getResult(currentNearable.identifier("065473d63cd9d687"));
    dbRow.getSa();
    dbRow.getDesc();
    dbRow.getCoo();
    dbRow.getId();
    dbRow.getPrice();
    dbRow.getSm();
}

@Override
protected void onResume() {
    super.onResume();
    beaconManager.setNearableListener(new BeaconManager.NearableListener() {
        @Override
        public void onNearablesDiscovered(List<Nearable> nearables) {
            updateCurrentNearable(nearables);
            displayCurrentNearableInfo();

        }
    });


    beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
        @Override
        public void onServiceReady() {
            scanId = beaconManager.startNearableDiscovery();
        }
    });
}

@Override
protected void onStop() {
    beaconManager.disconnect();
    super.onStop();
}

private void displayCurrentNearableInfo() {
            Desc = (TextView) findViewById(R.id.textview1);   //for description
            // Get reference of SpinnerView from layout/nearable_demo.xml
            spinnerDropDown = (Spinner) findViewById(R.id.spinner1);  //For size available
            spinnerDropDown2 = (Spinner) findViewById(R.id.spinner2);//for colours available
            COO = (TextView) findViewById(R.id.textview2);//for country of origin
            SM = (TextView) findViewById(R.id.textview3); //for shoe model
            Price = (TextView) findViewById(R.id.textview4); //for price
}

private void updateCurrentNearable(List<Nearable> nearables) {
    for (Nearable nearable : nearables) {
        if (nearable.equals(currentNearable)) {
            currentNearable = nearable;
        }
    }
}
}

【问题讨论】:

  • identifier() 应该是Nearable 类的String 类型方法。是吗?
  • 是的,但我不知道放在哪里
  • 什么意思?从你的 sn-p 我可以说你已经创建了一个 Nearable 类,在那个类中创建一个方法 identifier()
  • 如何在该类中创建方法?对不起,我是android新手,还在学习中,我正在学习,因为我正在做这个项目
  • 不先学习Java和OO就开始学习Android是个坏主意。在学习如何跑步之前,您需要先学会走路。

标签: java android estimote


【解决方案1】:

您正在对Nearable 类的对象调用identifier 方法。这个类中没有这样的方法:

http://estimote.github.io/Android-SDK/JavaDocs/com/estimote/sdk/Nearable.html

不过,有一个identifier 属性,这是您需要使用的:

http://estimote.github.io/Android-SDK/JavaDocs/com/estimote/sdk/Nearable.html#identifier

换句话说,这一行:

dbRow = stickerdb.getResult(currentNearable.identifier("065473d63cd9d687"));

……需要变成:

dbRow = stickerdb.getResult(currentNearable.identifier);

【讨论】:

    猜你喜欢
    • 2016-09-03
    • 2018-03-03
    • 1970-01-01
    • 2019-11-22
    • 1970-01-01
    • 2022-01-02
    • 2015-08-09
    • 1970-01-01
    相关资源
    最近更新 更多