There are many Questions related to my problem but none of them actually solved my problem. I tried almost all of them.
I'm trying to change values in layout after getting data from network source, but i'm getting nullpointerexception everytime.
Error I'm getting
03-25 18:05:43.071: E/AndroidRuntime(4832): FATAL EXCEPTION: main
03-25 18:05:43.071: E/AndroidRuntime(4832): java.lang.NullPointerException
03-25 18:05:43.071: E/AndroidRuntime(4832): at com.wishberg.app.CommunityPageActivity$SendRequest.onPostExecute(CommunityPageActivity.java:158)
03-25 18:05:43.071: E/AndroidRuntime(4832): at com.wishberg.app.CommunityPageActivity$SendRequest.onPostExecute(CommunityPageActivity.java:1)
03-25 18:05:43.071: E/AndroidRuntime(4832): at android.os.AsyncTask.finish(AsyncTask.java:631)
03-25 18:05:43.071: E/AndroidRuntime(4832): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-25 18:05:43.071: E/AndroidRuntime(4832): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
03-25 18:05:43.071: E/AndroidRuntime(4832): at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 18:05:43.071: E/AndroidRuntime(4832): at android.os.Looper.loop(Looper.java:137)
03-25 18:05:43.071: E/AndroidRuntime(4832): at android.app.ActivityThread.main(ActivityThread.java:5103)
03-25 18:05:43.071: E/AndroidRuntime(4832): at java.lang.reflect.Method.invokeNative(Native Method)
03-25 18:05:43.071: E/AndroidRuntime(4832): at java.lang.reflect.Method.invoke(Method.java:525)
03-25 18:05:43.071: E/AndroidRuntime(4832): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-25 18:05:43.071: E/AndroidRuntime(4832): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-25 18:05:43.071: E/AndroidRuntime(4832): at dalvik.system.NativeStart.main(Native Method)
Here is my activity class
public class CommunityPageActivity extends Activity {
public String wishid = null;
private Context context = null;
public String TAG = "communitypage";
private String cachedName = "community";
private static final int URL_LOADER = 0;
private Menu optionsMenu;
private ProgressDialog progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent i = getIntent();
wishid = i.getStringExtra("id");
context = getApplicationContext();
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
Common.setRefreshActionButtonState(true, optionsMenu);
progress = new ProgressDialog(this);
progress.setMessage("Loading...");
progress.setIndeterminate(true);
progress.show();
setContentView(R.layout.community);
}
private class SendRequest extends AsyncTask<String, Integer, String> {
// http://www.mysamplecode.com/2012/11/android-progress-bar-example.html
ViewHolder holder = null;
protected String doInBackground(String... requestURL) {
String data = "";
HttpURLConnection httpUrlConnection = null;
try {
data = Common.readStream(in);
} catch (MalformedURLException exception) {
Log.e(TAG, "MalformedURLException");
} catch (IOException exception) {
Log.e(TAG, "IOException");
} finally {
if (null != httpUrlConnection)
httpUrlConnection.disconnect();
}
return data;
}
protected void onPostExecute(String jsonString) {
progress.dismiss();
System.out.println(jsonString);
JSONArray jsonArray = Common.getArrayFromJsonString(jsonString, 0);
Inflater inflater;
// View v = inflater.inflate(R.layout.community);
holder.txtWishName = (TextView) CommunityPageActivity.this.findViewById(R.id.tv_communitywishname);
System.out.println(holder);
System.out.println(jsonArray);
}
/* private view holder class */
private class ViewHolder {
ImageView imageView;
TextView txtWishName;
ImageButton btn_touchwood;
ImageButton btn_addwish;
TextView tvGesture;
TextView tvNotes;
}
}
}