我对android很新,我正在创建一个活动,它有两个微调器,它们从两个独立的API调用接收的JSONObjects中填充它们的下拉项。出于某种原因,我收到此错误。我不知道为什么我收到此错误或如何解决它。任何人都可以对此有所了解吗?任何帮助将不胜感激!!!这是我的代码:
public class AddPropertyActivity extends AppCompatActivity {
private TextView selectCity;
private static final String TAG = RegisterUserActivity.class.getSimpleName();
private JSONObject jsonObject;
private JSONArray jsonArray;
private ProgressDialog mProgressDialog;
private MyProperty mMyProperty;
private ArrayList<City> cities = new ArrayList<City>();
private ArrayList<City> locations = new ArrayList<City>();
private ArrayList<String> cityNames = new ArrayList<String>();
private ArrayList<String> locationNames = new ArrayList<String>();
private String selectedCity="lahore";
private String selectedLocation="";
private int count=0;
private Spinner citySpinner;
private Spinner locationSpinner;
private DownloadJSON task1;
private DownloadJSON task2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_property);
Log.e(TAG, "Add property Activity Created");
mMyProperty = new MyProperty();
selectCity = (TextView) findViewById(R.id.txtSelectCity);
citySpinner = (Spinner) findViewById(R.id.my_spinner);
locationSpinner = (Spinner) findViewById(R.id.my_loc_spinner);
task1 = new DownloadJSON("http://xyz", 1);
task1.execute();
task2 = new DownloadJSON("http://xxx" + selectedCity,2 );
task2.execute();
}
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
private String mURL = "";
private int choice;
public DownloadJSON( String URL, int ch) {
mURL=URL;
choice=ch;
}
@Override
protected Void doInBackground(Void... params) {
jsonObject = JSONfunctions.getJSONfromURL(mURL);
if (mURL.equals("http://xyz")) {
try {
jsonArray = jsonObject.getJSONArray("results");
Log.d(TAG, "Number of entries " + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++) {
jsonObject = jsonArray.getJSONObject(i);
City mCity = new City();
mCity.setName(jsonObject.optString("locationTitle"));
mCity.setId(jsonObject.getInt("id"));
locations.add(mCity);
locationNames.add(jsonObject.optString("locationTitle"));
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
Log.e(TAG, "Exception caught"+e.toString());
e.printStackTrace();
}
} else {
try {
jsonArray = jsonObject.getJSONArray("results");
Log.i(TAG, "Number of entries " + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++) {
jsonObject = jsonArray.getJSONObject(i);
Log.e(TAG, "beep!");
City mCity = new City();
mCity.setName(jsonObject.optString("title"));
mCity.setId(jsonObject.getInt("id"));
cities.add(mCity);
cityNames.add(jsonObject.optString("title"));
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
Log.e(TAG, "exception caught!"+ e.toString());
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(Void args) {
if (choice==2) {
Log.e(TAG, "Spinner2 Created");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(AddPropertyActivity.this, android.R.layout.simple_spinner_item, locationNames);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
locationSpinner.setAdapter(adapter);
locationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long l) {
Log.e(TAG, "listener 2 called");
mMyProperty.setLocationId(locations.get(position).getId());
selectedLocation = locationNames.get(position);
Toast.makeText(getApplicationContext(), "You selected: " + selectedLocation, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
} else if (choice==1) {
Log.e(TAG, "City Spinner Created");
citySpinner.setAdapter(new ArrayAdapter<String>(AddPropertyActivity.this,
android.R.layout.simple_spinner_dropdown_item,
cityNames));
citySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Log.e(TAG, "listener called");
mMyProperty.setCity(cityNames.get(position));
selectedCity = cities.get(position).getName();
Toast.makeText(getApplicationContext(), "You selected: " + selectedCity, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
}
}}
我收到的错误堆栈如下:
12/19 01:46:51: Launching app
$ adb push D:\AndroidProjects\Homie\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.teksify.homie
$ adb shell pm install -r "/data/local/tmp/com.teksify.homie"
pkg: /data/local/tmp/com.teksify.homie
Success
$ adb shell am start -n "com.teksify.homie/com.teksify.homie.Activities.LoginActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 13200 on device samsung-sm_g900w8-0e5df62e
W/ResourcesManager: getTopLevelResources: /data/app/com.teksify.homie-2/base.apk / 1.0 running in com.teksify.homie rsrc of package null
W/System: ClassLoader referenced unknown path: /data/app/com.teksify.homie-2/lib/arm
I/InstantRun: Instant Run Runtime started. Android package is com.teksify.homie, real application class is null.
W/art: Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error
W/System: ClassLoader referenced unknown path: /data/app/com.teksify.homie-2/lib/arm
I/FirebaseInitProvider: FirebaseApp initialization unsuccessful
W/ResourcesManager: getTopLevelResources: /data/app/com.teksify.homie-2/base.apk / 1.0 running in com.teksify.homie rsrc of package null
W/ResourcesManager: getTopLevelResources: /data/app/com.teksify.homie-2/base.apk / 1.0 running in com.teksify.homie rsrc of package null
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
D/SecWifiDisplayUtil: Metadata value : none
D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{6d7d821 I.E...... R.....ID 0,0-0,0}
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: (Ia10634f51b)
OpenGL ES Shader Compiler Version: E031.29.00.00
Build Date: 01/28/16 Thu
Local Branch: ss
Remote Branch:
Local Patches:
Reconstruct Branch:
D/libEGL: eglInitialize EGLDisplay = 0x9e53a7c4
I/OpenGLRenderer: Initialized EGL, version 1.4
E/ClipboardServiceEx: clipEx is android.sec.clipboard.ClipboardExManager@7039d00
E/ClipboardServiceEx: clipEx has text data : false
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@3df022b time:198322914
D/ViewRootImpl: MSG_RESIZED: ci=Rect(0, 72 - 0, 885) vi=Rect(0, 72 - 0, 885) or=1
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
D/ViewRootImpl: The input has been finished in ImeInputStage.
D/ViewRootImpl: The input has been finished in ImeInputStage.
D/ViewRootImpl: MSG_RESIZED: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
D/ViewRootImpl: ViewPostImeInputStage processPointer 0
D/ViewRootImpl: ViewPostImeInputStage processPointer 1
I/Timeline: Timeline: Activity_launch_request id:com.teksify.homie time:198328171
W/ResourcesManager: getTopLevelResources: /data/app/com.teksify.homie-2/base.apk / 1.0 running in com.teksify.homie rsrc of package null
E/RegisterUserActivity: Add property Activity Created
D/SecWifiDisplayUtil: Metadata value : none
D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{b419b60 I.E...... R.....ID 0,0-0,0}
W/art: Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error
I/System.out: Thread-36942(ApacheHTTPLog):Reading from variable values from setDefaultValuesToVariables
I/System.out: Thread-36942(ApacheHTTPLog):isSBSettingEnabled false
I/System.out: Thread-36942(ApacheHTTPLog):isShipBuild true
I/System.out: Thread-36942(ApacheHTTPLog):getDebugLevel 0x4f4c
I/System.out: Thread-36942(ApacheHTTPLog):Smart Bonding Setting is false
I/System.out: Thread-36942(ApacheHTTPLog):SmartBonding Setting is false, SHIP_BUILD is true, log to file is false, DBG is false, DEBUG_LEVEL (1-LOW, 2-MID, 3-HIGH) is 1
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@f5b1363 time:198328370
V/ActivityThread: updateVisibility : ActivityRecord{85ced8e token=android.os.BinderProxy@3df022b {com.teksify.homie/com.teksify.homie.Activities.LoginActivity}} show : false
I/System.out: AsyncTask #2 calls detatch()
I/RegisterUserActivity: Number of entries 1
E/RegisterUserActivity: beep!
E/RegisterUserActivity: City Spinner Created
E/RegisterUserActivity: listener called
[ 12-19 01:47:20.834 13200:14034 W/ ]
Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory
W/art: Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error
I/System.out: Thread-36943(ApacheHTTPLog):isSBSettingEnabled false
I/System.out: Thread-36943(ApacheHTTPLog):isShipBuild true
I/System.out: Thread-36943(ApacheHTTPLog):getDebugLevel 0x4f4c
I/System.out: Thread-36943(ApacheHTTPLog):Smart Bonding Setting is false
I/System.out: Thread-36943(ApacheHTTPLog):SmartBonding Setting is false, SHIP_BUILD is true, log to file is false, DBG is false, DEBUG_LEVEL (1-LOW, 2-MID, 3-HIGH) is 1
D/SecWifiDisplayUtil: Metadata value : none
D/ViewRootImpl: #1 mView = android.widget.LinearLayout{caa0fa7 V.E...... ......I. 0,0-0,0 #10203a7 android:id/toast_layout_root}
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
I/System.out: AsyncTask #3 calls detatch()
D/RegisterUserActivity: Number of entries 449
E/RegisterUserActivity: Spinner2 Created
E/RegisterUserActivity: listener 2 called
D/ViewRootImpl: #1 mView = android.widget.LinearLayout{8b4f7fd V.E...... ......I. 0,0-0,0 #10203a7 android:id/toast_layout_root}
D/ViewRootImpl: #3 mView = null
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
D/ViewRootImpl: ViewPostImeInputStage processPointer 0
D/ViewRootImpl: #3 mView = null
D/ViewRootImpl: ViewPostImeInputStage processPointer 1
D/AbsListView: Get MotionRecognitionManager
E/MotionRecognitionManager: mSContextService = android.hardware.scontext.ISContextService$Stub$Proxy@cfe41ec
E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@8e029b5
E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@8e029b5
D/ViewRootImpl: #1 mView = android.widget.PopupWindow$PopupDecorView{f6e13bb V.E...... ......I. 0,0-0,0}
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/ViewRootImpl: ViewPostImeInputStage processPointer 0
D/ViewRootImpl: ViewPostImeInputStage processPointer 1
D/ViewRootImpl: #3 mView = null
D/ViewRootImpl: ViewPostImeInputStage processPointer 0
D/ViewRootImpl: ViewPostImeInputStage processPointer 1
D/AbsListView: Get MotionRecognitionManager
D/ViewRootImpl: #1 mView = android.widget.PopupWindow$PopupDecorView{75c27fa V.E...... ......I. 0,0-0,0}
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/ViewRootImpl: ViewPostImeInputStage processPointer 0
D/ViewRootImpl: ViewPostImeInputStage processPointer 1
E/RegisterUserActivity: listener 2 called
D/ViewRootImpl: #1 mView = android.widget.LinearLayout{e13f2e4 V.E...... ......I. 0,0-0,0 #10203a7 android:id/toast_layout_root}
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/OpenGLRenderer: endAllActiveAnimators on 0x9ce75380 (ListPopupWindow$DropDownListView) with handle 0x9cc1a090
D/ViewRootImpl: #3 mView = null
D/ViewRootImpl: #3 mView = null
V/ActivityThread: updateVisibility : ActivityRecord{2d8134d token=android.os.BinderProxy@f5b1363 {com.teksify.homie/com.teksify.homie.Activities.AddPropertyActivity}} show : true
Application terminated.
logcat的
12-19 01:47:19.484 13200-13200/com.teksify.homie E/RegisterUserActivity: Add property Activity Created
12-19 01:47:20.774 13200-13996/com.teksify.homie E/RegisterUserActivity: beep!
12-19 01:47:20.774 13200-13200/com.teksify.homie E/RegisterUserActivity: City Spinner Created
12-19 01:47:20.814 13200-13200/com.teksify.homie E/RegisterUserActivity: listener called
[ 12-19 01:47:20.834 13200:14034 W/ ]
Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory
12-19 01:47:21.014 13200-13200/com.teksify.homie E/RegisterUserActivity: Spinner2 Created
12-19 01:47:21.044 13200-13200/com.teksify.homie E/RegisterUserActivity: listener 2 called
12-19 01:47:29.034 13200-13200/com.teksify.homie E/RegisterUserActivity: listener 2 called`