在微调器适配器中插入数据后出错
我有一个问题,一个屏幕上有两个微调器,两个微调器在 JSON 解析后都被填充,而第二个微调器在从第一个微调器中选择项目后被填充;我想;第一次当我们打开屏幕时,微调器显示选择关键字,但是当我们想要更改第一个微调器中的所选项目时,它会显示所有解析的数据。但在尝试这样做之后,我收到了一条错误消息。不知道怎么去除呢?关于这个问题我希望你能帮个忙。
错误:
09-19 14:27:39.103: ERROR/AndroidRuntime(807): FATAL EXCEPTION: main
09-19 14:27:39.103: ERROR/AndroidRuntime(807): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at java.util.ArrayList.get(ArrayList.java:311)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:298)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:351)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.Spinner.makeAndAddView(Spinner.java:189)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.Spinner.layout(Spinner.java:148)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.Spinner.onLayout(Spinner.java:112)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1238)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.onLayout(LinearLayout.java:1044)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.os.Looper.loop(Looper.java:123)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at java.lang.reflect.Method.invoke(Method.java:521)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at dalvik.system.NativeStart.main(Native Method)
代码在这里
package com.equinix.android.sitevisit;
import java.util.ArrayList;
import java.util.Calendar;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.Toast;
import com.equinix.android.adapter.SiteVisit_CagesAdapter;
import com.equinix.android.adapter.SiteVisit_IBXAdapter;
import com.equinix.android.common.LoginScreen;
import com.equinix.android.common.MenuScreen;
import com.equinix.android.common.R;
import com.equinix.android.parsing.Parse_Json;
import com.equinix.android.servicecall.Service_Call;
public class Site_Visit_Details extends Activity {
/** Called when the activity is first created. */
ImageButton _siteVisit_Home, _siteVisit_Logout, _siteVisit_AddVisitor, _siteVisit_StartDateButton, _siteVisit_EndDateButton, _siteVisit_Next, _siteVisit_CheckBox;
EditText _siteVisit_StartDate, _siteVisit_EndDate, _siteVisit_AdditionalInfo;
Spinner _siteVisit_IBX, _siteVisit_Cage;
ArrayAdapter statusAdapter;
Bundle bundle;
private int mYear;
private int mMonth;
private int mDay;
private int flagValue, checkBoxFlag=0;
static final int DATE_DIALOG_ID = 0;
public static int count=0;
public static ArrayList<String> cage_Id = new ArrayList<String>();
public static ArrayList<String> cage_Name = new ArrayList<String>();
public static ArrayList<String> cage_NaturalKey = new ArrayList<String>();
public static boolean flag_cages = false;
public static ArrayList<String> firstName = new ArrayList<String>();
public static ArrayList<String> lastName = new ArrayList<String>();
public static ArrayList<String> companyName = new ArrayList<String>();
SharedPreferences prefs;
public static final String PREFS_NAME = "MyPrefsFile";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.site_visit_details);
bundle = getIntent().getExtras();
_siteVisit_Home = (ImageButton)findViewById(R.id.home);
_siteVisit_Logout = (ImageButton)findViewById(R.id.logout);
_siteVisit_AddVisitor = (ImageButton)findViewById(R.id.addVisitorImageButton);
_siteVisit_StartDateButton = (ImageButton)findViewById(R.id.startDateImageButton);
_siteVisit_EndDateButton = (ImageButton)findViewById(R.id.endDateImageButton);
_siteVisit_Next = (ImageButton)findViewById(R.id.nextImageButton);
_siteVisit_CheckBox =(ImageButton)findViewById(R.id.checkBox);
_siteVisit_StartDate = (EditText)findViewById(R.id.startDateEditText);
_siteVisit_EndDate = (EditText)findViewById(R.id.endDateEditText);
_siteVisit_AdditionalInfo = (EditText)findViewById(R.id.additionalInformationEditText);
_siteVisit_IBX = (Spinner)findViewById(R.id.ibxSpinner);
_siteVisit_Cage = (Spinner)findViewById(R.id.cageSpinner);
LoginScreen.name.add("Select");
statusAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item , LoginScreen.name);//Sets an status adapter
statusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
_siteVisit_IBX.setAdapter(statusAdapter);
_siteVisit_Cage.setAdapter(statusAdapter);
//Get Data from Parsing
try{
HttpPost post = new HttpPost("http://122.180.114.68/eqixmobile/siteservice/um/ibx");
StringEntity se = new StringEntity("{\"credentials\":{\"username\":\"mobileuser1\",\"password\":\"welcome1\"}}");
/* HttpPost post = new HttpPost("http://192.168.0.9/DEVELOPMENT/VERSIONED/Equinix/trunk/iphone/login");
StringEntity se = new StringEntity("{\"ibx\":{\"credentials\":{\"password\":\"welcome1\",\"userid\":\"mobileuser1\"}}}");*/
final Service_Call obj = new Service_Call(post, se, "mobileuser1", "welcome1",false);
final ProgressDialog dialog = ProgressDialog.show(Site_Visit_Details.this, " EQUINIX ", "Loading.... ", true);
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
statusAdapter.notifyDataSetChanged();
dialog.dismiss();
}
};
final Thread checkUpdate = new Thread() {
public void run() {
LoginScreen.name.clear();
String json_string = obj.call_Service();
new Parse_Json(json_string).parse();
handler.sendEmptyMessage(0);
}
};
checkUpdate.start();
}catch(Exception e)
{
e.printStackTrace();
}
/* Intent intent = new Intent(LoginScreen.this,MenuScreen.class);
startActivity(intent);*/
//statusAdapter.add(LoginScreen.name);
SiteVisit_IBXAdapter adapter = new SiteVisit_IBXAdapter(LoginScreen.name, this);
if(bundle.getInt("screen_flag")!=0)
{
try{
prefs = getSharedPreferences(PREFS_NAME, 0);
String savedIBXString = prefs.getString("savedIBXString",null);
String savedCagesString = prefs.getString("savedCagesString", null);
String startDate = prefs.getString("startDate", null);
String endDate= prefs.getString("endDate", null);
String addInfo = prefs.getString("additionalInfo", null);
_siteVisit_StartDate.setText(startDate);
_siteVisit_EndDate.setText(endDate);
_siteVisit_AdditionalInfo.setText(addInfo);
for(int i=0;i<LoginScreen.name.size();i++)
{
if(savedIBXString.equals(_siteVisit_IBX.getItemAtPosition(i).toString()))
{
_siteVisit_IBX.setSelection(i);
}
}
for(int i=0;i<cage_Name.size();i++)
{
if(savedCagesString.equals(_siteVisit_Cage.getItemAtPosition(i).toString()))
{
_siteVisit_Cage.setSelection(i);
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
_siteVisit_Home.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(Site_Visit_Details.this, MenuScreen.class);
startActivity(intent);
}
});
try {
firstName = bundle.getStringArrayList("FirstName");
lastName = bundle.getStringArrayList("LastName");
companyName = bundle.getStringArrayList("Company");
for(int i=0; i<firstName.size(); i++){
System.out.println("Name is ======== "+firstName.get(i)+" "+lastName.get(i)+" Company name=====>> "+companyName.get(i));
}
} catch (Exception e1) {
e1.printStackTrace();
}
_siteVisit_Logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(Site_Visit_Details.this, LoginScreen.class);
startActivity(intent);
}
});
_siteVisit_Next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
try{
System.out.println(" Size of ArrayList is "+firstName.size());
if(firstName.size()!=0){
if((_siteVisit_StartDate.getText().toString().length()!=0) &&(_siteVisit_EndDate.getText().toString().length()!=0))
{
Intent intent = new Intent(Site_Visit_Details.this, Site_Visit_Login.class);
intent.putExtra("IBXName", _siteVisit_IBX.getSelectedItem().toString());
intent.putExtra("CagesName", _siteVisit_Cage.getSelectedItem().toString());
intent.putExtra("StartDate", _siteVisit_StartDate.getText().toString());
intent.putExtra("EndDate", _siteVisit_EndDate.getText().toString());
intent.putStringArrayListExtra("FirstName", firstName);
intent.putStringArrayListExtra("LastName", lastName);
intent.putStringArrayListExtra("Company", companyName);
startActivity(intent);
}else{
Toast.makeText(Site_Visit_Details.this, "Please fill all mandatory field", Toast.LENGTH_SHORT).show();
}
}
else{
AlertDialog alertDialog = new AlertDialog.Builder(Site_Visit_Details.this).create();
alertDialog.setTitle("EQUINIX");
alertDialog.setMessage("Please Add Visitor First");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
}catch(Exception e)
{
Toast.makeText(Site_Visit_Details.this, "Please select add visitor", Toast.LENGTH_SHORT).show();
}
}
});
_siteVisit_IBX.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
/**
* Called when a new item was selected (in the Spinner)
*/
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
try{
arrayList_clear();
SiteVisit_IBXAdapter adapter = new SiteVisit_IBXAdapter(LoginScreen.name, Site_Visit_Details.this);
_siteVisit_IBX.setAdapter(adapter);
prefs = PreferenceManager.getDefaultSharedPreferences( getBaseContext());
SharedPreferences.Editor prefEditor = prefs.edit();
prefEditor.putString("savedValue",_siteVisit_IBX.getSelectedItem().toString());
HttpPost post = new HttpPost("http://122.180.114.68/eqixmobile/siteservice/um/cages");
StringEntity se = new StringEntity("{\"ibx\":{\"credentials\":{\"username\":\"mobileuser1\",\"password\":\"welcome1\"},\"userkey\":\"68782\",\"permissionCode\":\"PLACE_BASIC_SERVICES\",\"id\":\""+LoginScreen.id.get(pos)+"\",\"name\":\""+LoginScreen.name.get(pos)+"\",\"naturalKey\":\""+LoginScreen.naturalKey.get(pos)+"\"}}");
final Service_Call obj = new Service_Call(post, se, "mobileuser1", "welcome1",false);
/*String json_Response = obj.call_Service();
new Parse_Json(json_Response).parse_Cages();*/
/*SiteVisit_CagesAdapter adapter = new SiteVisit_CagesAdapter(Site_Visit_Details.cage_Name, Site_Visit_Details.this);
_siteVisit_Cage.setAdapter(adapter);*/
final ProgressDialog dialog = ProgressDialog.show(Site_Visit_Details.this, "EQUINIX ", "Loading.... ", true);
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
SiteVisit_CagesAdapter adapter = new SiteVisit_CagesAdapter(Site_Visit_Details.cage_Name, Site_Visit_Details.this);
_siteVisit_Cage.setAdapter(adapter);
dialog.dismiss();
}
};
final Thread checkUpdate = new Thread() {
public void run() {
String json_Response = obj.call_Service();
new Parse_Json(json_Response).parse_Cages();
handler.sendEmptyMessage(0);
}
};
checkUpdate.start();
}catch(Exception e)
{
e.printStackTrace();
}
}
private void arrayList_clear() {
Site_Visit_Details.cage_Id.clear();
Site_Visit_Details.cage_Name.clear();
Site_Visit_Details.cage_NaturalKey.clear();
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
});
_siteVisit_Cage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
/**
* Called when a new item was selected (in the Spinner)
*/
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
prefs = PreferenceManager.getDefaultSharedPreferences( getBaseContext());
SharedPreferences.Editor prefEditor = prefs.edit();
prefEditor.putString("savedCagesString",_siteVisit_Cage.getSelectedItem().toString());
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
_siteVisit_StartDateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
flagValue = 0;
showDialog(DATE_DIALOG_ID);
}
});
_siteVisit_EndDateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
flagValue = 1;
showDialog(DATE_DIALOG_ID);
}
});
_siteVisit_AddVisitor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(Site_Visit_Details.this, Site_Visit_AddVisitor.class);
startActivity(intent);
}
});
_siteVisit_CheckBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(checkBoxFlag==0){
_siteVisit_CheckBox.setBackgroundResource(R.drawable.check_box_checked);
checkBoxFlag=1;
}else{
_siteVisit_CheckBox.setBackgroundResource(R.drawable.check_box_unchecked);
checkBoxFlag=0;
}
}
});
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
}
private DatePickerDialog.OnDateSetListener mDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay(flagValue);
}
};
private void updateDisplay(int flag) {
if(flag==0){
_siteVisit_StartDate.setText(
new StringBuilder()
// Month is 0 based so add 1
.append(mMonth + 1).append("/")
.append(mDay).append("/")
.append(mYear).append(" "));
}
else{
_siteVisit_EndDate.setText(
new StringBuilder()
// Month is 0 based so add 1
.append(mMonth + 1).append("/")
.append(mDay).append("/")
.append(mYear).append(" "));
}
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this,
mDateSetListener,
mYear, mMonth, mDay);
}
return null;
}
@Override
protected void onStop(){
super.onStop();
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("savedIBXString", _siteVisit_IBX.getSelectedItem().toString());
editor.putString("savedCagesString", _siteVisit_Cage.getSelectedItem().toString());
editor.putString("startDate", _siteVisit_StartDate.getText().toString());
editor.putString("endDate", _siteVisit_EndDate.getText().toString());
editor.putString("additionalInfo", _siteVisit_AdditionalInfo.getText().toString());
// Commit the edits!
editor.commit();
}
}
I have a problem that I have a two spinner's on one screen, Both are filled after JSON parsing and second spinner is filled after selecting item from first spinner; I want; first time when we open the screen then spinner shows Select keyword but when we want to change selected item in first spinner then it shows all parsed data. but after attempting to do that I received an error message. I don't know How it will be removed? I wish a kind favour of you regarding this subject.
Error:
09-19 14:27:39.103: ERROR/AndroidRuntime(807): FATAL EXCEPTION: main
09-19 14:27:39.103: ERROR/AndroidRuntime(807): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at java.util.ArrayList.get(ArrayList.java:311)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:298)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:351)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.Spinner.makeAndAddView(Spinner.java:189)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.Spinner.layout(Spinner.java:148)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.Spinner.onLayout(Spinner.java:112)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1238)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.onLayout(LinearLayout.java:1044)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.View.layout(View.java:7035)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.os.Looper.loop(Looper.java:123)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at java.lang.reflect.Method.invoke(Method.java:521)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-19 14:27:39.103: ERROR/AndroidRuntime(807): at dalvik.system.NativeStart.main(Native Method)
The code is here
package com.equinix.android.sitevisit;
import java.util.ArrayList;
import java.util.Calendar;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.Toast;
import com.equinix.android.adapter.SiteVisit_CagesAdapter;
import com.equinix.android.adapter.SiteVisit_IBXAdapter;
import com.equinix.android.common.LoginScreen;
import com.equinix.android.common.MenuScreen;
import com.equinix.android.common.R;
import com.equinix.android.parsing.Parse_Json;
import com.equinix.android.servicecall.Service_Call;
public class Site_Visit_Details extends Activity {
/** Called when the activity is first created. */
ImageButton _siteVisit_Home, _siteVisit_Logout, _siteVisit_AddVisitor, _siteVisit_StartDateButton, _siteVisit_EndDateButton, _siteVisit_Next, _siteVisit_CheckBox;
EditText _siteVisit_StartDate, _siteVisit_EndDate, _siteVisit_AdditionalInfo;
Spinner _siteVisit_IBX, _siteVisit_Cage;
ArrayAdapter statusAdapter;
Bundle bundle;
private int mYear;
private int mMonth;
private int mDay;
private int flagValue, checkBoxFlag=0;
static final int DATE_DIALOG_ID = 0;
public static int count=0;
public static ArrayList<String> cage_Id = new ArrayList<String>();
public static ArrayList<String> cage_Name = new ArrayList<String>();
public static ArrayList<String> cage_NaturalKey = new ArrayList<String>();
public static boolean flag_cages = false;
public static ArrayList<String> firstName = new ArrayList<String>();
public static ArrayList<String> lastName = new ArrayList<String>();
public static ArrayList<String> companyName = new ArrayList<String>();
SharedPreferences prefs;
public static final String PREFS_NAME = "MyPrefsFile";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.site_visit_details);
bundle = getIntent().getExtras();
_siteVisit_Home = (ImageButton)findViewById(R.id.home);
_siteVisit_Logout = (ImageButton)findViewById(R.id.logout);
_siteVisit_AddVisitor = (ImageButton)findViewById(R.id.addVisitorImageButton);
_siteVisit_StartDateButton = (ImageButton)findViewById(R.id.startDateImageButton);
_siteVisit_EndDateButton = (ImageButton)findViewById(R.id.endDateImageButton);
_siteVisit_Next = (ImageButton)findViewById(R.id.nextImageButton);
_siteVisit_CheckBox =(ImageButton)findViewById(R.id.checkBox);
_siteVisit_StartDate = (EditText)findViewById(R.id.startDateEditText);
_siteVisit_EndDate = (EditText)findViewById(R.id.endDateEditText);
_siteVisit_AdditionalInfo = (EditText)findViewById(R.id.additionalInformationEditText);
_siteVisit_IBX = (Spinner)findViewById(R.id.ibxSpinner);
_siteVisit_Cage = (Spinner)findViewById(R.id.cageSpinner);
LoginScreen.name.add("Select");
statusAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item , LoginScreen.name);//Sets an status adapter
statusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
_siteVisit_IBX.setAdapter(statusAdapter);
_siteVisit_Cage.setAdapter(statusAdapter);
//Get Data from Parsing
try{
HttpPost post = new HttpPost("http://122.180.114.68/eqixmobile/siteservice/um/ibx");
StringEntity se = new StringEntity("{\"credentials\":{\"username\":\"mobileuser1\",\"password\":\"welcome1\"}}");
/* HttpPost post = new HttpPost("http://192.168.0.9/DEVELOPMENT/VERSIONED/Equinix/trunk/iphone/login");
StringEntity se = new StringEntity("{\"ibx\":{\"credentials\":{\"password\":\"welcome1\",\"userid\":\"mobileuser1\"}}}");*/
final Service_Call obj = new Service_Call(post, se, "mobileuser1", "welcome1",false);
final ProgressDialog dialog = ProgressDialog.show(Site_Visit_Details.this, " EQUINIX ", "Loading.... ", true);
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
statusAdapter.notifyDataSetChanged();
dialog.dismiss();
}
};
final Thread checkUpdate = new Thread() {
public void run() {
LoginScreen.name.clear();
String json_string = obj.call_Service();
new Parse_Json(json_string).parse();
handler.sendEmptyMessage(0);
}
};
checkUpdate.start();
}catch(Exception e)
{
e.printStackTrace();
}
/* Intent intent = new Intent(LoginScreen.this,MenuScreen.class);
startActivity(intent);*/
//statusAdapter.add(LoginScreen.name);
SiteVisit_IBXAdapter adapter = new SiteVisit_IBXAdapter(LoginScreen.name, this);
if(bundle.getInt("screen_flag")!=0)
{
try{
prefs = getSharedPreferences(PREFS_NAME, 0);
String savedIBXString = prefs.getString("savedIBXString",null);
String savedCagesString = prefs.getString("savedCagesString", null);
String startDate = prefs.getString("startDate", null);
String endDate= prefs.getString("endDate", null);
String addInfo = prefs.getString("additionalInfo", null);
_siteVisit_StartDate.setText(startDate);
_siteVisit_EndDate.setText(endDate);
_siteVisit_AdditionalInfo.setText(addInfo);
for(int i=0;i<LoginScreen.name.size();i++)
{
if(savedIBXString.equals(_siteVisit_IBX.getItemAtPosition(i).toString()))
{
_siteVisit_IBX.setSelection(i);
}
}
for(int i=0;i<cage_Name.size();i++)
{
if(savedCagesString.equals(_siteVisit_Cage.getItemAtPosition(i).toString()))
{
_siteVisit_Cage.setSelection(i);
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
_siteVisit_Home.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(Site_Visit_Details.this, MenuScreen.class);
startActivity(intent);
}
});
try {
firstName = bundle.getStringArrayList("FirstName");
lastName = bundle.getStringArrayList("LastName");
companyName = bundle.getStringArrayList("Company");
for(int i=0; i<firstName.size(); i++){
System.out.println("Name is ======== "+firstName.get(i)+" "+lastName.get(i)+" Company name=====>> "+companyName.get(i));
}
} catch (Exception e1) {
e1.printStackTrace();
}
_siteVisit_Logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(Site_Visit_Details.this, LoginScreen.class);
startActivity(intent);
}
});
_siteVisit_Next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
try{
System.out.println(" Size of ArrayList is "+firstName.size());
if(firstName.size()!=0){
if((_siteVisit_StartDate.getText().toString().length()!=0) &&(_siteVisit_EndDate.getText().toString().length()!=0))
{
Intent intent = new Intent(Site_Visit_Details.this, Site_Visit_Login.class);
intent.putExtra("IBXName", _siteVisit_IBX.getSelectedItem().toString());
intent.putExtra("CagesName", _siteVisit_Cage.getSelectedItem().toString());
intent.putExtra("StartDate", _siteVisit_StartDate.getText().toString());
intent.putExtra("EndDate", _siteVisit_EndDate.getText().toString());
intent.putStringArrayListExtra("FirstName", firstName);
intent.putStringArrayListExtra("LastName", lastName);
intent.putStringArrayListExtra("Company", companyName);
startActivity(intent);
}else{
Toast.makeText(Site_Visit_Details.this, "Please fill all mandatory field", Toast.LENGTH_SHORT).show();
}
}
else{
AlertDialog alertDialog = new AlertDialog.Builder(Site_Visit_Details.this).create();
alertDialog.setTitle("EQUINIX");
alertDialog.setMessage("Please Add Visitor First");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
}catch(Exception e)
{
Toast.makeText(Site_Visit_Details.this, "Please select add visitor", Toast.LENGTH_SHORT).show();
}
}
});
_siteVisit_IBX.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
/**
* Called when a new item was selected (in the Spinner)
*/
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
try{
arrayList_clear();
SiteVisit_IBXAdapter adapter = new SiteVisit_IBXAdapter(LoginScreen.name, Site_Visit_Details.this);
_siteVisit_IBX.setAdapter(adapter);
prefs = PreferenceManager.getDefaultSharedPreferences( getBaseContext());
SharedPreferences.Editor prefEditor = prefs.edit();
prefEditor.putString("savedValue",_siteVisit_IBX.getSelectedItem().toString());
HttpPost post = new HttpPost("http://122.180.114.68/eqixmobile/siteservice/um/cages");
StringEntity se = new StringEntity("{\"ibx\":{\"credentials\":{\"username\":\"mobileuser1\",\"password\":\"welcome1\"},\"userkey\":\"68782\",\"permissionCode\":\"PLACE_BASIC_SERVICES\",\"id\":\""+LoginScreen.id.get(pos)+"\",\"name\":\""+LoginScreen.name.get(pos)+"\",\"naturalKey\":\""+LoginScreen.naturalKey.get(pos)+"\"}}");
final Service_Call obj = new Service_Call(post, se, "mobileuser1", "welcome1",false);
/*String json_Response = obj.call_Service();
new Parse_Json(json_Response).parse_Cages();*/
/*SiteVisit_CagesAdapter adapter = new SiteVisit_CagesAdapter(Site_Visit_Details.cage_Name, Site_Visit_Details.this);
_siteVisit_Cage.setAdapter(adapter);*/
final ProgressDialog dialog = ProgressDialog.show(Site_Visit_Details.this, "EQUINIX ", "Loading.... ", true);
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
SiteVisit_CagesAdapter adapter = new SiteVisit_CagesAdapter(Site_Visit_Details.cage_Name, Site_Visit_Details.this);
_siteVisit_Cage.setAdapter(adapter);
dialog.dismiss();
}
};
final Thread checkUpdate = new Thread() {
public void run() {
String json_Response = obj.call_Service();
new Parse_Json(json_Response).parse_Cages();
handler.sendEmptyMessage(0);
}
};
checkUpdate.start();
}catch(Exception e)
{
e.printStackTrace();
}
}
private void arrayList_clear() {
Site_Visit_Details.cage_Id.clear();
Site_Visit_Details.cage_Name.clear();
Site_Visit_Details.cage_NaturalKey.clear();
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
});
_siteVisit_Cage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
/**
* Called when a new item was selected (in the Spinner)
*/
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
prefs = PreferenceManager.getDefaultSharedPreferences( getBaseContext());
SharedPreferences.Editor prefEditor = prefs.edit();
prefEditor.putString("savedCagesString",_siteVisit_Cage.getSelectedItem().toString());
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
_siteVisit_StartDateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
flagValue = 0;
showDialog(DATE_DIALOG_ID);
}
});
_siteVisit_EndDateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
flagValue = 1;
showDialog(DATE_DIALOG_ID);
}
});
_siteVisit_AddVisitor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(Site_Visit_Details.this, Site_Visit_AddVisitor.class);
startActivity(intent);
}
});
_siteVisit_CheckBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(checkBoxFlag==0){
_siteVisit_CheckBox.setBackgroundResource(R.drawable.check_box_checked);
checkBoxFlag=1;
}else{
_siteVisit_CheckBox.setBackgroundResource(R.drawable.check_box_unchecked);
checkBoxFlag=0;
}
}
});
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
}
private DatePickerDialog.OnDateSetListener mDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay(flagValue);
}
};
private void updateDisplay(int flag) {
if(flag==0){
_siteVisit_StartDate.setText(
new StringBuilder()
// Month is 0 based so add 1
.append(mMonth + 1).append("/")
.append(mDay).append("/")
.append(mYear).append(" "));
}
else{
_siteVisit_EndDate.setText(
new StringBuilder()
// Month is 0 based so add 1
.append(mMonth + 1).append("/")
.append(mDay).append("/")
.append(mYear).append(" "));
}
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this,
mDateSetListener,
mYear, mMonth, mDay);
}
return null;
}
@Override
protected void onStop(){
super.onStop();
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("savedIBXString", _siteVisit_IBX.getSelectedItem().toString());
editor.putString("savedCagesString", _siteVisit_Cage.getSelectedItem().toString());
editor.putString("startDate", _siteVisit_StartDate.getText().toString());
editor.putString("endDate", _siteVisit_EndDate.getText().toString());
editor.putString("additionalInfo", _siteVisit_AdditionalInfo.getText().toString());
// Commit the edits!
editor.commit();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查您在适配器中插入的 ArrayList 对象(如果它不为空),使用日志,然后双击 LogCat 中的错误以将您重定向到出现错误的代码行。
Check the ArrayList object that you're inserting in the adapter if it's not empty, use Logs, and double-click on the Error in your LogCat to re-direct you to the line of code that you're getting an error.