我正在从servlet获取JSonArray并将其转换为ListArray,此列表填充了微调器。当我尝试在微调器中选择一个值时,我看不到微调器中的值并得到NullPointerException,奇怪的是,列表打开了,我可以看到它,但看不到所选值。希望有人能帮助我。
我已经尝试了一切,包括提供的所有答案和解决方案 没有任何帮助。
这是客户端方法
public void getCities(){
params.has("cities");
client.get(url, params, new JsonHttpResponseHandler() {
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject responseString) {
Toast.makeText(context,"failure "+throwable+" "+responseString ,Toast.LENGTH_LONG ).show();
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
Toast.makeText(context, "success ", Toast.LENGTH_LONG).show();
for (int i = 0; i < response.length(); i++) {
try {
String cityname = response.getString(i);
cityList.add(cityname);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
UserData.setCityList(cityList);
}
这是微调器的课程
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
handler = new UserDBHandler(this);
userName = (EditText) findViewById(R.id.userName);
lastName = (EditText) findViewById(R.id.lastName);
firstName = (EditText) findViewById(R.id.firstName);
stretName = (EditText) findViewById(R.id.streetName);
stretNum = (EditText) findViewById(R.id.strNum);
birthDay = (EditText) findViewById(R.id.birthDay_date);
passwrd = (EditText) findViewById(R.id.passWord);
passwordSafty = (EditText) findViewById(R.id.passWordtruth);
email = (EditText) findViewById(R.id.email);
citySpnr = (Spinner) findViewById(R.id.citySpiner);
spinnerText = (EditText) findViewById(R.id.spinnText);
userPick = (RadioGroup) findViewById(R.id.userActn);
client = new HttpClient(this);
client.getCities();
date_picker = new Date();
handleDatePicker();
cityList = UserData.getCityList();
ArrayAdapter<String> dataAdapter;
dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, cityList);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
citySpnr.setAdapter(dataAdapter);
}
public void profileReg(View view) {
if(citySpnr.getSelectedItem() == null){
return;
}
cityPick = citySpnr.getSelectedItem().toString();
User = userName.getText().toString();
firstname = firstName.getText().toString();
lstname = lastName.getText().toString();
streetNam = stretName.getText().toString();
streetNm = stretNum.getText().toString();
password = passwrd.getText().toString();
passafe = passwordSafty.getText().toString();
emailAdd = email.getText().toString();
datePick = birthDay.getText().toString();
radioButtonID = userPick.getCheckedRadioButtonId();
r = (RadioButton) userPick.findViewById(radioButtonID);
selectedtext = r.getText().toString();
}
那是堆栈跟踪
> 2019-03-18 23:40:12.265 12775-12775/? I/n2.minyanbazma: Not late-enabling -Xcheck:jni (already on)
2019-03-18 23:40:12.377 12775-12775/? W/n2.minyanbazma: Unexpected CPU variant for X86 using defaults: x86
2019-03-18 23:40:13.708 12775-12775/com.example.eran2.minyanbazman D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
2019-03-18 23:40:13.708 12775-12775/com.example.eran2.minyanbazman D/FirebaseApp: com.google.firebase.iid.FirebaseInstanceId is not linked. Skipping initialization.
2019-03-18 23:40:13.709 12775-12775/com.example.eran2.minyanbazman D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
2019-03-18 23:40:13.709 12775-12775/com.example.eran2.minyanbazman D/FirebaseApp: com.google.android.gms.measurement.AppMeasurement is not linked. Skipping initialization.
2019-03-18 23:40:13.710 12775-12775/com.example.eran2.minyanbazman I/FirebaseInitProvider: FirebaseApp initialization successful
2019-03-18 23:40:14.095 12775-12775/com.example.eran2.minyanbazman W/n2.minyanbazma: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-03-18 23:40:14.096 12775-12775/com.example.eran2.minyanbazman W/n2.minyanbazma: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-03-18 23:40:14.345 12775-12775/com.example.eran2.minyanbazman D/OpenGLRenderer: HWUI GL Pipeline
2019-03-18 23:40:14.484 12775-12797/com.example.eran2.minyanbazman I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-03-18 23:40:14.487 12775-12797/com.example.eran2.minyanbazman I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2019-03-18 23:40:14.487 12775-12797/com.example.eran2.minyanbazman I/OpenGLRenderer: Initialized EGL, version 1.4
2019-03-18 23:40:14.488 12775-12797/com.example.eran2.minyanbazman D/OpenGLRenderer: Swap behavior 1
2019-03-18 23:40:14.488 12775-12797/com.example.eran2.minyanbazman W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-03-18 23:40:14.488 12775-12797/com.example.eran2.minyanbazman D/OpenGLRenderer: Swap behavior 0
2019-03-18 23:40:14.518 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglCreateContext: 0xe6a96a00: maj 2 min 0 rcv 2
2019-03-18 23:40:14.568 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:14.651 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:41.207 12775-12775/com.example.eran2.minyanbazman W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@e7260ab
2019-03-18 23:40:41.737 12775-12775/com.example.eran2.minyanbazman D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2019-03-18 23:40:42.247 12775-12787/com.example.eran2.minyanbazman I/n2.minyanbazma: Background concurrent copying GC freed 9887(1787KB) AllocSpace objects, 4(76KB) LOS objects, 49% free, 2MB/4MB, paused 1.161ms total 379.081ms
2019-03-18 23:40:42.408 12775-12775/com.example.eran2.minyanbazman I/Choreographer: Skipped 72 frames! The application may be doing too much work on its main thread.
2019-03-18 23:40:42.863 12775-12797/com.example.eran2.minyanbazman I/OpenGLRenderer: Davey! duration=1661ms; Flags=1, IntendedVsync=56331387107154, Vsync=56332587107106, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=56332594920730, AnimationStart=56332595040900, PerformTraversalsStart=56332597284800, DrawStart=56333003579010, SyncQueued=56333003845440, SyncStart=56333003985280, IssueDrawCommandsStart=56333004055410, SwapBuffers=56333023892140, FrameCompleted=56333049220790, DequeueBufferDuration=523000, QueueBufferDuration=2855000,
2019-03-18 23:40:42.911 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:43.211 12775-12797/com.example.eran2.minyanbazman I/OpenGLRenderer: Davey! duration=778ms; Flags=0, IntendedVsync=56332616272503, Vsync=56333049605819, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=56333053216780, AnimationStart=56333053366040, PerformTraversalsStart=56333056984410, DrawStart=56333060192250, SyncQueued=56333095644320, SyncStart=56333098365910, IssueDrawCommandsStart=56333110930800, SwapBuffers=56333266857230, FrameCompleted=56333397917730, DequeueBufferDuration=542000, QueueBufferDuration=1120000,
2019-03-18 23:40:43.382 12775-12775/com.example.eran2.minyanbazman I/Choreographer: Skipped 30 frames! The application may be doing too much work on its main thread.
2019-03-18 23:40:43.678 12775-12797/com.example.eran2.minyanbazman I/OpenGLRenderer: Davey! duration=798ms; Flags=0, IntendedVsync=56333065637659, Vsync=56333565637639, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=56333569139190, AnimationStart=56333569261500, PerformTraversalsStart=56333570195920, DrawStart=56333580787200, SyncQueued=56333599157920, SyncStart=56333599308880, IssueDrawCommandsStart=56333599519720, SwapBuffers=56333716487310, FrameCompleted=56333864473920, DequeueBufferDuration=718000, QueueBufferDuration=964000,
2019-03-18 23:40:43.922 12775-12775/com.example.eran2.minyanbazman V/AsyncHttpRH: Progress 1140 from 1 (114000%)
2019-03-18 23:40:43.925 12775-12775/com.example.eran2.minyanbazman V/AsyncHttpRH: Progress 5236 from 1 (523600%)
2019-03-18 23:40:43.930 12775-12775/com.example.eran2.minyanbazman V/AsyncHttpRH: Progress 9332 from 1 (933200%)
2019-03-18 23:40:43.936 12775-12775/com.example.eran2.minyanbazman V/AsyncHttpRH: Progress 13428 from 1 (1342800%)
2019-03-18 23:40:43.938 12775-12775/com.example.eran2.minyanbazman V/AsyncHttpRH: Progress 13442 from 1 (1344200%)
2019-03-18 23:40:43.941 12775-12775/com.example.eran2.minyanbazman V/AsyncHttpRH: Progress 17538 from 1 (1753800%)
2019-03-18 23:40:43.942 12775-12775/com.example.eran2.minyanbazman V/AsyncHttpRH: Progress 18282 from 1 (1828200%)
2019-03-18 23:40:44.099 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:45.838 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:46.514 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:46.596 12775-12797/com.example.eran2.minyanbazman I/chatty: uid=10085(com.example.eran2.minyanbazman) RenderThread identical 1 line
2019-03-18 23:40:46.689 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:46.840 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:46.899 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:48.809 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:49.092 12775-12797/com.example.eran2.minyanbazman I/chatty: uid=10085(com.example.eran2.minyanbazman) RenderThread identical 3 lines
2019-03-18 23:40:49.278 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:49.281 12775-12797/com.example.eran2.minyanbazman D/OpenGLRenderer: endAllActiveAnimators on 0xd252e680 (DropDownListView) with handle 0xe7ca9ee0
2019-03-18 23:40:51.642 12775-12797/com.example.eran2.minyanbazman D/EGL_emulation: eglMakeCurrent: 0xe6a96a00: ver 2 0 (tinfo 0xef431ff0)
2019-03-18 23:40:51.817 12775-12775/com.example.eran2.minyanbazman D/AndroidRuntime: Shutting down VM
2019-03-18 23:40:51.820 12775-12775/com.example.eran2.minyanbazman E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.eran2.minyanbazman, PID: 12775
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at com.example.eran2.minyanbazman.RegistrationActivity.profileReg(RegistrationActivity.java:120)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2019-03-18 23:40:51.963 12775-12775/com.example.eran2.minyanbazman I/Process: Sending signal. PID: 12775 SIG: 9
请帮忙,我迷路了。