在CSipSimple中添加微调器时遇到问题



我正在尝试在我的CSipSimple帐户注册表中添加微调器。 但是我在几行上遇到了错误。首先我在

accountUserName = (Spinner) findViewById("username");

findViewById 未定义。其次是在

ArrayAdapter

dataAdapter = new ArrayAdapter(this, R.layout.spinner_item, list);

说构造函数数组适配器是未定义的。这段代码在Saperate程序中运行良好,但是当我尝试将此代码放入CSipsimple Basic.java文件中时,它显示了这两个错误。有人可以帮我吗?

public class Basic extends BaseImplementation {
protected static final String THIS_FILE = "Basic W";    
InputStream is=null;
String result=null;
String line=null;
JSONObject json = null;
private Spinner accountUserName;
private EditTextPreference accountDisplayName;
//private EditTextPreference accountUserName;
private EditTextPreference accountServer;
private EditTextPreference accountPassword;
private void bindFields() {
accountDisplayName = (EditTextPreference) findPreference("display_name");
accountUserName = (Spinner) findViewById("username");
accountServer = (EditTextPreference) findPreference("server");
accountPassword = (EditTextPreference) findPreference("password");
}
public void fillLayout(final SipProfile account) {
bindFields();
accountDisplayName.setText(account.display_name);
//fetching values fro mysql database 
String serverFull = account.reg_uri;
if (serverFull == null) {
serverFull = "";
}else {
serverFull = serverFull.replaceFirst("sip:", "");
}
ParsedSipContactInfos parsedInfo = SipUri.parseSipContact(account.acc_id);
//accountUserName.setText(parsedInfo.userName);
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.xx.xxx/conIds.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("Pass 1", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 1", e.toString());
Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_LONG).show();
}
try
{
BufferedReader reader = new BufferedReader
(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
{
sb.append(line + "n");
}
is.close();
result = sb.toString();
System.out.println(result);
Log.e("Pass 2", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 2", e.toString());
}
//
try
{
JSONArray NJA=new JSONArray(result);
String arr=NJA.getString(1);
Log.d("My arry", ""+arr);
JSONArray JA=new JSONArray(arr);
final String[] str2 = new String[JA.length()];
for(int i=0;i<JA.length();i++)
{
str2[i] = JA.getString(i);
}
List<String> list = new ArrayList<String>();
for(int i=0;i<str2.length;i++)
{
list.add(str2[i]);
}
Collections.sort(list);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
accountUserName.setAdapter(dataAdapter);
accountUserName.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0, View arg1,int position, long id)
{
// TODO Auto-generated method stub
String Item=accountUserName.getSelectedItem().toString();
Toast.makeText(getApplicationContext(), Item,Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> arg0)
{
// TODO Auto-generated method stub
}
});
}
catch(Exception e)
{
Log.e("Fail 3", e.toString());
}
accountServer.setText(serverFull);
accountPassword.setText(account.data);
}

您是否导入了android.app.Activity(其中定义了findViewById(int))并android.widget.ArrayAdapter

最新更新