logcat没有给我特定的错误,它仅显示错误位置,该位置在第155行{id_status = spStatus.getSelectedItem().toString();}
我不知道解决该错误的正确关键字。我一直在浏览,我认为这与我遵循的教程相同。我的错误在哪里?给我更详细的说明
我的Java这样:
package src.bkkpost.loker;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Calendar;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import src.bkkpost.MainActivity;
import src.bkkpost.R;
import src.bkkpost.loker.adapter.AdapterStatus;
import src.bkkpost.model.Value;
import src.bkkpost.util.BaseApiService;
import src.bkkpost.util.SharedPrefManager;
import src.bkkpost.util.UtilsApi;
public class UpdateLoker extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
//string spinner kelamin
String[] idStatus = {"10", "20"};
String[] nama_status = {"Buka", "Tutup"};
//string spinner kelamin
String[] id_kelamin = {"5001", "5002", "5003"};
String[] nama_kelamin = {"Pria/Wanita", "Pria", "Wanita"};
//string spinner pendidikan
String[] pendidikan_id = {"3001", "3002", "3003", "30004", "3005", "3006", "3007"};
String[] nama_pendidikan = {"SD", "SMP", "SMA", "SMK ", "Diploma/(D3)", "Sarjana/(S1)", "Master/(S2)"};
//string spinner pendidikan
String[] jurusan_id = {"30001", "300301", "300302", "3000401", "3000402", "3000403", "3000404",
"3000405", "3000406", "3000407", "3000408", "3000409", "3000410", "3000411", "3000412", "3000413", "3000414",
"3000415", "300501", "300502", "300503", "300504", "300505", "300506", "300075"};
String[] nama_jurusan = {"Semua Jurusan", "IPA", "IPS", "Administrasi Perkantoran ", "Akuntansi ", "ANalisis Kimia ",
"Animasi ", "Broadcasting ", "Elektronik ", "Farmasi ", "Multimedia ", "Otomotif ", "Pariwisata ", "Pemasaran ",
"Perbankan ", "Perhotelan", "Tata Boga ", "Tata Busana ", "Perpajakan(D3/S1) ", "Broadcasting(D3/S1)", "Teknik Mesin(D3/S1)",
"Pariwisata(D3/S1)", "Sekretaris (D3/S1)", "Hubungan Masyarakat (D3/S1)", "Akuntansi(D3/S1) "};
AutoCompleteTextView date;
DatePickerDialog datePickerDialog;
BaseApiService mApiservice;
ProgressDialog loading;
Context mContex;
SharedPrefManager sharedPrefManager;
public static final String URL = "http://192.168.43.164/gokerja/";
private ProgressDialog progress;
String bkk_id, posisi, nama_pt, alamat_pt, waktu_buka, id_status;
@BindView(R.id.post_btn_upload)
Button btnUpload;
@BindView(R.id.post_bkk_id)
TextView tvBkkid;
@BindView(R.id.post_posisi)
AutoCompleteTextView etPosisi;
@BindView(R.id.post_namaperusahaan)
AutoCompleteTextView etNamaperusahan;
@BindView(R.id.post_alamat_pt)
AutoCompleteTextView etAlamat;
@BindView(R.id.post_tanggal)
AutoCompleteTextView etTangggal;
@BindView(R.id.post_spin_statusup)
Spinner spStatus;
@OnClick(R.id.post_btn_upload)
void daftar() { }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loker_update_loker);
ButterKnife.bind(this);
sharedPrefManager = new SharedPrefManager(this);
tvBkkid.setText(sharedPrefManager.getSPNama());
mApiservice = UtilsApi.getAPIService();
mContex = this;
date = (AutoCompleteTextView) findViewById(R.id.post_tanggal);
date.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final java.util.Calendar c = java.util.Calendar.getInstance();
int mYear = c.get(java.util.Calendar.YEAR);
int mMont = c.get(Calendar.MONTH);
int mDay = c.get(java.util.Calendar.DAY_OF_MONTH);
//date picker dialog
datePickerDialog = new DatePickerDialog(UpdateLoker.this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int month, int dayOfMonth) {
date.setText(year + "-"
+ (month + 1) + "-" + dayOfMonth);
}
}, mYear, mMont, mDay);
datePickerDialog.show();
}
});
//get spinner status
final Spinner spinnerStatus = (Spinner) findViewById(R.id.post_spin_statusup);
spinnerStatus.setOnItemSelectedListener(this);
AdapterStatus adapterStatus = new AdapterStatus(getApplicationContext(), idStatus);
spinnerStatus.setAdapter(adapterStatus);
progress = new ProgressDialog(this);
btnUpload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (etPosisi.getText().toString().equals("")) {
etPosisi.setError("Posisi harus di isi");
} else if (etNamaperusahan.getText().toString().equals("")) {
etNamaperusahan.setError("Perusahaan harus di isi");
} else if (etAlamat.getText().toString().equals("")) {
etAlamat.setError("alamat harus di isi");
} else {
//Untuk menampilkan progress dialog
progress.setCancelable(false);
progress.setMessage("Loading...");
progress.show();
bkk_id = tvBkkid.getText().toString();
posisi = etPosisi.getText().toString();
nama_pt = etNamaperusahan.getText().toString();
alamat_pt = etAlamat.getText().toString();
waktu_buka = etTangggal.getText().toString();
id_status = spStatus.getSelectedItem().toString();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
BaseApiService api = retrofit.create(BaseApiService.class);
Call<Value> call = api.post_loker(bkk_id, posisi, nama_pt, alamat_pt, waktu_buka, id_status);
call.enqueue(new Callback<Value>() {
@Override
public void onResponse(Call<Value> call, Response<Value> response) {
String value = response.body().getValue();
String message = response.body().getMessage();
progress.dismiss();
if (value.equals("1")) {
AlertDialog.Builder alert = new AlertDialog.Builder(UpdateLoker.this);
alert.setTitle("Confirm");
alert.setMessage("Iklan Lowongan kerja telah berhasil dibuat");
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(mContex, MainActivity.class));
dialog.dismiss();
}
});
alert.show();
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(UpdateLoker.this);
alert.setTitle("Confirm");
alert.setMessage("Terjadi Kesalahan Jaringan, Iklan gagal dibuat");
alert.setPositiveButton("Coba Lagi", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(mContex, UpdateLoker.class));
dialog.dismiss();
}
});
alert.show();
}
}
@Override
public void onFailure(Call<Value> call, Throwable t) {
t.printStackTrace();
progress.dismiss();
AlertDialog.Builder alert = new AlertDialog.Builder(UpdateLoker.this);
alert.setTitle("Error 301");
alert.setMessage("Terjadi kesalahan jaringan, Iklan gagal dibuat");
alert.setPositiveButton("Coba Lagi", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
//Toast.makeText(UpdateLoker.this, "semelekete", Toast.LENGTH_SHORT).show();
}
});
}
}
});
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
这是我的Logcat
09-04 17:13:15.904 16015-16015/src.bkkpost D/AndroidRuntime: Shutting down VM
09-04 17:13:15.904 16015-16015/src.bkkpost W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x419f3d58)
--------- beginning of /dev/log/system
09-04 17:13:15.904 16015-16015/src.bkkpost E/AndroidRuntime: FATAL EXCEPTION: main
Process: src.bkkpost, PID: 16015
java.lang.NullPointerException
at src.bkkpost.loker.UpdateLoker$2.onClick(UpdateLoker.java:155)
at android.view.View.performClick(View.java:4444)
at android.view.View$PerformClick.run(View.java:18457)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)