This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
I am trying to create a fill in the blanks game. I have given the options to choose from in a spinner dropdown (10 spinner for 10 blanks). Till now its working. But to calculate score, I want to store the selected options in a string array. Here I am getting a NullPointerException.
package com.example.harimohan.myapplication;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class StartPage extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
TextView substring1;
TextView substring2;
TextView substring3;
TextView substring4;
TextView substring5;
TextView substring6;
TextView substring7;
TextView substring8;
TextView substring9;
TextView substring10;
TextView substring11;
Spinner blank1 ;
Spinner blank2 ;
Spinner blank3 ;
Spinner blank4 ;
Spinner blank5 ;
Spinner blank6 ;
Spinner blank7 ;
Spinner blank8 ;
Spinner blank9 ;
Spinner blank10;
String[] subs = new String[20] ;
String[] words = "batsmen domestically scored ranked appearances previously outstanding announced recipient aviation".split(" ");
String[] ans = new String[10];
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start_page);
blank1 = (Spinner) findViewById(R.id.Blank1);
Spinner blank2 = (Spinner) findViewById(R.id.Blank2);
Spinner blank3 = (Spinner) findViewById(R.id.Blank3);
Spinner blank4 = (Spinner) findViewById(R.id.Blank4);
Spinner blank5 = (Spinner) findViewById(R.id.Blank5);
Spinner blank6 = (Spinner) findViewById(R.id.Blank6);
Spinner blank7 = (Spinner) findViewById(R.id.Blank7);
Spinner blank8 = (Spinner) findViewById(R.id.Blank8);
Spinner blank9 = (Spinner) findViewById(R.id.Blank9);
Spinner blank10 = (Spinner) findViewById(R.id.Blank10);
blank1.setOnItemSelectedListener(this );
blank2.setOnItemSelectedListener( this);
blank3.setOnItemSelectedListener( this);
blank4.setOnItemSelectedListener( this);
blank5.setOnItemSelectedListener( this);
blank6.setOnItemSelectedListener( this);
blank7.setOnItemSelectedListener( this);
blank8.setOnItemSelectedListener( this);
blank9.setOnItemSelectedListener( this);
blank10.setOnItemSelectedListener( this);
substring1 = (TextView) findViewById(R.id.subs1);
substring2 = (TextView) findViewById(R.id.subs2);
substring3 = (TextView) findViewById(R.id.subs3);
substring4 = (TextView) findViewById(R.id.subs4);
substring5 = (TextView) findViewById(R.id.subs5);
substring6 = (TextView) findViewById(R.id.subs6);
substring7 = (TextView) findViewById(R.id.subs7);
substring8 = (TextView) findViewById(R.id.subs8);
substring9 = (TextView) findViewById(R.id.subs9);
substring10= (TextView) findViewById(R.id.subs10);
substring11= (TextView) findViewById(R.id.subs11);
new jsontask(). execute("https://en.wikipedia.org/w/api.php?action=query&prop=extracts&explaintext=&titles=Sachin_Tendulkar&formatversion=2&format=json");
List<String> categories = new ArrayList<String>();
categories.add("Select Answer");
categories.add(words[8]);
categories.add(words[1]);
categories.add(words[4]);
categories.add(words[3]);
categories.add(words[7]);
categories.add(words[5]);
categories.add(words[6]);
categories.add(words[0]);
categories.add(words[2]);
categories.add(words[9]);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
blank1.setAdapter(dataAdapter);
blank2.setAdapter(dataAdapter);
blank3.setAdapter(dataAdapter);
blank4.setAdapter(dataAdapter);
blank5.setAdapter(dataAdapter);
blank6.setAdapter(dataAdapter);
blank7.setAdapter(dataAdapter);
blank8.setAdapter(dataAdapter);
blank9.setAdapter(dataAdapter);
blank10.setAdapter(dataAdapter);
/*ans[0] = blank1.getSelectedItem().toString();
ans[1] = blank2.getSelectedItem().toString();
ans[2] = blank3.getSelectedItem().toString();
ans[3]= blank4.getSelectedItem().toString();
ans[4] = blank5.getSelectedItem().toString();
ans[5] = blank6.getSelectedItem().toString();
ans[6] = blank7.getSelectedItem().toString();
ans[7] = blank8.getSelectedItem().toString();
ans[8] = blank9.getSelectedItem().toString();
ans[9] = blank10.getSelectedItem().toString();*/
}
public int Score( String[] WordString, String[] AnsString){
for (int j=0;j<AnsString.length;j++) {
Log.d("Ans: " ,j +" : "+ AnsString[j]);
}
int scores=0;
for (int i=0;i<WordString.length;i++){
if (WordString[i].contains(AnsString[i])) {
scores++;
}
}
Log.d("scores",Integer.toString(scores));
return scores;
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// On selecting a spinner item
String item = parent.getItemAtPosition(position).toString();
try{
Spinner spinner = (Spinner) parent;
Log.d("spinner=",Integer.toString(spinner.getId()));
Log.d("R.id.Blank1=",Integer.toString(R.id.Blank1));
Log.d("Blank1 value=",blank1.getSelectedItem().toString());
/*if(spinner.getId() == R.id.Blank1)
{*/
String ans = blank1.getSelectedItem().toString();
Log.d("ans0 ",ans);
/*}
else if(spinner.getId() == R.id.Blank2)
{
ans[1] = blank2.getSelectedItem().toString();
Log.d("ans1 ",ans[1]);
}*/
}catch (Exception exception)
{
exception.printStackTrace();
}
// Showing selected spinner item
Toast.makeText(parent.getContext(), "Selected: " + item +" at "+position+""+id, Toast.LENGTH_LONG).show();
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
public class jsontask extends AsyncTask<String, String, String[]> {
#Override
protected String[] doInBackground(String... params) {
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line ;
while ((line=reader.readLine())!= null) {
buffer.append(line);
}
String json = buffer.toString();
JSONObject parentObj = new JSONObject(json);
JSONObject query = parentObj.getJSONObject("query");
JSONArray pages = query.getJSONArray("pages");
JSONObject pagearray = pages.getJSONObject(0);
String extract = pagearray.getString("extract");
int lines = 0;
int pos = 0;
String print = null;
int x;
while ((pos = extract.indexOf(".", pos) + 1) != 0) {
lines++;
if(lines==10){
x= extract.indexOf("\n",pos);
print = extract.substring(0,x);
break;
}
}
String[] sentence = print.split(" ");
for (int j = 0 ; j < words.length;j++){
boolean flag= false;
for (int i = 0; i < sentence.length ; i++) {
if (sentence[i].equals(words[j])) {
/* System.out.println(words[j]+" is found at "+ i);
System.out.println("size of "+words[j]+"="+words[j].length());
*/
if (j==0){
System.out.println("end "+print.indexOf(words[j]));
System.out.println(print.substring(0,i));
subs[j]= print.substring(0,print.indexOf(words[j]));
System.out.println(print.indexOf(words[j]));
}
else{
int start = print.indexOf(words[j-1])+ words[j-1].length();
/*System.out.println(print.indexOf(words[j-1])+"+" +words[j-1].length());
System.out.println("start"+start);
System.out.println("end"+print.indexOf(words[j]));*/
subs[j]= print.substring(start,print.indexOf(words[j]));
if(j==9){
int n =print.indexOf(words[j])+ words[j].length();
subs[10]=print.substring(n);
}
}
flag= true;
break;
}
}
if (!flag ){
System.out.println("doesnt found");
}
}
return subs;
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e3) {
e3.printStackTrace();
}
}
return null;
}
#Override
protected void onPostExecute(String[] result) {
super.onPostExecute(result);
substring1.setText(subs[0]);
substring2.setText(subs[1]);
substring3.setText(subs[2]);
substring4.setText(subs[3]);
substring5.setText(subs[4]);
substring6.setText(subs[5]);
substring7.setText(subs[6]);
substring8.setText(subs[7]);
substring9.setText(subs[8]);
substring10.setText(subs[9]);
substring11.setText(subs[10]);
}
}
public void gotoScorePage(View view){
Score(words,ans);
Intent nextPage=new Intent(StartPage.this,ScorePage.class);
nextPage.putExtra("Score",Score(words,ans));
startActivity(nextPage);
}
}
This is logcat
07-13 12:33:18.360 19760-19760/com.example.harimohan.myapplication D/dalvikvm: VFY: replacing opcode 0x20 at 0x0016
07-13 12:33:18.810 19760-19760/com.example.harimohan.myapplication D/spinner=: 2131492976
07-13 12:33:18.810 19760-19760/com.example.harimohan.myapplication D/R.id.Blank1=: 2131492976
07-13 12:33:18.810 19760-19760/com.example.harimohan.myapplication W/System.err: java.lang.NullPointerException
07-13 12:33:18.810 19760-19760/com.example.harimohan.myapplication W/System.err: at com.example.harimohan.myapplication.StartPage.onItemSelected(StartPage.java:174)
07-13 12:33:18.810 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.fireOnSelected(AdapterView.java:893)
07-13 12:33:18.820 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.access$200(AdapterView.java:48)
07-13 12:33:18.820 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:861)
07-13 12:33:18.820 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
07-13 12:33:18.820 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
07-13 12:33:18.830 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Looper.loop(Looper.java:136)
07-13 12:33:18.830 19760-19760/com.example.harimohan.myapplication W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017)
07-13 12:33:18.830 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
07-13 12:33:18.830 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
07-13 12:33:18.830 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-13 12:33:18.830 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-13 12:33:18.830 19760-19760/com.example.harimohan.myapplication W/System.err: at dalvik.system.NativeStart.main(Native Method)
07-13 12:33:18.840 19760-19760/com.example.harimohan.myapplication D/spinner=: 2131492978
07-13 12:33:18.840 19760-19760/com.example.harimohan.myapplication D/R.id.Blank1=: 2131492976
07-13 12:33:18.850 19760-19760/com.example.harimohan.myapplication W/System.err: java.lang.NullPointerException
07-13 12:33:18.850 19760-19760/com.example.harimohan.myapplication W/System.err: at com.example.harimohan.myapplication.StartPage.onItemSelected(StartPage.java:174)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.fireOnSelected(AdapterView.java:893)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.access$200(AdapterView.java:48)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:861)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Looper.loop(Looper.java:136)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at dalvik.system.NativeStart.main(Native Method)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication D/spinner=: 2131492980
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication D/R.id.Blank1=: 2131492976
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: java.lang.NullPointerException
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at com.example.harimohan.myapplication.StartPage.onItemSelected(StartPage.java:174)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.fireOnSelected(AdapterView.java:893)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.access$200(AdapterView.java:48)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:861)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Looper.loop(Looper.java:136)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-13 12:33:18.860 19760-19760/com.example.harimohan.myapplication W/System.err: at dalvik.system.NativeStart.main(Native Method)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication D/spinner=: 2131492982
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication D/R.id.Blank1=: 2131492976
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: java.lang.NullPointerException
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at com.example.harimohan.myapplication.StartPage.onItemSelected(StartPage.java:174)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.fireOnSelected(AdapterView.java:893)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.access$200(AdapterView.java:48)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:861)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Looper.loop(Looper.java:136)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-13 12:33:18.880 19760-19760/com.example.harimohan.myapplication W/System.err: at dalvik.system.NativeStart.main(Native Method)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication D/spinner=: 2131492984
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication D/R.id.Blank1=: 2131492976
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: java.lang.NullPointerException
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at com.example.harimohan.myapplication.StartPage.onItemSelected(StartPage.java:174)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.fireOnSelected(AdapterView.java:893)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.access$200(AdapterView.java:48)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:861)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Looper.loop(Looper.java:136)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at dalvik.system.NativeStart.main(Native Method)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication D/spinner=: 2131492986
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication D/R.id.Blank1=: 2131492976
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: java.lang.NullPointerException
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at com.example.harimohan.myapplication.StartPage.onItemSelected(StartPage.java:174)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.fireOnSelected(AdapterView.java:893)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.access$200(AdapterView.java:48)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:861)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
07-13 12:33:18.890 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Looper.loop(Looper.java:136)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at dalvik.system.NativeStart.main(Native Method)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication D/spinner=: 2131492988
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication D/R.id.Blank1=: 2131492976
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: java.lang.NullPointerException
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at com.example.harimohan.myapplication.StartPage.onItemSelected(StartPage.java:174)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.fireOnSelected(AdapterView.java:893)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView.access$200(AdapterView.java:48)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:861)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at android.os.Looper.loop(Looper.java:136)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-13 12:33:18.900 19760-19760/com.example.harimohan.myapplication
there is :
at com.example.harimohan.myapplication.StartPage.onItemSelected(StartPage.java:174)
in line 174 you have choose and null value
maybe you should initilize blank1 in on create method .
You can try to check the where the null is in line 174 (the blank1.getSelectedItem() return the null value). It's helpful for you to solve the problem . Please forgive my English is poor.
I am developing a gridview to display JSON images. I am entering ImageAdapter, but I am not receiving images in the screen indicating that something incorrect occurred while getting the associated view. Is MyArrList null?
I realize that there are other posts similar to my own out there, but I have done deep research into them and cannot find a solution.
Logcat:
V/log﹕ getcount
08-04 11:02:33.044 22241-22241/com.example.justin.myapplication V/log﹕ getcount
08-04 11:02:33.060 22241-22241/com.example.justin.myapplication V/log﹕ getcount
08-04 11:02:33.060 22241-22241/com.example.justin.myapplication V/log﹕ getcount
08-04 11:02:33.060 22241-22241/com.example.justin.myapplication V/log﹕ getcount
08-04 11:02:33.060 22241-22241/com.example.justin.myapplication V/log﹕ getcount
08-04 11:02:33.169 22241-22241/com.example.justin.myapplication V/log﹕ getcount
08-04 11:02:33.169 22241-22241/com.example.justin.myapplication V/log﹕ getcount
08-04 11:02:33.177 22241-22241/com.example.justin.myapplication V/log﹕ getcount
08-04 11:02:33.177 22241-22241/com.example.justin.myapplication V/log﹕ getcount
08-04 09:12:44.179 6312-6315/com.example.justin.myapplication D/dalvikvm﹕ GC_CONCURRENT freed 177K, 3% free 8929K/9148K, paused 5ms+2ms, total 37ms
08-04 09:12:44.179 6312-6352/com.example.justin.myapplication D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 17ms
08-04 09:12:44.203 6312-6352/com.example.justin.myapplication D/dalvikvm﹕ GC_FOR_ALLOC freed 285K, 6% free 8941K/9452K, paused 20ms, total 20ms
08-04 09:12:44.289 6312-6315/com.example.justin.myapplication D/dalvikvm﹕ GC_CONCURRENT freed 241K, 3% free 9198K/9464K, paused 1ms+5ms, total 24ms
08-04 09:12:44.359 6312-6352/com.example.justin.myapplication D/dalvikvm﹕ GC_FOR_ALLOC freed 288K, 5% free 9159K/9612K, paused 13ms, total 13ms
08-04 09:12:44.359 6312-6352/com.example.justin.myapplication I/dalvikvm-heap﹕ Grow heap (frag case) to 9.093MB for 130826-byte allocation
08-04 09:12:44.375 6312-6321/com.example.justin.myapplication D/dalvikvm﹕ GC_FOR_ALLOC freed 85K, 6% free 9202K/9740K, paused 14ms, total 14ms
08-04 09:12:44.375 6312-6352/com.example.justin.myapplication V/data﹕ {"car_images":[{"CarManufacturerImage":"bmw.png","...}
08-04 09:12:45.875 6312-6315/com.example.justin.myapplication D/dalvikvm﹕ GC_CONCURRENT freed 269K, 5% free 9299K/9740K, paused 2ms+3ms, total 23ms
08-04 09:12:46.047 6312-6352/com.example.justin.myapplication V/Bitmap﹕ CarImageLink
08-04 09:12:46.047 6312-6352/com.example.justin.myapplication V/MyArrList﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b5b7d8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34d28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5eb98}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3c7e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c828}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb96a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54f48}]
08-04 09:12:46.054 6312-6352/com.example.justin.myapplication V/return0﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b5b7d8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34d28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5eb98}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3c7e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c828}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb96a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54f48}]
08-04 09:12:46.054 6312-6352/com.example.justin.myapplication V/getJSONObject(i)﹕ {"CarManufacturerImage":"bmw.png",....}
08-04 09:12:46.265 6312-6352/com.example.justin.myapplication V/Bitmap﹕ CarImageLink
08-04 09:12:46.265 6312-6352/com.example.justin.myapplication V/MyArrList﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b5b7d8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34d28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5eb98}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3c7e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c828}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb96a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54f48}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b86380}]
08-04 09:12:46.273 6312-6352/com.example.justin.myapplication V/return0﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b5b7d8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34d28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5eb98}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3c7e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c828}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb96a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54f48}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b86380}]
08-04 09:12:46.273 6312-6352/com.example.justin.myapplication V/getJSONObject(i)﹕ {"CarManufacturerImage":"bmw.png",....}
08-04 09:12:46.468 6312-6352/com.example.justin.myapplication V/Bitmap﹕ CarImageLink
08-04 09:12:46.468 6312-6352/com.example.justin.myapplication V/MyArrList﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b5b7d8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34d28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5eb98}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3c7e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c828}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb96a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54f48}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b86380}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c420}]
08-04 09:12:46.468 6312-6352/com.example.justin.myapplication V/return0﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b5b7d8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34d28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5eb98}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3c7e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c828}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb96a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54f48}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b86380}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c420}]
08-04 09:12:46.476 6312-6352/com.example.justin.myapplication V/getJSONObject(i)﹕ {"CarManufacturerImage":"bmw.png",....}
08-04 09:12:46.679 6312-6352/com.example.justin.myapplication V/Bitmap﹕ CarImageLink
08-04 09:12:46.687 6312-6352/com.example.justin.myapplication V/MyArrList﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b5b7d8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34d28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5eb98}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3c7e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c828}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb96a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54f48}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b86380}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c420}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bdedf8}]
08-04 09:12:46.695 6312-6352/com.example.justin.myapplication V/return0﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b5b7d8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34d28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5eb98}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3c7e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c828}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb96a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54f48}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b86380}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c420}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bdedf8}]
08-04 09:12:46.695 6312-6352/com.example.justin.myapplication V/getJSONObject(i)﹕ {"CarManufacturerImage":"bmw.png",....}
08-04 09:12:46.711 6312-6315/com.example.justin.myapplication D/dalvikvm﹕ GC_CONCURRENT freed 315K, 4% free 9420K/9812K, paused 7ms+2ms, total 31ms
08-04 09:12:46.906 6312-6352/com.example.justin.myapplication V/Bitmap﹕ CarImageLink
08-04 09:12:46.906 6312-6352/com.example.justin.myapplication V/MyArrList﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b5b7d8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34d28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5eb98}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3c7e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c828}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb96a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54f48}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b86380}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c420}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bdedf8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b50150}]
08-04 09:12:46.914 6312-6352/com.example.justin.myapplication V/return0﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b5b7d8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34d28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5eb98}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3c7e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c828}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb96a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54f48}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b86380}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c420}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bdedf8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b50150}]
08-04 09:12:46.914 6312-6352/com.example.justin.myapplication V/getJSONObject(i)﹕ {"CarManufacturerImage":"bmw.png",....}
08-04 09:12:47.117 6312-6352/com.example.justin.myapplication V/Bitmap﹕ CarImageLink
08-04 09:12:47.117 6312-6352/com.example.justin.myapplication V/MyArrList﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b5b7d8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34d28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5eb98}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3c7e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c828}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb96a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54f48}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b86380}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9c420}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bdedf8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b50150}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41baa090}]
08-04 11:02:37.255 22241-22279/com.example.justin.myapplication V/return0﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41b86600}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b34e38}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba3c28}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b59b68}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b0b0f8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b9bee0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb94a8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b54d10}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b37458}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b411b8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bdec58}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b4ff18}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bc37c8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bcfbd8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41c05140}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b19c30}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bf4ce0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bcf7a0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b4b120}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b2d638}]
08-04 11:34:59.794 4563-4563/com.example.justin.myapplication V/return3﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41ace870}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b35768}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba4298}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b72cd0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3d2e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b842e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb99c0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b642e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ad6a60}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b8b8c0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bdf338}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5f4f0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bc3608}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba9308}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41be9138}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b4bcb0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bab378}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb0408}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5a6f8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bec410}]
08-04 11:34:59.794 4563-4563/com.example.justin.myapplication V/value﹕ value
08-04 11:34:59.794 4563-4563/com.example.justin.myapplication V/value1﹕ value1
08-04 11:34:59.794 4563-4563/com.example.justin.myapplication V/log﹕ getcount
08-04 11:34:59.794 4563-4563/com.example.justin.myapplication V/log﹕ getcount
08-04 11:34:59.794 4563-4563/com.example.justin.myapplication V/return2﹕ com.example.justin.myapplication.JSONImageViewer$ImageAdapter#41afd290
08-04 11:34:59.794 4563-4563/com.example.justin.myapplication V/return2.1﹕ [{CarImageLink=android.graphics.drawable.BitmapDrawable#41ace870}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b35768}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba4298}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b72cd0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b3d2e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b842e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb99c0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b642e8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ad6a60}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b8b8c0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bdf338}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5f4f0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bc3608}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41ba9308}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41be9138}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b4bcb0}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bab378}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bb0408}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41b5a6f8}, {CarImageLink=android.graphics.drawable.BitmapDrawable#41bec410}]
08-04 11:34:59.810 4563-4563/com.example.justin.myapplication V/log﹕ getcount
08-04 11:34:59.810 4563-4563/com.example.justin.myapplication V/v﹕ convertView inflating
08-04 11:34:59.810 4563-4563/com.example.justin.myapplication V/convertview﹕ android.widget.RelativeLayout{41baedb8 V.E..... ......I. 0,0-0,0}
08-04 11:34:59.810 4563-4563/com.example.justin.myapplication D/AndroidRuntime﹕ Shutting down VM
08-04 11:34:59.810 4563-4563/com.example.justin.myapplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41266930)
08-04 11:34:59.825 4563-4563/com.example.justin.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.example.justin.myapplication.JSONImageViewer$ImageAdapter.getView(JSONImageViewer.java:238)
at android.widget.AbsListView.obtainView(AbsListView.java:2159)
at android.widget.GridView.onMeasure(GridView.java:1040)
at android.view.View.measure(View.java:15518)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:15518)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:15518)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15518)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:15518)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
at android.view.View.measure(View.java:15518)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
08-04 11:34:59.856 4563-4567/com.example.justin.myapplication D/dalvikvm﹕ GC_CONCURRENT freed 650K, 8% free 9424K/10140K, paused 2ms+3ms, total 32ms
Activity_column.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/ColPhoto"
android:layout_width="50dp"
android:layout_height="50dp"
/>
</RelativeLayout>
Any suggestions/insight as to why I cannot receive images through getView() yet can get values for getCount() are appreciated. Thank you.
In your onCreate() method change getApplicationContext() to this in the line where you're creating adapter and remove notifyDataSetChanged().
And remove MyArrList duplicate from doInBackground()
Try to change your task as follows:
class LoadContentFromServer extends AsyncTask<Object, Integer, Object> {
#Override
protected Object doInBackground(Object... params) {
String url = "http://..no looking..";
JSONObject data;
try {
data = new JSONObject(getJSONUrl(url));
Log.v("data", data.toString());
JSONArray dataArray = data.getJSONArray("car_images");
/*
* TotalRows = Show for total rows
* TotalPage = Show for total page
*/
int displayPerPage = 9; // Per Page
int TotalRows = data.length();
int indexRowStart = ((displayPerPage * currentPage) - displayPerPage);
if (TotalRows <= displayPerPage) {
TotalPage = 1;
} else if ((TotalRows % displayPerPage) == 0) {
TotalPage = (TotalRows / displayPerPage);
} else {
TotalPage = (TotalRows / displayPerPage) + 1;
TotalPage = (int) TotalPage;
}
int indexRowEnd = displayPerPage * currentPage;
if (indexRowEnd > TotalRows) {
indexRowEnd = TotalRows;
}
for (int i = 0; i < dataArray.length(); i++) {
//HashMap<String, Object> map = new HashMap<String, Object>();
JSONObject c = dataArray.getJSONObject(i);
Log.v("getJSONObject(i)", dataArray.getJSONObject(i).toString());
// Thumbnail Get ImageBitmap To Object
HashMap<String, Object> map = new HashMap<String, Object>();
Bitmap bitmap = loadBitmap(c.getString(TAG_IMG));
Drawable d = new BitmapDrawable(getResources(), bitmap);
map.put(TAG_IMG, d);
Log.v("Bitmap", TAG_IMG);
MyArrList.add(map);
Log.v("MyArrList", MyArrList.toString());
Log.v("return0", MyArrList.toString());
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Object result) {
Log.v("return3", MyArrList.toString());
// Disabled Button Next
if(currentPage >= TotalPage) {
btnNext.setEnabled(false);
}
else {
btnNext.setEnabled(true);
}
// Disabled Button Previous
if(currentPage <= 1) {
btnPre.setEnabled(false);
}
else {
btnPre.setEnabled(true);
}
setProgressBarIndeterminateVisibility(false);
imageAdapter.addAll(MyArrList);
imageAdapter.notifyDataSetChanged();
Log.v("return2", imageAdapter.toString());
Log.v("return2.1", MyArrList.toString());
}
}
and adapter:
class ImageAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<HashMap<String, Object>> array;
public ImageAdapter(Context context) {
mContext = context;
array = new ArrayList<>();
}
#Override
public int getCount() {
Log.v("log", "getcount");
return array.size();
}
public Object getItem(int position) {
return array.get(position);
}
public long getItemId(int position) {
return position;
}
public void addAll(ArrayList<HashMap<String, Object>> list) {
array.clear();
array.addAll(list);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//If convertView is null create a new view, else use convert view
if(convertView==null) {
Log.v("v", "convertView inflating");
convertView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate
(R.layout.activity_column, null);
}
Log.v("convertview", convertView.toString());
ImageView iv = (ImageView) convertView.findViewById(R.id.ColPhoto);
iv.setImageBitmap((Bitmap) array.get(position).get(TAG_IMG));
iv.setVisibility(ImageView.VISIBLE);
return v;
}
}
You need to call
protected String onPostExecute()
{
// change your data set here then call
imageAdapter.notifyDataSetChanged();
}
in onPostExecute() not in OnProgressUpdated() also you must call it when after you have modified the data set
EDIT
onProgressUpdate is normally for updating the ui (ie an progress bar). it will get called every time you call
protected String doInBackground()
{
// other code ommited
String progress = "test";
publishProgress(progress);
}
which you are not doing hence it will never update the data set.
try moving your code from the OnProgressUpdated to onPostExecute();
I have called a function returnCurrentNameById() by passing the id of the particular row. But it gives an error.
String[] s1;
public String[] returnCurrentNameById(int k) throws SQLException{
String[] columns = new String[]{ KEY_ID1, KEY_NAME, Key_DOB, KEY_AGE, KEY_PHONE_NO, Key_EXPERIENCE, KEY_EMAIL, KEY_STATUS, KEY_STATUS};
SQLiteDatabase db3 = this.getReadableDatabase();
Cursor c = db3.query(DATA_BASE_TABLE_NAME1, columns, KEY_ID1 + "=" + k, null, null, null, null);
if (c != null){
c.moveToFirst();
for(int i = 0; i<=8; i++){
s1[i] = c.getString(i);
}
return s1;
}
return null;
}
The Log cat error report is:
02-15 16:38:13.424 1545-1545/world.com.my`enter code here`progect09 D/AndroidRuntime﹕ Shutting down VM
02-15 16:38:13.464 1545-1545/world.com.myprogect09 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x2bc9a300)
02-15 16:38:13.533 1545-1545/world.com.myprogect09 E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3591)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3586)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at world.com.myprogect09.DataBaseSQL.returnCurrentNameById1(DataBaseSQL.java:209)
at world.com.myprogect09.ThirdActivity.isClicked(ThirdActivity.java:74)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3586)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
02-15 16:38:34.491 1545-1545/world.com.myprogect09 I/Process﹕ Sending signal. PID: 1545 SIG: 9
You have not initialized your s1 array.
Use
s1 = new String[9];
to allocate an array of 9 elements.
Also check the return value of moveToFirst() so you don't get an exception in case the query returns no rows.
Replace
Cursor c = db3.query(DATA_BASE_TABLE_NAME1, columns, KEY_ID1 + "=" + k, null, null, null, null);
with
Cursor c = db3.query(DATA_BASE_TABLE_NAME1, columns, KEY_ID1 + " = ?", new String[]{String.valueOf(k)}, null, null, null);
In my current android project I create two bitmaps from xml resources. Every time I build my project using the xml bitmaps as the resource for Bitmap.decodeResources() I get a null pointer exception when I try to access the bitmaps. But when I switch to using the straight .png the error goes away.
Why is decodeResources() returning null?
code where the bitmaps are created:
public OvertButton(float x, float y, float width, float height, int pressedId, int unPressedId, Resources res, boolean visible) {
\\these are null if xml bitmap is passed
pressed = BitmapFactory.decodeResource(res, pressedId);
unPressed = BitmapFactory.decodeResource(res, unPressedId);
this.visible = visible;
relocate(x, y);
resize(width, height); //throws NPE when I createScaledBitmap()
ClickableManager.registerClickable(this);
}
resource file
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/play_button_pressed"
android:filter="false"
android:antialias="false"
android:dither="false"/>
and the resize method
#Override
public void resize(float width, float height) {
box.set(box.left, box.top, box.left + width, box.top + height);
Log.d("resize",String.valueOf(height));
pressed = Bitmap.createScaledBitmap(pressed, (int)width, (int)height, true);
unPressed = Bitmap.createScaledBitmap(unPressed, (int)width, (int)height, true);
}
And the logcat
04-16 09:45:06.341 11824-11824/com.handmade.eed D/dalvikvm﹕ Late-enabling CheckJNI
04-16 09:45:06.450 11824-11824/com.handmade.eed D/MenuActivity﹕ 2130837594$$$2130837596
04-16 09:45:06.451 11824-11824/com.handmade.eed D/skia﹕ --- SkImageDecoder::Factory returned null
04-16 09:45:06.451 11824-11824/com.handmade.eed D/OvertButton﹕ true2130837591
04-16 09:45:06.457 11824-11824/com.handmade.eed D/OvertButton﹕ false2130837595
04-16 09:45:06.457 11824-11824/com.handmade.eed D/resize﹕ 252.0
04-16 09:45:06.458 11824-11824/com.handmade.eed D/AndroidRuntime﹕ Shutting down VM
04-16 09:45:06.459 11824-11824/com.handmade.eed W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41610d40)
04-16 09:45:06.461 11824-11824/com.handmade.eed E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.handmade.eed, PID: 11824
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.handmade.eed/com.handmade.eed.MenuActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
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)
Caused by: java.lang.NullPointerException
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:615)
at com.handmade.overt.visible.OvertButton.resize(OvertButton.java:61)
at com.handmade.overt.visible.OvertButton.<init>(OvertButton.java:29)
at com.handmade.overt.visible.OvertButton.<init>(OvertButton.java:34)
at com.handmade.eed.MenuActivity.onCreate(MenuActivity.java:72)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
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)
04-16 09:45:09.872 11824-11824/com.handmade.eed I/Process﹕ Sending signal. PID: 11824 SIG: 9
This is a case of me being dumb but here is the answer for posterity.
Bitmap is not the same as BitmapDrawable
From the Drawable Resources link above:
COMPILED RESOURCE DATATYPE:
Resource pointer to a BitmapDrawable.
Thus I had to change this:
Bitmap pressed = BitmapFactory.decodeResource(res, R.drawable.play_button_pressed_res); //this is the id for the xml referring to the png
to either this:
Drawable pressed = res.getDrawable(R.drawable.play_button_pressed_res);
or this:
Bitmap pressed = BitmapFactory.decodeResource(res, R.drawable.play_button_pressed); //this is the id for the png
I decided to use bitmap because, as I understand, it is faster.