myOnClickListener = new MyOnClickListener(this);
nRecyclerView = (RecyclerView) findViewById(R.id.my_recycler2_view);
nRecyclerView.setHasFixedSize(true);
static class MyOnClickListener implements View.OnClickListener{
private final Context context;
private MyOnClickListener(Context context) {
this.context = context;
}
public void onClick(View v) {
checkWhich(v);
}
private static void checkWhich (View v){
int selectedItemPosition = nRecyclerView.getChildPosition(v);
RecyclerView.ViewHolder nViewHolder = nRecyclerView.findViewHolderForPosition (selectedItemPosition);
TextView textViewName = (TextView) nViewHolder.itemView.findViewById(R.id.textViewCountry);
String selectedName = (String) textViewName.getText();
for (int i = 0; i < MyData.countryArray.length; i++){
if (selectedName==MyData.countryArray[i]) {
System.out.println(selectedName);
}
}
}
}
This has worked before, but isnt working now. Did I do anything wrong? I have 2 RecyclerViews but they are not visible together. This click listener is for one RecyclerView only.
LogCat
01-31 18:41:17.514 3441-3441/com.wc.gap.worldcupfixture I/art﹕ Late-enabling -Xcheck:jni
01-31 18:41:17.761 3441-3471/com.wc.gap.worldcupfixture D/OpenGLRenderer﹕ Render dirty regions requested: true
01-31 18:41:17.767 3441-3441/com.wc.gap.worldcupfixture D/Atlas﹕ Validating map...
01-31 18:41:17.792 3441-3471/com.wc.gap.worldcupfixture I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: QUALCOMM Build: 10/24/14, 167c270, I68fa98814b
01-31 18:41:17.793 3441-3471/com.wc.gap.worldcupfixture I/OpenGLRenderer﹕ Initialized EGL, version 1.4
01-31 18:41:17.805 3441-3471/com.wc.gap.worldcupfixture D/OpenGLRenderer﹕ Enabling debug mode 0
01-31 18:41:57.529 3441-3470/com.wc.gap.worldcupfixture I/System.out﹕ 544, 543, 646, 797, 64, 66, 987
01-31 18:43:25.218 4242-4271/com.wc.gap.worldcupfixture D/OpenGLRenderer﹕ Render dirty regions requested: true
01-31 18:43:25.224 4242-4242/com.wc.gap.worldcupfixture D/Atlas﹕ Validating map...
01-31 18:43:25.257 4242-4271/com.wc.gap.worldcupfixture I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: QUALCOMM Build: 10/24/14, 167c270, I68fa98814b
01-31 18:43:25.258 4242-4271/com.wc.gap.worldcupfixture I/OpenGLRenderer﹕ Initialized EGL, version 1.4
01-31 18:43:25.270 4242-4271/com.wc.gap.worldcupfixture D/OpenGLRenderer﹕ Enabling debug mode 0
When implementing View.OnClickListener, do it like below.
public class YourClass extends Activity implements View.OnClickListener
#Override
protected void onCreate(Bundle savedInstanceState) {
//Component setup here.
nRecyclerView = (RecyclerView) findViewById(R.id.my_recycler2_view);
nRecyclerView.setHasFixedSize(true);
nRecyclerView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
checkWhich(v);
}
private static void checkWhich (View v){
int selectedItemPosition = nRecyclerView.getChildPosition(v);
RecyclerView.ViewHolder nViewHolder = nRecyclerView.findViewHolderForPosition (selectedItemPosition);
TextView textViewName = (TextView) nViewHolder.itemView.findViewById(R.id.textViewCountry);
String selectedName = textViewName.getText().toString();
for (int i = 0; i < MyData.countryArray.length; i++){
if (selectedName==MyData.countryArray[i]) {
System.out.println(selectedName);
}
}
}
}
Related
I have the following code with no compilation errors, just resulting in an infinite loop... I don't get where the problem is.
When I click the Button, I want to create an object using the values entered in the edittexts and pass them to another activity. But instead, I get a loop.
Each spinner is populated using a string-array from resources/strings. I had some difficulties getting the values here, because at the spinner spTipUtilizator when "Profesor" is selected, I want spGrupa to be disabled, and when "Student" is selected, I want spdept to be disabled, but also this doesn't work. And based on that option will be chosen the next activity which will be opened after clicking the button.
Also, why doesn't it work to set the default date in my calendar? I tried multiple things found here, but none of them worked for me. My Android Studio doesn't show DatePicker, which I would prefer, only that Calendar.
public class SignInActivity extends Activity {
private Button bSignup;
private EditText etNume, etPrenume, etUsername, etPassword, etConfirmPass, etEmail;
private RadioButton rbMasc, rbFem;
private Spinner spTipUtilizator, spgrupa, spdept;
private ProgressBar progBar;
private Calendar calendar;
private int year, month, day, currentYear, defday, defmonth, defyear;
private List<String> tipUtilizatorList, grupaList;
private ArrayAdapter<String> spinnerArrayAdapterTipU;
private String nume,prenume,username,password,password2,email,masc,fem,sex,tipUser,dept,DataN;
private int grupa;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
calendar=Calendar.getInstance();
calendar.set(1990,12,12);
bSignup = findViewById(R.id.buttonSignin);
etNume=findViewById(R.id.et_nume);
etPrenume=findViewById(R.id.et_prenume);
etUsername=findViewById(R.id.et_username);
etPassword=findViewById(R.id.et_password);
etConfirmPass = findViewById(R.id.et_confirmpassword);
etEmail=findViewById(R.id.et_email);
rbMasc=findViewById(R.id.radioButtonMasc);
rbFem=findViewById(R.id.radioButtonFem);
spTipUtilizator=findViewById(R.id.spinnerTipUtilizator);
spgrupa=findViewById(R.id.spinnerGrupa);
spdept=findViewById(R.id.spinnerDepartament);
progBar = findViewById(R.id.progressBar);
tipUtilizatorList=new ArrayList<>(Arrays.asList(getResources().getStringArray((R.array.tipUtilizator))));
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,tipUtilizatorList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spTipUtilizator.setAdapter(adapter);
grupaList = new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.grupa)));
bSignup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
nume = etNume.getText().toString().trim();
prenume = etPrenume.getText().toString().trim();
username = etUsername.getText().toString().trim();
password = etPassword.getText().toString().trim();
password2 = etConfirmPass.getText().toString().trim();
email = etEmail.getText().toString().trim();
masc = rbMasc.getText().toString().trim();
fem = rbFem.getText().toString().trim();
sex=fem;
tipUser = spTipUtilizator.getSelectedItem().toString().trim();
grupa = Integer.parseInt(spgrupa.getSelectedItem().toString().trim());
dept = spdept.getSelectedItem().toString().trim();
DataN = day+"/"+month+"/"+year;
progBar.setVisibility(View.VISIBLE);
if(rbFem.isChecked()) {
sex=fem;
}
else if(rbMasc.isChecked()) {
sex=masc;
}
spTipUtilizator.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String Text = parent.getSelectedItem().toString();
if(Text.equals("Profesor")) {
spgrupa.getSelectedView().setEnabled(false);
spdept.getSelectedView().setEnabled(true);
Intent intent = new Intent(getApplicationContext(),StartProfesorActivity.class);
Profesor prof = new Profesor(nume,prenume,username,password,email,sex,dept,DataN);
intent.putExtra("profesor",prof);
startActivity(intent);
return;
}
else if(Text.equals("Student")) {
spgrupa.getSelectedView().setEnabled(true);
spdept.getSelectedView().setEnabled(false);
Intent intent = new Intent(getApplicationContext(),StartStudentActivity.class);
Student stud = new Student(nume,prenume,username,password,email,sex,grupa, DataN);
intent.putExtra("student",stud);
startActivity(intent);
return;
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
});
}
}
Log:
D/AbsListView: in onLayout changed
D/ViewRootImpl#cab402e[PopupWindow:ad4e773]: MSG_WINDOW_FOCUS_CHANGED 1
V/InputMethodManager: Not IME target window, ignoring
D/ViewRootImpl#cab402e[PopupWindow:ad4e773]: MSG_RESIZED_REPORT: frame=Rect(266, 72 - 422, 1047) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/ViewRootImpl#27d7010[SignInActivity]: MSG_WINDOW_FOCUS_CHANGED 0
D/ViewRootImpl#cab402e[PopupWindow:ad4e773]: ViewPostIme pointer 0
D/ViewRootImpl#cab402e[PopupWindow:ad4e773]: ViewPostIme pointer 1
D/AbsListView: onTouchUp() mTouchMode : 0
D/ViewRootImpl#cab402e[PopupWindow:ad4e773]: Relayout returned: old=[266,72][422,1047] new=[266,72][422,1047] result=0x1 surface={valid=true 481098420224} changed=false
D/ViewRootImpl#27d7010[SignInActivity]: MSG_WINDOW_FOCUS_CHANGED 1
D/ViewRootImpl#cab402e[PopupWindow:ad4e773]: MSG_WINDOW_FOCUS_CHANGED 0
I/zygote64: Compiler allocated 4MB to compile void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
I/OpenGLRenderer: prepareTree mLayerUpdateQueue is not empty, size = 1
name = PopupWindow$PopupBackgroundView, size (156, 975)
D/OpenGLRenderer: eglDestroySurface = 0x6ff4459d80
endAllActiveAnimators on 0x6ff591ec00 (DropDownListView) with handle 0x7003b6eb00
D/ViewRootImpl#cab402e[PopupWindow:ad4e773]: dispatchDetachedFromWindow
D/InputEventReceiver: channel '468478f PopupWindow:ad4e773 (client)' ~ Disposing input event receiver.
channel '468478f PopupWindow:ad4e773 (client)' ~NativeInputEventReceiver.
D/ViewRootImpl#27d7010[SignInActivity]: ViewPostIme pointer 0
D/ViewRootImpl#27d7010[SignInActivity]: ViewPostIme pointer 1
D/ViewRootImpl#27d7010[SignInActivity]: ViewPostIme pointer 0
D/ViewRootImpl#27d7010[SignInActivity]: ViewPostIme pointer 1
D/ViewRootImpl#27d7010[SignInActivity]: ViewPostIme pointer 0
D/ViewRootImpl#27d7010[SignInActivity]: ViewPostIme pointer 1
D/ViewRootImpl#27d7010[SignInActivity]: ViewPostIme pointer 0
D/ViewRootImpl#27d7010[SignInActivity]: ViewPostIme pointer 1
V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo#54a19af nm : com.example.ancaa.proiectandroidquiz ic=com.android.internal.widget.EditableInputConnection#ba71bc
I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
W/IInputConnectionWrapper: getCursorCapsMode on inactive InputConnection
W/IInputConnectionWrapper: getCursorCapsMode on inactive InputConnection
W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
D/OpenGLRenderer: eglDestroySurface = 0x7003ab7400
D/ViewRootImpl#27d7010[SignInActivity]: Relayout returned: old=[0,0][1080,1920] new=[0,0][1080,1920] result=0x5 surface={valid=false 0} changed=true
D/ViewRootImpl#27d7010[SignInActivity]: MSG_WINDOW_FOCUS_CHANGED 0
D/ViewRootImpl#27d7010[SignInActivity]: Relayout returned: old=[0,0][1080,1920] new=[0,0][1080,1920] result=0x1 surface={valid=false 0} changed=false
Application terminated.
You shouldn't create the OnItemSelectedListener inside the OnClickListener for your sign in button, instead you have to create it outside and save the selected option in a variable.
Then when the user clicks your sign in button, you check witch option was selected and start the correct Activity.
Looking at your code, you could simply save the intent to the next activity, and when the user clicks the button just start the Activity on that intent.
I've put a check for nullity before trying to start that intent, and you could show the user some dialog or Toast if no valid option was selected.
public class SignInActivity extends Activity {
private Button bSignup;
private EditText etNume, etPrenume, etUsername, etPassword, etConfirmPass, etEmail;
private RadioButton rbMasc, rbFem;
private Spinner spTipUtilizator, spgrupa, spdept;
private ProgressBar progBar;
private Calendar calendar;
private int year, month, day, currentYear, defday, defmonth, defyear;
private List<String> tipUtilizatorList, grupaList;
private ArrayAdapter<String> spinnerArrayAdapterTipU;
private String nume,prenume,username,password,password2,email,masc,fem,sex,tipUser,dept,DataN;
private int grupa;
private Intent activityToStart;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
calendar=Calendar.getInstance();
calendar.set(1990,12,12);
bSignup = findViewById(R.id.buttonSignin);
etNume=findViewById(R.id.et_nume);
etPrenume=findViewById(R.id.et_prenume);
etUsername=findViewById(R.id.et_username);
etPassword=findViewById(R.id.et_password);
etConfirmPass = findViewById(R.id.et_confirmpassword);
etEmail=findViewById(R.id.et_email);
rbMasc=findViewById(R.id.radioButtonMasc);
rbFem=findViewById(R.id.radioButtonFem);
spTipUtilizator=findViewById(R.id.spinnerTipUtilizator);
spgrupa=findViewById(R.id.spinnerGrupa);
spdept=findViewById(R.id.spinnerDepartament);
progBar = findViewById(R.id.progressBar);
tipUtilizatorList=new ArrayList<>(Arrays.asList(getResources().getStringArray((R.array.tipUtilizator))));
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,tipUtilizatorList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spTipUtilizator.setAdapter(adapter);
grupaList = new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.grupa)));
bSignup.setOnClickListener(v -> {
nume = etNume.getText().toString().trim();
prenume = etPrenume.getText().toString().trim();
username = etUsername.getText().toString().trim();
password = etPassword.getText().toString().trim();
password2 = etConfirmPass.getText().toString().trim();
email = etEmail.getText().toString().trim();
masc = rbMasc.getText().toString().trim();
fem = rbFem.getText().toString().trim();
sex=fem;
tipUser = spTipUtilizator.getSelectedItem().toString().trim();
grupa = Integer.parseInt(spgrupa.getSelectedItem().toString().trim());
dept = spdept.getSelectedItem().toString().trim();
DataN = day+"/"+month+"/"+year;
progBar.setVisibility(View.VISIBLE);
if(rbFem.isChecked()) {
sex=fem;
}
else if(rbMasc.isChecked()) {
sex=masc;
}
if(activityToStart != null)
startActivity(activityToStart);
});
spTipUtilizator.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String Text = parent.getSelectedItem().toString();
if(Text.equals("Profesor")) {
spgrupa.getSelectedView().setEnabled(false);
spdept.getSelectedView().setEnabled(true);
activityToStart = new Intent(getApplicationContext(),StartProfesorActivity.class);
Profesor prof = new Profesor(nume,prenume,username,password,email,sex,dept,DataN);
activityToStart.putExtra("profesor",prof);
return;
}
else if(Text.equals("Student")) {
spgrupa.getSelectedView().setEnabled(true);
spdept.getSelectedView().setEnabled(false);
activityToStart = new Intent(getApplicationContext(),StartStudentActivity.class);
Student stud = new Student(nume,prenume,username,password,email,sex,grupa, DataN);
activityToStart.putExtra("student",stud);
return;
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
My app gets data from a PHP file. 3 normal textdata and 5 image urls. The app displays them in a recyclerview with cardviews.
My problem is, that the app crashes when getting empty image urls.
But with empty textdata the app works without problems.
Like:
textdata with content + image urls with content = works
Empty textdata + empty image urls = App crashes
Empty textdata + image urls with content = works
textdata with content + empty image urls = App crashes
This is the getting and sending (to RecyclerviewAdapter) Code:
public void JSON_DATA_WEB_CALL (String url){
jsonArrayRequest = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
JSON_PARSE_DATA_AFTER_WEBCALL(response);
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonArrayRequest);
}
public void JSON_PARSE_DATA_AFTER_WEBCALL(JSONArray array) {
for (int i = 0; i < array.length(); i++) {
GetDataAdapter GetDataAdapter2 = new GetDataAdapter();
JSONObject json = null;
try {
json = array.getJSONObject(i);
GetDataAdapter2.setImageUrl(json.getString(Image_URL_JSON));
GetDataAdapter2.setImageUrl2(json.getString(Image_URL_JSON2));
GetDataAdapter2.setImageUrl3(json.getString(Image_URL_JSON3));
GetDataAdapter2.setImageUrl4(json.getString(Image_URL_JSON4));
GetDataAdapter2.setImageUrl5(json.getString(Image_URL_JSON5));
GetDataAdapter2.setPhone_number(json.getString(SOMETEXT));
GetDataAdapter2.setName(json.getString(SOMETEXT2));
GetDataAdapter2.setSubject2(json.getString(SOMETEXT3));
} catch (JSONException e) {
e.printStackTrace();
}
GetDataAdapter1.add(GetDataAdapter2);
}
recyclerViewadapter = new RecyclerViewAdapter(solutionTemplate.this, GetDataAdapter1, exerciseAdapter);
recyclerView.setAdapter(recyclerViewadapter);
}
The mainproblem is:
json = array.getJSONObject(i);
GetDataAdapter2.setImageUrl(json.getString(Image_URL_JSON));
GetDataAdapter2.setImageUrl2(json.getString(Image_URL_JSON2));
GetDataAdapter2.setImageUrl3(json.getString(Image_URL_JSON3));
GetDataAdapter2.setImageUrl4(json.getString(Image_URL_JSON4));
GetDataAdapter2.setImageUrl5(json.getString(Image_URL_JSON5));
GetDataAdapter2.setPhone_number(json.getString(SOMETEXT));
GetDataAdapter2.setName(json.getString(SOMETEXT2));
GetDataAdapter2.setSubject2(json.getString(SOMETEXT3));
Working:
json = array.getJSONObject(i);
GetDataAdapter2.setImageUrl(json.getString(Image_URL_JSON));
GetDataAdapter2.setImageUrl2(json.getString(Image_URL_JSON2));
GetDataAdapter2.setImageUrl3(json.getString(Image_URL_JSON3));
GetDataAdapter2.setImageUrl4(json.getString(Image_URL_JSON4));
GetDataAdapter2.setImageUrl5(json.getString(Image_URL_JSON5));
Not working:
GetDataAdapter2.setPhone_number(json.getString(SOMETEXT));
GetDataAdapter2.setName(json.getString(SOMETEXT2));
GetDataAdapter2.setSubject2(json.getString(SOMETEXT3));
Getting image urls with content is necassary!
But it should work without it!
This is the GetDataAdapter:
public String getPhone_number() {
return phone_number;
}
public void setPhone_number(String phone_number1) {
this.phone_number = phone_number1;
}
public String getSubject2() {
return subject2;
}
public void setSubject2(String subject2) {
this.subject2 = subject2;
}
public String getImageUrl() {
return ImageURL;
}
public void setImageUrl(String imageServerUrl) {
this.ImageURL = imageServerUrl;
}
public String getImageUrl2() {
return ImageURL2;
}
public void setImageUrl2(String imageServerUrl2) {
this.ImageURL2 = imageServerUrl2;
}
public String getImageUrl3() {
return ImageURL3;
}
public void setImageUrl3(String imageServerUrl3) {
this.ImageURL3 = imageServerUrl3;
}
public String getImageUrl4() {
return ImageURL4;
}
public void setImageUrl4(String imageServerUrl4) {
this.ImageURL4 = imageServerUrl4;
}
public String getImageUrl5() {
return ImageURL5;
}
public void setImageUrl5(String imageServerUrl5) {
this.ImageURL5 = imageServerUrl5;
}
RecyclerViewAdapter:
#Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ViewHolder) {
final GetDataAdapter current = getItem(position - 1);
final ViewHolder holder1 = (ViewHolder) holder;
final ImageLoader imageLoader = ImageAdapter.getInstance(context).getImageLoader();
final ImageLoader imageLoader2 = ImageAdapter.getInstance(context).getImageLoader();
final ImageLoader imageLoader3 = ImageAdapter.getInstance(context).getImageLoader();
final ImageLoader imageLoader4 = ImageAdapter.getInstance(context).getImageLoader();
final ImageLoader imageLoader5 = ImageAdapter.getInstance(context).getImageLoader();
imageLoader.get(current.getImageUrl(),
ImageLoader.getImageListener(
holder1.imageView1,
R.mipmap.ic_launcher_image,
android.R.drawable.ic_dialog_alert
)
);
imageLoader2.get(current.getImageUrl2(),
ImageLoader.getImageListener(
holder1.imageView2,
R.mipmap.ic_launcher_image,
android.R.drawable.ic_dialog_alert
)
);
imageLoader3.get(current.getImageUrl3(),
ImageLoader.getImageListener(
holder1.imageView3,
R.mipmap.ic_launcher_image,
android.R.drawable.ic_dialog_alert
)
);
imageLoader4.get(current.getImageUrl4(),
ImageLoader.getImageListener(
holder1.imageView4,
R.mipmap.ic_launcher_image,
android.R.drawable.ic_dialog_alert
)
);
imageLoader5.get(current.getImageUrl5(),
ImageLoader.getImageListener(
holder1.imageView5,
R.mipmap.ic_launcher_image,
android.R.drawable.ic_dialog_alert
)
);
holder1.imageView1.setImageUrl(current.getImageUrl(), imageLoader);
holder1.imageView2.setImageUrl(current.getImageUrl2(), imageLoader2);
holder1.imageView3.setImageUrl(current.getImageUrl3(), imageLoader3);
holder1.imageView4.setImageUrl(current.getImageUrl4(), imageLoader4);
holder1.imageView5.setImageUrl(current.getImageUrl5(), imageLoader5);
holder1.NameTextView.setText(current.getName());
holder1.PhoneNumberTextView.setText(current.getPhone_number());
holder1.SubjectTextView.setText(current.getSubject2());
ImageAdapter:
public class ImageAdapter {
public static ImageAdapter imageAdapter;
public Network networkOBJ ;
public RequestQueue requestQueue1;
public ImageLoader Imageloader1;
public Cache cache1 ;
public static Context context1;
LruCache<String, Bitmap> LRUCACHE = new LruCache<String, Bitmap>(30);
private ImageAdapter(Context context) {
this.context1 = context;
this.requestQueue1 = RequestQueueFunction();
Imageloader1 = new ImageLoader(requestQueue1, new ImageLoader.ImageCache() {
#Override
public Bitmap getBitmap(String URL) {
return LRUCACHE.get(URL);
}
#Override
public void putBitmap(String url, Bitmap bitmap) {
LRUCACHE.put(url, bitmap);
}
});
}
public ImageLoader getImageLoader() {
return Imageloader1;
}
public static ImageAdapter getInstance(Context SynchronizedContext) {
if (imageAdapter == null) {
imageAdapter = new ImageAdapter(SynchronizedContext);
}
return imageAdapter;
}
public RequestQueue RequestQueueFunction() {
if (requestQueue1 == null) {
cache1 = new DiskBasedCache(context1.getCacheDir());
networkOBJ = new BasicNetwork(new HurlStack());
requestQueue1 = new RequestQueue(cache1, networkOBJ);
requestQueue1.start();
}
return requestQueue1;
}
}
PHP:
<?php
$conn = mysqli_connect('localhost', 'root', '','webapp');
$id = $_GET['id'];
$sql = "SELECT * FROM answers WHERE id='$id' ORDER BY id DESC";
$res = mysqli_query($conn,$sql);
$result = array();
while($row = mysqli_fetch_array($res)){
array_push($result,array(
'url2'=>$row['images'],
'url3'=>$row['images2'],
'url4'=>$row['images3'],
'url5'=>$row['images4'],
'url6'=>$row['images5'],
'subject'=>$row['subject'],
'phone'=>$row['phone'],
'name'=>$row['name']));
}
echo json_encode(array_values($result));
mysqli_close($conn);
?>
If PHP sends url2, url3, url4... without content the app chrashes, but phone, name, subject with empty values works without problems.
I think Android has a Problem with converting empty imageurls and with displaying it.
EDIT:
A lot of users said that I have to add the Logcat:
07-16 13:12:10.713 1578-1990/system_process W/ActivityManager: Force finishing activity com.example.jakob.webapplicationsave/.solutionTemplate
07-16 13:12:10.822 1578-1990/system_process W/ActivityManager: Force finishing activity com.example.jakob.webapplicationsave/.Main2Activity
07-16 13:12:10.946 1578-2630/system_process I/OpenGLRenderer: Initialized EGL, version 1.4
07-16 13:12:10.947 1578-2630/system_process D/EGL_emulation: eglCreateContext: 0x9c2be040: maj 2 min 0 rcv 2
07-16 13:12:10.953 1578-2630/system_process D/EGL_emulation: eglMakeCurrent: 0x9c2be040: ver 2 0 (tinfo 0x9efbd6e0)
07-16 13:12:10.962 1578-2630/system_process D/EGL_emulation: eglMakeCurrent: 0x9c2be040: ver 2 0 (tinfo 0x9efbd6e0)
07-16 13:12:11.323 1578-1592/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{e46f507 u0 com.example.jakob.webapplicationsave/.solutionTemplate t497 f}
07-16 13:12:11.372 1930-2076/com.android.launcher3 I/OpenGLRenderer: Initialized EGL, version 1.4
07-16 13:12:11.374 1930-2076/com.android.launcher3 D/EGL_emulation: eglCreateContext: 0xae414660: maj 2 min 0 rcv 2
07-16 13:12:11.385 1930-2076/com.android.launcher3 D/EGL_emulation: eglMakeCurrent: 0xae414660: ver 2 0 (tinfo 0xae412440)
07-16 13:12:11.423 1930-2076/com.android.launcher3 D/EGL_emulation: eglMakeCurrent: 0xae414660: ver 2 0 (tinfo 0xae412440)
07-16 13:12:13.537 1270-1616/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 38006369 , only wrote 37870012
07-16 13:12:14.795 13519-13519/com.example.jakob.webapplicationsave I/Process: Sending signal. PID: 13519 SIG: 9
07-16 13:12:14.814 1578-2630/system_process D/EGL_emulation: eglMakeCurrent: 0x9c2be040: ver 2 0 (tinfo 0x9efbd6e0)
07-16 13:12:14.815 1578-2630/system_process E/Surface: getSlotFromBufferLocked: unknown buffer: 0x9b6834a0
07-16 13:12:14.830 1578-2182/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 104)
07-16 13:12:14.830 1578-2182/system_process W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 13519 uid 10062
07-16 13:12:14.833 1578-2182/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 104)
07-16 13:12:14.847 1578-1713/system_process D/GraphicsStats: Buffer count: 5
07-16 13:12:14.847 1578-1625/system_process W/InputDispatcher: channel '7af27b1 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.Main2Activity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
07-16 13:12:14.847 1578-2182/system_process I/WindowState: WIN DEATH: Window{7af27b1 u0 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.Main2Activity}
07-16 13:12:14.847 1578-1625/system_process E/InputDispatcher: channel '7af27b1 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.Main2Activity (server)' ~ Channel is unrecoverably broken and will be disposed!
07-16 13:12:14.847 1578-1625/system_process W/InputDispatcher: channel 'cd3daa3 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.solutionTemplate (server)' ~ Consumer closed input channel or an error occurred. events=0x9
07-16 13:12:14.847 1578-1625/system_process E/InputDispatcher: channel 'cd3daa3 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.solutionTemplate (server)' ~ Channel is unrecoverably broken and will be disposed!
07-16 13:12:14.847 1578-2182/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel '7af27b1 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.Main2Activity (server)'
07-16 13:12:14.848 1578-2179/system_process I/WindowState: WIN DEATH: Window{cd3daa3 u0 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.solutionTemplate}
07-16 13:12:14.848 1578-2179/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel 'cd3daa3 com.example.jakob.webapplicationsave/com.example.jakob.webapplicationsave.solutionTemplate (server)'
07-16 13:12:14.853 1259-1259/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
07-16 13:12:14.853 1578-1963/system_process I/ActivityManager: Process com.example.jakob.webapplicationsave (pid 13519) has died
07-16 13:12:15.026 1578-1597/system_process W/AppOps: Finishing op nesting under-run: uid 1000 pkg android code 24 time=0 duration=0 nesting=0
07-16 13:12:17.958 1270-1616/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 38145850 , only wrote 38008822
07-16 13:13:00.065 1259-1351/? D/hwcomposer: hw_composer sent 312 syncs in 60s
07-16 13:14:00.056 1259-1351/? D/hwcomposer: hw_composer sent 5 syncs in 60s
These are the classes which I have made
logcat
11-09 11:34:49.183 27661-27661/? I/art: Late-enabling -Xcheck:jni
11-09 11:34:49.193 27661-27661/? D/TidaProvider: TidaProvider()
11-09 11:34:49.197 27661-27661/? V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance#ce504
11-09 11:34:49.348 27661-27661/nischayvaish.com.test1 W/System: ClassLoader referenced unknown path: /data/app/nischayvaish.com.test1-1/lib/arm64
11-09 11:34:49.360 27661-27661/nischayvaish.com.test1 I/InstantRun: starting instant run server: is main process
11-09 11:34:49.463 27661-27661/nischayvaish.com.test1 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
11-09 11:34:49.484 27661-27661/nischayvaish.com.test1 D/AccessibilityManager: current package=nischayvaish.com.test1, accessibility manager mIsFinalEnabled=false, mOptimizeEnabled=true, mIsUiAutomationEnabled=false, mIsInterestedPackage=false
11-09 11:34:49.512 27661-27661/nischayvaish.com.test1 V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance#d00846
11-09 11:34:49.512 27661-27661/nischayvaish.com.test1 V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance#73d0a07
11-09 11:34:49.593 27661-27661/nischayvaish.com.test1 V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance#ed682f7
11-09 11:34:49.593 27661-27661/nischayvaish.com.test1 V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance#f473564
11-09 11:34:49.647 27661-27661/nischayvaish.com.test1 E/HAL: PATH3 /odm/lib64/hw/gralloc.qcom.so
11-09 11:34:49.647 27661-27661/nischayvaish.com.test1 E/HAL: PATH2 /vendor/lib64/hw/gralloc.qcom.so
11-09 11:34:49.647 27661-27661/nischayvaish.com.test1 E/HAL: PATH1 /system/lib64/hw/gralloc.qcom.so
11-09 11:34:49.647 27661-27661/nischayvaish.com.test1 E/HAL: PATH3 /odm/lib64/hw/gralloc.msm8953.so
11-09 11:34:49.647 27661-27661/nischayvaish.com.test1 E/HAL: PATH2 /vendor/lib64/hw/gralloc.msm8953.so
11-09 11:34:49.647 27661-27661/nischayvaish.com.test1 E/HAL: PATH1 /system/lib64/hw/gralloc.msm8953.so
11-09 11:34:49.654 27661-27661/nischayvaish.com.test1 D/ActivityThreadInjector: clearCachedDrawables.
11-09 11:34:49.673 27661-27691/nischayvaish.com.test1 I/Adreno: QUALCOMM build : 01d2d27, I3d52eaf367
Build Date : 12/10/16
OpenGL ES Shader Compiler Version: XE031.09.00.03
Local Branch :
Remote Branch :
Remote Branch :
Reconstruct Branch :
11-09 11:34:49.679 27661-27691/nischayvaish.com.test1 I/OpenGLRenderer: Initialized EGL, version 1.4
11-09 11:34:49.679 27661-27691/nischayvaish.com.test1 D/OpenGLRenderer: Swap behavior 1
11-09 11:34:49.706 27661-27661/nischayvaish.com.test1 W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
This is my mainactivity class
public class MainActivity extends AppCompatActivity {
private TextView tv1;
private RecyclerView recycler_view;
private RecyclerView.LayoutManager layoutManager;
private ArrayList<IncomingNumber> arrayList = new ArrayList<>();
private RecyclerAdapter adapter;
private BroadcastReceiver broadcastReceiver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.emptyTxt);
recycler_view = (RecyclerView) findViewById(R.id.recyclerView);
layoutManager = new LinearLayoutManager(this);
adapter = new RecyclerAdapter(arrayList);
recycler_view.setLayoutManager(layoutManager);
recycler_view.setHasFixedSize(true);
recycler_view.setAdapter(adapter);
readFromDb();
broadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
readFromDb();
}
};
}
private void readFromDb() {
arrayList.clear();
DbHelper dbHelper = new DbHelper(this);
SQLiteDatabase database = dbHelper.getWritableDatabase();
Cursor cursor = dbHelper.readNumber(database);
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String number;
int id;
number = cursor.getString(cursor.getColumnIndex(DbContract.INCOMING_NUMBER));
id = cursor.getInt(cursor.getColumnIndex("id"));
arrayList.add(new IncomingNumber(id, number));
}
cursor.close();
dbHelper.close();
adapter.notifyDataSetChanged();
recycler_view.setVisibility(View.VISIBLE);
tv1.setVisibility(View.GONE);
}
}
#Override
protected void onResume() {
super.onResume();
registerReceiver(broadcastReceiver, new IntentFilter(DbContract.UPDATE_UI_FILTER));
unregisterReceiver(broadcastReceiver);
}
DbHelper.class
private static final String DATABASE_NAME = "numberDb";
private static final int DATABASE_VERSION = 2;
private static final String CREATE = "CREATE TABLE " + DbContract.TABLE_NAME + "(ID INTEGER PRIMARY KEY AUTOINCREMENT," + DbContract.INCOMING_NUMBER + " TEXT);";
private static final String DROP_TABLE = "drop table if exists " + DbContract.TABLE_NAME;
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(DROP_TABLE);
onCreate(db);
}
public void saveNumber(String number, SQLiteDatabase database) {
ContentValues contentValues = new ContentValues();
contentValues.put(DbContract.INCOMING_NUMBER, number);
database.insert(DbContract.TABLE_NAME, null, contentValues);
}
public Cursor readNumber(SQLiteDatabase database) {
String[] projection = {"id", DbContract.INCOMING_NUMBER};
return (database.query(DbContract.TABLE_NAME, projection, null, null, null, null, null));
}
On compiling code ,it compiled but it does not show any incoming call number.
currently I am beginner in Android So I did not understand the error properly.
Warning given by the application at the compile time,
Before Android 4.1, method int
android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int,
boolean) would have incorrectly overridden the package-private method
in android.widget.ListView
Phone permission is allowed.
can't write comment because my reputation but try to Toast array size after readFromDb() and Toast adapter count and recyclerview childCount to check if it really add the data to adapter and recyclerview or not
and try to delete recycler_view.setHasFixedSize(true); and let me know if it work or not
I have creted a class through which i want to get a list url's from the database. But I get this error:
03-30 15:05:35.599 3591-3591/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.imran.myapp, PID: 3591
java.lang.NullPointerException: Attempt to read from null array
at com.example.imran.myapp.gridgallery.onCreateView(gridgallery.java:55)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1026)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1207)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1572)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:493)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6145)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
03-30 15:05:35.599 1032-1045/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname com.example.imran.myapp
03-30 15:05:35.599 1032-1045/? W/ActivityManager: Force finishing activity com.example.imran.myapp/.Home
03-30 15:05:35.609 1032-1045/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname com.example.imran.myapp
03-30 15:05:35.909 1032-1032/? D/CrashAnrDetector: processName: com.example.imran.myapp
03-30 15:05:35.919 1032-1032/? D/CrashAnrDetector: broadcastEvent : com.example.imran.myapp data_app_crash
03-30 15:05:36.159 1032-1059/? W/ActivityManager: Activity pause timeout for ActivityRecord{3f2af340 u0 com.example.imran.myapp/.Home t3125 f}
03-30 15:05:37.019 1032-1521/? I/WindowState: WIN DEATH: Window{224e112b u0 com.example.imran.myapp/com.example.imran.myapp.Home}
03-30 15:05:37.079 1032-1528/? I/ActivityManager: Process com.example.imran.myapp (pid 3591)(adj 9) has died(67,606)
03-30 15:05:37.359 10199-10199/? D/AASAservice-UpdateReceiver: AASAUpdateReceiver: android.intent.action.PACKAGE_REPLACED, package = com.example.imran.myapp, uid = -1
03-30 15:05:37.379 2433-3619/? D/PkgBroadcastIntentOp: Received broadcast action=android.intent.action.PACKAGE_REPLACED and uri=com.example.imran.myapp
03-30 15:05:37.559 2433-3974/? D/k: Processing package: com.example.imran.myapp
03-30 15:05:37.559 2227-3976/? D/Compatibility: intentservice saw: Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:com.example.imran.myapp flg=0x4000010 cmp=com.sec.android.app.soundalive/.compatibility.Compatibility$Receiver (has extras) } Bundle[{android.intent.extra.UID=10252, android.intent.extra.REPLACING=true, android.intent.extra.user_handle=0}]
03-30 15:05:37.589 2433-3974/? D/GassUtils: Found app info for package com.example.imran.myapp:1. Hash: 6b9333e031907d7a6a6c12cd9fdfa0d23bd13ee0f40c9617ddd005dc358321b0
03-30 15:05:37.589 2433-3974/? D/k: Found info for package com.example.imran.myapp in db.
This is the activity in which i am using the class:
gridgallery.java
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_gridgallery, null);
Myserver myserver = new Myserver();
//postStringRequest(myserver.url + "/api/albums/getalbums.php", view);
AlbumsList albumsList = new AlbumsList(myserver.url+"/api/albums/getalbums.php",getContext(),view);
albumsList.connection(); // Do connection
Toast.makeText(getContext(),albumsList.imgsurls[1],Toast.LENGTH_LONG).show();
/*
GridView gv = (GridView)view.findViewById(R.id.fragment_gridgallery);
ImageAdapter myadapter = new ImageAdapter(getContext(),albumsList.imgurls());
gv.setAdapter(myadapter);
*/
return view;
}
AlbumsList.java
public class AlbumsList {
private String server;
Context mycontext;
public String[] imgsurls;
private View view;
AlbumsList(String serverurl, Context c,View uview){
mycontext = c;
server = serverurl;
view = uview;
}
public View connection(){
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(mycontext);
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.POST, server,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
//GridView gv = (GridView)view.findViewById(R.id.fragment_gridgallery);
final ArrayList<String> urls2 = new ArrayList<String>();
try {
JSONArray jsonObj = new JSONArray(response);
Myserver myserver = new Myserver();
for (int i=0;i<jsonObj.length();i++){
JSONObject c = jsonObj.getJSONObject(i);
String imgurl = myserver.url+"/images/thumbs/tn_"+c.getString("album_thumbnail");
urls2.add(imgurl);
}
final String myabc[] = urls2.toArray(new String[urls2.size()]); //Do not remove this
imgsurls = myabc;
Toast.makeText(mycontext, imgsurls[0], Toast.LENGTH_LONG).show(); //Interestingly this toast works and imgsurls[] is ok
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(mycontext,e.getLocalizedMessage(),Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(mycontext, "Unable to reach server", Toast.LENGTH_LONG).show();
}
}) {
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("getalbum", "getalbum");
return params;
}
};
queue.add(stringRequest);
return view;
}
public String[] imgurls(){
return imgsurls;
}
}
In AlbumsList.java, I want to return the list of URLS by either a function or variables, but both approachs don't work. Interestingly the url's are fetched proper from database. And that Toast inside AlbumsList.java: Toast.makeText(mycontext, imgsurls[0], Toast.LENGTH_LONG).show(); also works. Then I don't know why the imgsurls is not returned to main function. Thanks in advance.
Because Volley request is asynchronous.
Thus when are you calling albumsList.connection();, the request is running in background and before it is completed, control comes to the following line:
Toast.makeText(getContext(),albumsList.imgsurls[1],Toast.LENGTH_LONG).show();
And by that time, your request is not completed.
Volley works in an asynchronous fashion. This means that it doesn't return the result of the operation immediately. You are trying to access the results before they are fetched from the server.
You should move your view initialisation logic to the onResponse(), when the result is actually being delivered.
I would like to update my Listview in a fragmen in a onPostExecute() separate class.
The first initialization of the the Listview doas work, but wehe I call createList() again, the App crashes (NullPointerException)
Any Idea?
Main_Fragment:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View fragmentView = inflater.inflate(R.layout.main_fragment, container, false);
StartSocketService = (Button) fragmentView.findViewById(R.id.start_socketservice);
StartSocketService.setOnClickListener(this);
StopSocketService = (Button) fragmentView.findViewById(R.id.stop_socketservice);
StopSocketService.setOnClickListener(this);
listview = (ListView) fragmentView.findViewById(R.id.listView1);
createList();
return fragmentView;
}
public void createList(){
//Reading Server IPs from SharedPreferences and put them to ListView
SharedPreferences settings = getActivity().getSharedPreferences("Found_Devices", 0);
for (int i = 0; i < 255; i++) {
if ((settings.getString("Server"+i,null)) != null) {
serverList.add(settings.getString("Server"+i, null));
Log.v("Reading IP: " +settings.getString("Server"+i, null), " from SraredPreferrences at pos.: "+i );
}
}
//Initializing listView
final StableArrayAdapter adapter = new StableArrayAdapter(getActivity(),android.R.layout.simple_list_item_1, serverList);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
#Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
final String item = (String) parent.getItemAtPosition(position);
view.animate().setDuration(2000).alpha(0).withEndAction(new Runnable() {
#Override
public void run() {
serverList.remove(item);
adapter.notifyDataSetChanged();
view.setAlpha(1);
}
});
}
});
}
Some class:
async_cient = new AsyncTask<Void, Void, Void>() {
...
protected void onPostExecute(Void result) {
Toast.makeText(mContext, "Scan Finished", Toast.LENGTH_SHORT).show();
Main_Fragment cList = new Main_Fragment();
cList.createList();
super.onPostExecute(result);
}
};
Log:
07-29 14:42:46.428 3382-3382/de.liquidbeam.LED.control D/AndroidRuntime﹕ Shutting down VM
07-29 14:42:46.428 3382-3382/de.liquidbeam.LED.control W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41549ba8)
07-29 14:42:46.438 3382-3382/de.liquidbeam.LED.control E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: de.liquidbeam.LED.control, PID: 3382
java.lang.NullPointerException
at de.liquidbeam.LED.control.fragments.Main_Fragment.createList(Main_Fragment.java:56)
at de.liquidbeam.LED.control.background.UDP_Discover$1.onPostExecute(UDP_Discover.java:94)
at de.liquidbeam.LED.control.background.UDP_Discover$1.onPostExecute(UDP_Discover.java:57)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
07-29 14:47:46.591 3382-3382/de.liquidbeam.LED.control I/Process﹕ Sending signal. PID: 3382 SIG: 9
Lines:
56 : SharedPreferences settings = getActivity().getSharedPreferences("Found_Devices", 0);
94 : cList.createList();
57: async_cient = new AsyncTask<Void, Void, Void>() {
You creating a new instance of your fragment with no context (activity) to run in. So
the line
SharedPreferences settings = getActivity().getSharedPreferences("Found_Devices", 0);
Tries to get his activity but there is no activity where the fragment lives in ;)