Having serious problems with a lab and I am not the only one. I have my emulator running fine with all Facebook example apps. FacebookSDK and HelloFacebookSample project all work fine. It is something in the code that is incorrect. All xml, and manifest coding is correct. I am sure it is something in the Java code. It compiles, it prompts a Log-In then it asks about permissions, then it crashes.
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.facebook.HttpMethod;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.Session.StatusCallback;
import com.facebook.model.GraphObject;
import com.facebook.SessionState;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
final TextView newsFeedTextView = (TextView) rootView
.findViewById(R.id.newsFeed);
StatusCallback mCallback = new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state,
Exception exception) {
if (session.isOpened()) {
/* make the API call */
new Request(session, "/GmitClubsandsocieties/feed", null,
HttpMethod.GET, new Request.Callback() {
#Override
public void onCompleted(Response response) {
/* check logcat for responce */
System.out.println(response);
newsFeedTextView
.setText(parseDataFromFQLResponse(response));
}
}).executeAsync();
}
}
};
Session.OpenRequest request = new Session.OpenRequest(getActivity());
// request.setPermissions(Arrays.asList("read_stream"));
request.setCallback(mCallback);
// get active session
Session mFacebookSession = Session.getActiveSession();
if (mFacebookSession == null || mFacebookSession.isClosed()) {
mFacebookSession = new Session(getActivity());
}
// mFacebookSession.openForRead(request);
mFacebookSession.openForRead(request);
return rootView;
}
}
private static String parseDataFromFQLResponse(Response response) {
StringBuilder responseText = new StringBuilder(" ");
try {
GraphObject go = response.getGraphObject();
JSONObject jso = go.getInnerJSONObject();
JSONArray arr = jso.getJSONArray( "data" );
for (int i = 0; i < (arr.length()); i++) {
JSONObject json_obj = arr.getJSONObject(i);
responseText.append(String.format("Message: %s\n\n",
json_obj.getString("message")));
}
} catch (Throwable t) {
t.printStackTrace();
}
return responseText.toString();
}
}
This is the logFile:
04-24 09:57:28.453: D/AndroidRuntime(2574): Shutting down VM
04-24 09:57:28.453: W/dalvikvm(2574): threadid=1: thread exiting with uncaught exception (group=0xb2ae0ba8)
04-24 09:57:28.513: E/AndroidRuntime(2574): FATAL EXCEPTION: main
04-24 09:57:28.513: E/AndroidRuntime(2574): Process: ie.gmit.facebooknewsfeed, PID: 2574
04-24 09:57:28.513: E/AndroidRuntime(2574): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=-1, data=Intent { (has extras) }} to activity {ie.gmit.facebooknewsfeed/ie.gmit.facebooknewsfeed.MainActivity}: java.lang.NullPointerException
04-24 09:57:28.513: E/AndroidRuntime(2574): at android.app.ActivityThread.deliverResults(ActivityThread.java:3365)
04-24 09:57:28.513: E/AndroidRuntime(2574): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3408)
04-24 09:57:28.513: E/AndroidRuntime(2574): at android.app.ActivityThread.access$1300(ActivityThread.java:135)
04-24 09:57:28.513: E/AndroidRuntime(2574): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
04-24 09:57:28.513: E/AndroidRuntime(2574): at android.os.Handler.dispatchMessage(Handler.java:102)
04-24 09:57:28.513: E/AndroidRuntime(2574): at android.os.Looper.loop(Looper.java:136)
04-24 09:57:28.513: E/AndroidRuntime(2574): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-24 09:57:28.513: E/AndroidRuntime(2574): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 09:57:28.513: E/AndroidRuntime(2574): at java.lang.reflect.Method.invoke(Method.java:515)
04-24 09:57:28.513: E/AndroidRuntime(2574): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-24 09:57:28.513: E/AndroidRuntime(2574): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-24 09:57:28.513: E/AndroidRuntime(2574): at dalvik.system.NativeStart.main(Native Method)
04-24 09:57:28.513: E/AndroidRuntime(2574): Caused by: java.lang.NullPointerException
04-24 09:57:28.513: E/AndroidRuntime(2574): at ie.gmit.facebooknewsfeed.MainActivity.onActivityResult(MainActivity.java:40)
04-24 09:57:28.513: E/AndroidRuntime(2574): at android.app.Activity.dispatchActivityResult(Activity.java:5423)
04-24 09:57:28.513: E/AndroidRuntime(2574): at android.app.ActivityThread.deliverResults(ActivityThread.java:3361)
04-24 09:57:28.513: E/AndroidRuntime(2574): ... 11 more
04-24 09:57:32.283: I/Process(2574): Sending signal. PID: 2574 SIG: 9
Your data parameter may not be properly populated. In onActivityResult
add the line Bundle bundle = data.getExtras();
Related
I'm studying Android development. I have a problem in LogCat, it seems like it is unable to start settings activity:
05-06 09:40:37.323: E/AndroidRuntime(945): FATAL EXCEPTION: main
05-06 09:40:37.323: E/AndroidRuntime(945): Process: com.androiddevbook.onyourbike_chapter4, PID: 945
05-06 09:40:37.323: E/AndroidRuntime(945): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androiddevbook.onyourbike_chapter4/com.androiddevbook.onyourbike_chapter5.activities.SettingsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
05-06 09:40:37.323: E/AndroidRuntime(945): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
05-06 09:40:37.323: E/AndroidRuntime(945): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
05-06 09:40:37.323: E/AndroidRuntime(945): at android.app.ActivityThread.access$800(ActivityThread.java:144)
05-06 09:40:37.323: E/AndroidRuntime(945): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
05-06 09:40:37.323: E/AndroidRuntime(945): at android.os.Handler.dispatchMessage(Handler.java:102)
05-06 09:40:37.323: E/AndroidRuntime(945): at android.os.Looper.loop(Looper.java:135)
05-06 09:40:37.323: E/AndroidRuntime(945): at android.app.ActivityThread.main(ActivityThread.java:5221)
05-06 09:40:37.323: E/AndroidRuntime(945): at java.lang.reflect.Method.invoke(Native Method)
05-06 09:40:37.323: E/AndroidRuntime(945): at java.lang.reflect.Method.invoke(Method.java:372)
05-06 09:40:37.323: E/AndroidRuntime(945): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
05-06 09:40:37.323: E/AndroidRuntime(945): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
05-06 09:40:37.323: E/AndroidRuntime(945): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
05-06 09:40:37.323: E/AndroidRuntime(945): at com.androiddevbook.onyourbike_chapter5.activities.SettingsActivity.setupActionBar(SettingsActivity.java:48)
05-06 09:40:37.323: E/AndroidRuntime(945): at com.androiddevbook.onyourbike_chapter5.activities.SettingsActivity.onCreate(SettingsActivity.java:40)
05-06 09:40:37.323: E/AndroidRuntime(945): at android.app.Activity.performCreate(Activity.java:5933)
05-06 09:40:37.323: E/AndroidRuntime(945): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
05-06 09:40:37.323: E/AndroidRuntime(945): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
05-06 09:40:37.323: E/AndroidRuntime(945): ... 10 more
Here is class where make intent with function clickedSettings for calling SettingsActivity.class Activity ( in runtime when is clicked Settings on the actionBar on top of the screen) :
package com.androiddevbook.onyourbike_chapter5.activities;
import com.androiddevbook.onyourbike_chapter4.BuildConfig;
import com.androiddevbook.onyourbike_chapter4.R;
import com.androiddevbook.onyourbike_chapter5.model.TimerState;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.os.Vibrator;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TimerActivity extends ActionBarActivity {
private static String CLASS_NAME;
protected TextView counter;
protected Button start;
protected Button stop;
protected Handler handler;
protected UpdateTimer updateTimer;
private static long UPDATE_EVERY = 200;
protected Vibrator vibrate;
protected long lastSeconds;
private TimerState timer;
public TimerActivity(){
CLASS_NAME = getClass().getName();
timer = new TimerState();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timer);
counter = (TextView) findViewById(R.id.timer);
start = (Button) findViewById(R.id.start_button);
stop = (Button) findViewById(R.id.stop_button);
Log.d(CLASS_NAME, "Setting text.");
if (BuildConfig.DEBUG){
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().penaltyDeath().build());
}
timer.reset();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.d(CLASS_NAME, "Showing menu.");
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
Log.d(CLASS_NAME, "SETTINGS PRESSED.");
System.out.println("Settings pressed.");
clickedSettings(null);
return true;
}
return super.onOptionsItemSelected(item);
}
public void clickedStart(View view){
Log.d(CLASS_NAME, "Clicked start button.");
timer.start();
enableButtons();
handler = new Handler();
updateTimer = new UpdateTimer();
handler.postDelayed(updateTimer, UPDATE_EVERY);
}
public void clickedStop(View view){
Log.d(CLASS_NAME, "Clicked stop button.");
timer.stop();
enableButtons();
handler.removeCallbacks(updateTimer);
updateTimer = null;
handler = null;
}
public void enableButtons(){
Log.d(CLASS_NAME, "Set buttons enabled/disabled.");
start.setEnabled(!timer.isRunning());
stop.setEnabled(timer.isRunning());
}
public class UpdateTimer implements Runnable {
public void run(){
Log.d(CLASS_NAME, "run");
setTimeDisplay();
if ( handler != null){
handler.postDelayed(this, UPDATE_EVERY);
}
if ( timer.isRunning() ){
vibrateCheck();
}
}
}
public void onStart(){
super.onStart();
Log.d(CLASS_NAME, "onStart");
if ( timer.isRunning() ){
handler = new Handler();
updateTimer = new UpdateTimer();
handler.postDelayed(updateTimer, UPDATE_EVERY);
}
vibrate = (Vibrator) getSystemService(VIBRATOR_SERVICE);
if (vibrate == null){
Log.w(CLASS_NAME, "No vibrate service exists.");
}
}
public void onPause(){
super.onPause();
Log.d(CLASS_NAME, "onPause");
}
public void onResume(){
super.onResume();
Log.d(CLASS_NAME, "onResume");
}
public void onStop(){
super.onStop();
Log.d(CLASS_NAME, "onSop");
if ( timer.isRunning() ){
handler.removeCallbacks(updateTimer);
handler = null;
updateTimer = null;
}
}
public void onDestroy(){
super.onDestroy();
Log.d(CLASS_NAME, "onDestroy");
}
public void onRestart(){
super.onRestart();
Log.d(CLASS_NAME, "onRestart");
}
protected void vibrateCheck(){
long diff = timer.elapsedTime();
long seconds = diff / 1000;
long minutes = seconds / 60;
seconds = seconds % 60;
minutes = minutes % 60;
Log.d(CLASS_NAME, "vibrateCheck");
if ( vibrate != null && seconds == 0 && seconds != lastSeconds){
long[] once = { 0, 100 };
long[] twice= { 0, 100, 400, 100};
long[] thrice = { 0, 100, 400, 100, 400, 100 };
// every hour
if ( minutes == 0){
Log.d(CLASS_NAME, "Vibrate 3 times");
vibrate.vibrate(thrice, -1);
}
// every 15 minutes
else if ( minutes % 15 == 0 ){
Log.d(CLASS_NAME, "Vibrate 2 times");
vibrate.vibrate(twice, -1);
}
// every 1 minute
else if ( minutes == 1 ){
Log.d(CLASS_NAME, "Vibrate 1 time");
vibrate.vibrate(once, -1);
}
}
lastSeconds = seconds;
}
public void clickedSettings(View view){
Log.d(CLASS_NAME, "clickedSettings.");
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);
}
public void setTimeDisplay(){
Log.d(CLASS_NAME, "setTimeDisplay");
counter.setText(timer.display());
}
}
And here is SettingsActivity class, where keep options for vibrate:
package com.androiddevbook.onyourbike_chapter5.activities;
import com.androiddevbook.onyourbike.chapter5.helpers.Toaster;
import com.androiddevbook.onyourbike_chapter4.R;
import com.androiddevbook.onyourbike_chapter5.OnYourBike;
import com.androiddevbook.onyourbike_chapter5.model.Settings;
import android.support.v7.app.ActionBarActivity;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
public class SettingsActivity extends ActionBarActivity {
private CheckBox vibrate;
private String CLASS_NAME = "dada";
public SettingsActivity(){
Log.d(CLASS_NAME, "SettingsActivity.class....");
CLASS_NAME = getClass().getName();
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
vibrate = (CheckBox)
findViewById(R.id.vibrate_checkbox);
Settings settings = ((OnYourBike)getApplication()).getSettings();
vibrate.setChecked(settings.isVibrateOn(this));
setupActionBar();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.settings, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.home) {
goHome();
return true;
}
return super.onOptionsItemSelected(item);
}
private void goHome() {
Log.d(CLASS_NAME, "gotoHome");
Intent timer =
new Intent(this, TimerActivity.class);
timer.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(timer);
}
public void onStop(){
super.onStop();
Settings settings = ((OnYourBike)getApplication()).getSettings();
settings.setVibrate(this, vibrate.isChecked());
}
public void vibrateChanged(View view){
Toaster toast = new Toaster(getApplicationContext());
if(vibrate.isChecked())
toast.make(R.string.vibrate_on);
else
toast.make(R.string.vibrate_off);
}
public void goBack(View view){
finish();
}
}
And finnaly, spec about my virtual telephone:
CPU/ABI: ARM (armeabi-v7a)
Target: Android 5.0.1 ( API level 21)
As you Extends ActionBarActivity so you need to get ActionBar using
ActionBar actionBar = getSupportActionBar();
According to the error log:
05-06 09:40:37.323: E/AndroidRuntime(945): Process: com.androiddevbook.onyourbike_chapter4, PID: 945
05-06 09:40:37.323: E/AndroidRuntime(945): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androiddevbook.onyourbike_chapter4/com.androiddevbook.onyourbike_chapter5.activities.SettingsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
ActionBar actionBar = getActionBar(); line returns a null object.
Reasons:
ActionBarActivity subclasses FragmentActivity which is a support component, change code to ActionBar actionBar = getSupportActionBar();
You might be using a theme like ...Light.NoActionBar, so this due to this also there is no ActionBar present for activities, change theme to a theme that support ActionBar.
Another thing to note, this isn't the reason of this issue but, is that ActionBarActivity is deprecated, use AppCompatActivity from now on.
Your error log says it all:
05-06 09:40:37.323: E/AndroidRuntime(945): Process: com.androiddevbook.onyourbike_chapter4, PID: 945
05-06 09:40:37.323: E/AndroidRuntime(945): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androiddevbook.onyourbike_chapter4/com.androiddevbook.onyourbike_chapter5.activities.SettingsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
You are calling a method on a null object:
actionBar.setDisplayHomeAsUpEnabled(true);
So make sure you do a null check or you might need to use getSupportActionBar
change your setupActionBar method like this:
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
Here, this is detailActivity.java which gathers data from openWeatherAPI and populates the data into a listView. When I click on the item on listView there is NPE in OnCreateOptionsMenu.
package com.example.sunshine2;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.ShareActionProvider;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.sunshine2.data.WeatherContract.WeatherEntry;
public class DetailActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new DetailFragment()).commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.detail, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
startActivity(new Intent(this, SettingsActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class DetailFragment extends Fragment implements
LoaderCallbacks<Cursor> {
private static final String LOG_TAG = DetailFragment.class
.getSimpleName();
private static final String FORECAST_SHARE_HASHTAG = " #SunshineApp";
private ShareActionProvider mShareActionProvider;
private String mForecast;
private static final int DETAIL_LOADER = 0;
private static final String[] FORECAST_COLUMNS = {
WeatherEntry.TABLE_NAME + "." + WeatherEntry._ID,
WeatherEntry.COLUMN_DATE, WeatherEntry.COLUMN_SHORT_DESC,
WeatherEntry.COLUMN_MAX_TEMP, WeatherEntry.COLUMN_MIN_TEMP, };
// these constants correspond to the projection defined above, and must
// change if the
// projection changes
private static final int COL_WEATHER_ID = 0;
private static final int COL_WEATHER_DATE = 1;
private static final int COL_WEATHER_DESC = 2;
private static final int COL_WEATHER_MAX_TEMP = 3;
private static final int COL_WEATHER_MIN_TEMP = 4;
public DetailFragment() {
setHasOptionsMenu(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_detail, container, false);
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Inflate the menu; this adds items to the action bar if it is
// present.
inflater.inflate(R.menu.detail_fragment, menu);
// Retrieve the share menu item
MenuItem menuItem = menu.findItem(R.id.action_share);
// Get the provider and hold onto it to set/change the share intent.
mShareActionProvider = (ShareActionProvider) MenuItemCompat
.getActionProvider(menuItem);
// If onLoadFinished happens before this, we can go ahead and set
// the share intent now.
if (mForecast != null) {
mShareActionProvider
.setShareIntent(createShareForecastIntent());
}
}
private Intent createShareForecastIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, mForecast
+ FORECAST_SHARE_HASHTAG);
return shareIntent;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
getLoaderManager().initLoader(DETAIL_LOADER, null, this);
super.onActivityCreated(savedInstanceState);
}
#Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Log.v(LOG_TAG, "In onCreateLoader");
Intent intent = getActivity().getIntent();
if (intent == null) {
return null;
}
// Now create and return a CursorLoader that will take care of
// creating a Cursor for the data being displayed.
return new CursorLoader(getActivity(), intent.getData(),
FORECAST_COLUMNS, null, null, null);
}
#Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
Log.v(LOG_TAG, "In onLoadFinished");
if (!data.moveToFirst()) {
return;
}
String dateString = Utility.formatDate(data
.getLong(COL_WEATHER_DATE));
String weatherDescription = data.getString(COL_WEATHER_DESC);
boolean isMetric = Utility.isMetric(getActivity());
String high = Utility.formatTemperature(
data.getDouble(COL_WEATHER_MAX_TEMP), isMetric);
String low = Utility.formatTemperature(
data.getDouble(COL_WEATHER_MIN_TEMP), isMetric);
mForecast = String.format("%s - %s - %s/%s", dateString,
weatherDescription, high, low);
TextView detailTextView = (TextView) getView().findViewById(
R.id.detail_text);
detailTextView.setText(mForecast);
// If onCreateOptionsMenu has already happened, we need to update
// the share intent now.
if (mShareActionProvider != null) {
mShareActionProvider
.setShareIntent(createShareForecastIntent());
}
}
#Override
public void onLoaderReset(Loader<Cursor> loader) {
}
}
}
And Here is the LogCat
04-13 01:22:51.916: E/AndroidRuntime(20197): FATAL EXCEPTION: main
04-13 01:22:51.916: E/AndroidRuntime(20197): Process: com.example.sunshine2, PID: 20197
04-13 01:22:51.916: E/AndroidRuntime(20197): java.lang.NullPointerException
04-13 01:22:51.916: E/AndroidRuntime(20197): at com.example.sunshine2.DetailActivity$DetailFragment.onCreateOptionsMenu(DetailAc tivity.java:117)
04-13 01:22:51.916: E/AndroidRuntime(20197): at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1582)
04-13 01:22:51.916: E/AndroidRuntime(20197): at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1967)
04-13 01:22:51.916: E/AndroidRuntime(20197): at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
04-13 01:22:51.916: E/AndroidRuntime(20197): at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232)
04-13 01:22:51.916: E/AndroidRuntime(20197): at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:146)
04-13 01:22:51.916: E/AndroidRuntime(20197): at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:199)
04-13 01:22:51.916: E/AndroidRuntime(20197): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:293)
04-13 01:22:51.916: E/AndroidRuntime(20197): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:436)
04-13 01:22:51.916: E/AndroidRuntime(20197): at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:803)
04-13 01:22:51.916: E/AndroidRuntime(20197): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221)
04-13 01:22:51.916: E/AndroidRuntime(20197): at android.os.Handler.handleCallback(Handler.java:733)
04-13 01:22:51.916: E/AndroidRuntime(20197): at android.os.Handler.dispatchMessage(Handler.java:95)
04-13 01:22:51.916: E/AndroidRuntime(20197): at android.os.Looper.loop(Looper.java:149)
04-13 01:22:51.916: E/AndroidRuntime(20197): at android.app.ActivityThread.main(ActivityThread.java:5077)
04-13 01:22:51.916: E/AndroidRuntime(20197): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 01:22:51.916: E/AndroidRuntime(20197): at java.lang.reflect.Method.invoke(Method.java:515)
04-13 01:22:51.916: E/AndroidRuntime(20197): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-13 01:22:51.916: E/AndroidRuntime(20197): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
04-13 01:22:51.916: E/AndroidRuntime(20197): at dalvik.system.NativeStart.main(Native Method)
I've tried debugging the code, but the
- mShareActionProvider gives me null, which I can't figure out how
I think the problem is you have a onClick function declared in your XML menu layout file but no corresponding function in your code.
I have a list of Claim objects, each claim object is initialized with a name and an expense list.
i made an adapter for the listview for the claims. what I am trying to do now is create an adaptor for the expenses. Since each claim has its own expense list, i cannot just make a general adapter. i need to make an adapter for a specific Claim, or am thinking of this wrong? here is what I did..
JUST TO BE CLEAR< MY QUESTION IS: How do I make an adaptor for the list initializd with the expenses, and open that list-view to see the expenses of a specific claim when I click on it?
package app.zioueche_travelexpense;
import java.util.ArrayList;
import java.util.Collection;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.Toast;
//figure out how to add claim in different page. so we can add date range.
public class AddClaim extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_claim);
//adapter for claim view this one works. it is the expenses one that i do not know how to implement
ListView listView = (ListView) findViewById(R.id.claimListView);
Collection<Claim> claims = ClaimListController.getClaimList().getClaim();
final ArrayList<Claim> list = new ArrayList<Claim>(claims);
final ArrayAdapter<Claim> claimAdapter = new ArrayAdapter<Claim>(this, android.R.layout.simple_list_item_1, list);
listView.setAdapter(claimAdapter);
//Added observer pattern
ClaimListController.getClaimList().addListener(new Listener(){
#Override
public void update(){
list.clear();
Collection<Claim> claims = ClaimListController.getClaimList().getClaim();
list.addAll(claims);
claimAdapter.notifyDataSetChanged();
}
});
//SINGLE TAP FUNCTION
listView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//adapter expenses I DO NOT KNOW HOW TO IMPLEMENT THIS
ListView expView = (ListView) findViewById(R.id.ExpenseListView);
Collection<Expense> expenses = list.get(position).getExpenses();
final ArrayList<Expense> expense = new ArrayList<Expense>(expenses);
final ArrayAdapter<Expense> expAdap = new ArrayAdapter<Expense>(AddClaim.this, android.R.layout.simple_list_item_1, expense);
expView.setAdapter(expAdap); //THIS IS MY LINE 64
}
});
//LONG CLICK FUNCTIONS
listView.setOnItemLongClickListener(new OnItemLongClickListener(){
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
final int finalPosition = position;
PopupMenu popup = new PopupMenu(AddClaim.this, view);
popup.getMenuInflater().inflate(R.menu.add_claim, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
//DELETE button check.
if (item.getTitle().equals("Delete")){
AlertDialog.Builder adb = new AlertDialog.Builder(AddClaim.this);
adb.setMessage("Delete "+ list.get(finalPosition).toString()+"?");
adb.setCancelable(true);
adb.setPositiveButton("Delete",new OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int which) {
Claim claim = list.get(finalPosition);
ClaimListController.getClaimList().deleteClaim(claim);
}
});
adb.setNegativeButton("Cancel",new OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
adb.show();
}//end of delete button check
//START of ADD EXPENSE check
if (item.getTitle().equals("Add Expense")){
Intent intent = new Intent(AddClaim.this, ExpenseAdd.class);
intent.putExtra("somename", finalPosition);
startActivity(intent);
}
//end of add expense check
return true;
}
});
popup.show();
return false;
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.add_claim, menu);
return true;
}
protected void onDeleteClick(final int position, final ArrayList<Claim> list){
AlertDialog.Builder adb = new AlertDialog.Builder(AddClaim.this);
adb.setMessage("Delete "+ list.get(position).toString()+"?");
adb.setCancelable(true);
adb.setPositiveButton("Delete",new OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int which) {
Claim claim = list.get(position);
ClaimListController.getClaimList().deleteClaim(claim);
}
});
adb.setNegativeButton("Cancel",new OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
adb.show();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void addClaimView(MenuItem item){
Toast.makeText(this, "going to claim creation page", Toast.LENGTH_SHORT).show();
setContentView(R.layout.claim_add_page);
}
public void addClaims(View v){
ClaimListController ct = new ClaimListController();
EditText textView = (EditText) findViewById(R.id.add_claim_field);
String added = textView.getText().toString();
if (!TextUtils.isEmpty(added)){
final String t = format("added",added);
ct.addClaim(new Claim(added));
Toast.makeText(this, t, Toast.LENGTH_SHORT).show();
textView.setText("");
setContentView(R.layout.claim_list);
//Intent intent = new Intent(MainActivity.this, AddClaim.class);
//startActivity(intent);
}else{
Toast.makeText(AddClaim.this,"Please type something before adding", Toast.LENGTH_SHORT).show();
}
}
private String format(String string, String added) {
String formats = string +" "+ added;
return formats;
}
}
As you can see, i made my listview adapter for the expenses inside the onclick method, since i need the position to get the expense list out of the specific claim.
How can I do this/ when I run this code I get null pointer exceptions on line 64.
here is the log cat.
01-24 02:01:15.434: E/AndroidRuntime(1099): FATAL EXCEPTION: main
01-24 02:01:15.434: E/AndroidRuntime(1099): java.lang.NullPointerException
01-24 02:01:15.434: E/AndroidRuntime(1099): at app.zioueche_travelexpense.AddClaim$2.onItemClick(AddClaim.java:64)
01-24 02:01:15.434: E/AndroidRuntime(1099): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
01-24 02:01:15.434: E/AndroidRuntime(1099): at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
01-24 02:01:15.434: E/AndroidRuntime(1099): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
01-24 02:01:15.434: E/AndroidRuntime(1099): at android.widget.AbsListView$1.run(AbsListView.java:3423)
01-24 02:01:15.434: E/AndroidRuntime(1099): at android.os.Handler.handleCallback(Handler.java:725)
01-24 02:01:15.434: E/AndroidRuntime(1099): at android.os.Handler.dispatchMessage(Handler.java:92)
01-24 02:01:15.434: E/AndroidRuntime(1099): at android.os.Looper.loop(Looper.java:137)
01-24 02:01:15.434: E/AndroidRuntime(1099): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-24 02:01:15.434: E/AndroidRuntime(1099): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 02:01:15.434: E/AndroidRuntime(1099): at java.lang.reflect.Method.invoke(Method.java:511)
01-24 02:01:15.434: E/AndroidRuntime(1099): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-24 02:01:15.434: E/AndroidRuntime(1099): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-24 02:01:15.434: E/AndroidRuntime(1099): at dalvik.system.NativeStart.main(Native Method)
01-24 02:01:17.814: E/Trace(1117): error opening trace file: No such file or directory (2)
I really can't figure out what's the problem here, I did almost the same example i got from somewhere on net and it's working, but this one reports a runtime error when I click on the button to switch to secondActivity. But before I set up onActivityResult in first and sending result in second activity, it switched fine.
It's a little bit longer code, but it's nothing complicated. In first activity you click button to go to second activity, and there you pick two numbers, which are stored in object and sent by intent back to the first activity, and in first activity in textview you get the total of those numbers.
MainActivity
package com.example.parcelablevezba4;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
TextView tv1;
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView)findViewById(R.id.tv1);
btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(MainActivity.this, SecondActivity.class);
startActivityForResult(i, 42);
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 42){
if(resultCode == RESULT_OK){
Object obj2 = data.getParcelableExtra("obje");
int total = obj2.getFirstSummand() + obj2.getSecondSummand();
tv1.setText(obj2.getFirstSummand()+"+"+obj2.getSecondSummand()+"is "+total);
}else if(resultCode == RESULT_CANCELED){
Toast.makeText(getApplicationContext(), "CANCELED", Toast.LENGTH_SHORT).show();
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
SecondActivity
package com.example.parcelablevezba4;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.content.Intent;
public class SecondActivity extends Activity {
EditText et1;
EditText et2;
Button btnOk;
int firstSummand;
int secondSummand;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
et1 = (EditText)findViewById(R.id.etFirst);
et2 = (EditText)findViewById(R.id.etSecond);
btnOk = (Button)findViewById(R.id.btnOk);
firstSummand = Integer.parseInt(et1.getText().toString());
secondSummand = Integer.parseInt(et2.getText().toString());
btnOk.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent resultIntent = new Intent();
Object obj = new Object();
obj.setFirstSummand(firstSummand);
obj.setSecondSummand(secondSummand);
resultIntent.putExtra("obje", obj);
setResult(RESULT_OK,resultIntent);
finish();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
}
}
Object class
package com.example.parcelablevezba4;
import android.os.Parcel;
import android.os.Parcelable;
public class Object implements Parcelable {
private int firstSummand;
private int secondSummand;
public Object(){}
public Object(Parcel p){
this.firstSummand; = p.readInt();
this.secondSummand; = p.readInt();
}
public int getFirstSummand(){
return this.firstSummand;
}
public int getSecondSummand(){
return this.secondSummand;;
}
public void setFirstSummand(int f){
this.firstSummand = f;
}
public void setSecondSummand(int s){
this.secondSummand; = s;
}
#Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
#Override
public void writeToParcel(Parcel p, int flag) {
p.writeInt(firstSummand);
p.writeInt(secondSummand);
}
public static Parcelable.Creator<Object> CREATOR = new Parcelable.Creator<Object>() {
#Override
public Object createFromParcel(Parcel source) {
// TODO Auto-generated method stub
return new Object(source);
}
#Override
public Object[] newArray(int size) {
// TODO Auto-generated method stub
return new Object[size];
}
};
}
I translated this from my language, so if I mistyped somewhere sorry about that.
Error
08-17 13:20:22.933: E/AndroidRuntime(743): FATAL EXCEPTION: main
08-17 13:20:22.933: E/AndroidRuntime(743): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.parcelablevezba4/com.example.parcelablevezba4.SecondActivity}: java.lang.NumberFormatException: unable to parse '' as integer
08-17 13:20:22.933: E/AndroidRuntime(743): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-17 13:20:22.933: E/AndroidRuntime(743): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-17 13:20:22.933: E/AndroidRuntime(743): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-17 13:20:22.933: E/AndroidRuntime(743): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-17 13:20:22.933: E/AndroidRuntime(743): at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 13:20:22.933: E/AndroidRuntime(743): at android.os.Looper.loop(Looper.java:123)
08-17 13:20:22.933: E/AndroidRuntime(743): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-17 13:20:22.933: E/AndroidRuntime(743): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 13:20:22.933: E/AndroidRuntime(743): at java.lang.reflect.Method.invoke(Method.java:507)
08-17 13:20:22.933: E/AndroidRuntime(743): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-17 13:20:22.933: E/AndroidRuntime(743): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-17 13:20:22.933: E/AndroidRuntime(743): at dalvik.system.NativeStart.main(Native Method)
08-17 13:20:22.933: E/AndroidRuntime(743): Caused by: java.lang.NumberFormatException: unable to parse '' as integer
08-17 13:20:22.933: E/AndroidRuntime(743): at java.lang.Integer.parseInt(Integer.java:362)
08-17 13:20:22.933: E/AndroidRuntime(743): at java.lang.Integer.parseInt(Integer.java:332)
08-17 13:20:22.933: E/AndroidRuntime(743): at com.example.parcelablevezba4.SecondActivity.onCreate(SecondActivity.java:30)
08-17 13:20:22.933: E/AndroidRuntime(743): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-17 13:20:22.933: E/AndroidRuntime(743): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-17 13:20:22.933: E/AndroidRuntime(743): ... 11 more
It looks like one of your EditTexts are returning an empty string:
firstSummand = Integer.parseInt(et1.getText().toString());
secondSummand = Integer.parseInt(et2.getText().toString());
And then you try to parse that empty string.
Add a log before or even better a check:
String edit1 = et1.getText().toString();
String edit2 = et2.getText().toString();
Log.e("TAG", "First: "+edit1+" Second: "+edit2);
firstSummand = (edit1.isEmpty()) ? 0 : Integer.parseInt(edit1);
secondSummand = (edit2.isEmpty()) ? 0 : Integer.parseInt(edit2);
I'm trying to add adMob Banner ads into the getView method used for my ListView in one of my fragments. I'm using the latest adMob SDK (com.google.android.gms.ads.).
I'm only finding examples which use the older versions of the Google SDK. If anyone has a link to example of a current version of Google admob please let me know.
FYI - I took Tim's suggestion. I found a complete sample of code from http://jmsliu.com/1482/adding-admob-banner-in-android-listview-header.html.
Its a different one that I first showed you but is set up with 3 Activities. After several hours of testing I thought I would show you my code and the error I'm currently getting, and the original code. I added "Log.i" throughout the program to determine which line causes the abend. It appears that the ads is returning null. Also, note that the original version of code (after the error section) has special "keytwordSet" logic. I was unable to get rid of the syntax errors so I removed it from my version.
AdRequest adRequest = new AdRequest();
Set keywordsSet = new HashSet();
keywordsSet.add("game");
keywordsSet.add("dating");
keywordsSet.add("money");
keywordsSet.add("girl");
adRequest.addKeywords(keywordsSet);
adView.loadAd(adRequest);
New Code:
PostItemAdapter.java
Adapter Class which configs and returns the View for ListView
*/
package com.jms.admobinlistview;
import java.util.HashSet;
import java.util.Set;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.mediation.admob.AdMobExtras;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class PostItemAdapter extends ArrayAdapter {
private LayoutInflater inflater;
private PostData[] datas;
private Activity mainActivity;
private AdView adView;
public PostItemAdapter(Context context, int textViewResourceId,
PostData[] objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
mainActivity = (Activity) context;
inflater = mainActivity.getLayoutInflater();
datas = objects;
}
static class ViewHolder {
TextView postTitleView;
TextView postDateView;
ImageView postThumbView;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (position == 0) {
if (convertView == null || !(convertView instanceof AdView)) {
if (adView == null) {
Log.i("1", "msg1");
AdView adView = new AdView(mainActivity);
Log.i("2", "msg2");
adView.setAdUnitId("ca-app-pub-4409647944042499/8301167762");
Log.i("3", "msg3");
adView.setAdSize(AdSize.BANNER);
Log.i("4", "msg4");
// Convert the default layout parameters so that they play > nice with
// ListView.
float density = mainActivity.getResources().getDisplayMetrics>
().density;
int height = Math.round(AdSize.BANNER.getHeight() * density);
AbsListView.LayoutParams params = new AbsListView.LayoutParams(
AbsListView.LayoutParams.FILL_PARENT,
height);
adView.setLayoutParams(params);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("TEST_DEVICE_ID")
.build();
Log.i("5", "msg5");
adView.loadAd(adRequest);
Log.i("6", "msg6");
}
Log.i("7", "msg7");
convertView = adView;
Log.i("8", "msg8");
}
} else {
Log.i("8", "msg8");
if (convertView == null || convertView instanceof AdView) {
Log.i("9", "msg9");
convertView = inflater.inflate(R.layout.postitem, null);
Log.i("10", "msg10");
viewHolder = new ViewHolder();
Log.i("11", "msg11");
viewHolder.postThumbView = (ImageView) convertView
.findViewById(R.id.postThumb);
Log.i("12", "msg12");
viewHolder.postTitleView = (TextView) convertView
.findViewById(R.id.postTitleLabel);
Log.i("13", "msg13");
viewHolder.postDateView = (TextView) convertView
.findViewById(R.id.postDateLabel);
Log.i("14", "msg14");
convertView.setTag(viewHolder);
Log.i("15", "msg15");
} else {
Log.i("16", "msg16");
viewHolder = (ViewHolder) convertView.getTag();
Log.i("17", "msg17");
}
Log.i("18", "msg18");
if (datas[position].postThumbUrl == null) {
Log.i("19", "msg19");
viewHolder.postThumbView
.setImageResource(R.drawable.postthumb_loading);
}
Log.i("20", "msg20");
viewHolder.postTitleView.setText(datas[position].postTitle);
viewHolder.postDateView.setText(datas[position].postDate);
}
Log.i("21", "msg21");
return convertView;
}
}
Error:
03-16 21:34:10.509: I/1(415): msg1
03-16 21:34:10.530: I/2(415): msg2
03-16 21:34:10.530: I/3(415): msg3
03-16 21:34:10.530: I/4(415): msg4
03-16 21:34:10.582: I/5(415): msg5
03-16 21:34:10.609: D/dalvikvm(415): DexOpt: couldn't find field
Landroid/content/res/Configuration;.smallestScreenWidthDp
03-16 21:34:10.609: W/dalvikvm(415): VFY: unable to resolve instance field 36
03-16 21:34:10.609: D/dalvikvm(415): VFY: replacing opcode 0x52 at 0x0012
03-16 21:34:10.623: D/dalvikvm(415): VFY: dead code 0x0014-0018 in
Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
03-16 21:34:10.649: W/GooglePlayServicesUtil(415): Google Play Store is missing.
03-16 21:34:10.730: D/dalvikvm(415): DexOpt: --- BEGIN 'ads256706667.jar' (bootstrap=0) ---
03-16 21:34:10.919: D/dalvikvm(415): DexOpt: --- END 'ads256706667.jar' (success) ---
03-16 21:34:10.919: D/dalvikvm(415): DEX
prep '/data/data/com.jms.admobinlistview/cache/ads256706667.jar': unzip in 2ms, rewrite 193ms
03-16 21:34:11.019: I/Ads(415): Use AdRequest.Builder.addTestDevice
("B3EEABB8EE11C2BE770B684D95219ECB") to get test ads on this device.
03-16 21:34:11.059: I/Ads(415): Starting ad request.
03-16 21:34:11.179: D/dalvikvm(415): GC_EXTERNAL_ALLOC freed 269K, 52% free 2677K/5575K,
external 2032K/2137K, paused 74ms
03-16 21:34:11.499: I/6(415): msg6
03-16 21:34:11.499: I/7(415): msg7
03-16 21:34:11.499: I/8(415): msg8
03-16 21:34:11.509: I/21(415): msg21
03-16 21:34:11.509: D/AndroidRuntime(415): Shutting down VM
03-16 21:34:11.509: W/dalvikvm(415): threadid=1: thread exiting with uncaught exception
(group=0x40015560)
03-16 21:34:11.589: E/AndroidRuntime(415): FATAL EXCEPTION: main
03-16 21:34:11.589: E/AndroidRuntime(415): java.lang.NullPointerException
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.AbsListView.obtainView
(AbsListView.java:1432)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.ListView.makeAndAddView
(ListView.java:1745)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.ListView.fillDown
(ListView.java:670)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.ListView.fillFromTop
(ListView.java:727)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.ListView.layoutChildren
(ListView.java:1598)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.AbsListView.onLayout
(AbsListView.java:1260)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.view.View.layout(View.java:7175)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.LinearLayout.setChildFrame
(LinearLayout.java:1254)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.LinearLayout.layoutVertical
(LinearLayout.java:1130)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.LinearLayout.onLayout
(LinearLayout.java:1047)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.view.View.layout(View.java:7175)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.FrameLayout.onLayout
(FrameLayout.java:338)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.view.View.layout(View.java:7175)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.LinearLayout.setChildFrame
(LinearLayout.java:1254)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.LinearLayout.layoutVertical
(LinearLayout.java:1130)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.LinearLayout.onLayout
(LinearLayout.java:1047)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.view.View.layout(View.java:7175)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.widget.FrameLayout.onLayout
(FrameLayout.java:338)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.view.View.layout(View.java:7175)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.view.ViewRoot.performTraversals
(ViewRoot.java:1140)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.view.ViewRoot.handleMessage
(ViewRoot.java:1859)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.os.Handler.dispatchMessage
(Handler.java:99)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.os.Looper.loop(Looper.java:123)
03-16 21:34:11.589: E/AndroidRuntime(415): at android.app.ActivityThread.main
(ActivityThread.java:3683)
03-16 21:34:11.589: E/AndroidRuntime(415): at java.lang.reflect.Method.invokeNative(Native
Method)
03-16 21:34:11.589: E/AndroidRuntime(415): at java.lang.reflect.Method.invoke(Method.java:507)
03-16 21:34:11.589: E/AndroidRuntime(415): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-16 21:34:11.589: E/AndroidRuntime(415): at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:597)
03-16 21:34:11.589: E/AndroidRuntime(415): at dalvik.system.NativeStart.main(Native Method)
03-16 21:34:17.879: I/Process(415): Sending signal. PID: 415 SIG: 9
Original Code with previous version of adMob:
/**
* PostItemAdapter.java
*
* Adapter Class which configs and returns the View for ListView
*
*/
package com.jms.admobinlistview;
import java.util.HashSet;
import java.util.Set;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
public class PostItemAdapter extends ArrayAdapter {
private LayoutInflater inflater;
private PostData[] datas;
private Activity mainActivity;
private AdView adView;
public PostItemAdapter(Context context, int textViewResourceId,
PostData[] objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
mainActivity = (Activity) context;
inflater = mainActivity.getLayoutInflater();
datas = objects;
}
static class ViewHolder {
TextView postTitleView;
TextView postDateView;
ImageView postThumbView;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (position == 0) {
if (convertView == null || !(convertView instanceof AdView)) {
if (adView == null) {
adView = new AdView(mainActivity, AdSize.SMART_BANNER,
"a151bd35eeb068d");
AdRequest adRequest = new AdRequest();
Set<String> keywordsSet = new HashSet<String>();
keywordsSet.add("game");
keywordsSet.add("dating");
keywordsSet.add("money");
keywordsSet.add("girl");
adRequest.addKeywords(keywordsSet);
adView.loadAd(adRequest);
}
convertView = adView;
}
} else {
if (convertView == null || convertView instanceof AdView) {
convertView = inflater.inflate(R.layout.postitem, null);
viewHolder = new ViewHolder();
viewHolder.postThumbView = (ImageView) convertView
.findViewById(R.id.postThumb);
viewHolder.postTitleView = (TextView) convertView
.findViewById(R.id.postTitleLabel);
viewHolder.postDateView = (TextView) convertView
.findViewById(R.id.postDateLabel);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
if (datas[position].postThumbUrl == null) {
viewHolder.postThumbView
.setImageResource(R.drawable.postthumb_loading);
}
viewHolder.postTitleView.setText(datas[position].postTitle);
viewHolder.postDateView.setText(datas[position].postDate);
}
return convertView;
}
}
===============================================================================
Tim, thanks for getting back to me. The following is my code and error message that I'm getting. I tried several things and I keep getting the same type of errors. Can you please clarify your explanation you gave? Is purview really preview?
package com.robertrichardson.bxxxyxxxxzxxxxLite;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.database.DataSetObserver;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.Loader;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockListFragment;
import com.actionbarsherlock.view.MenuInflater;
import android.app.Activity;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdRequest.Builder;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.doubleclick.PublisherAdRequest;
import com.google.android.gms.ads.doubleclick.PublisherAdView;
import com.google.android.gms.drive.query.internal.InFilter;
import com.robertrichardson.bxxxyxxxxzxxxxLite.R.string;
/*
* BxxxxListFragment Class: Sets up and displays all Bxxxx Activity on the list.
*/
public class BxxxxListFragment extends SherlockListFragment {
private ArrayList<Bxxxx> mBxxxx;
private boolean mSubtitleVisible;
private LayoutInflater inflater;
private Activity mainActivity;
private static final String AD_UNIT_ID = "ca-app-pub-4409647944042499/8301167762";
public static final String TAG = "BxxxxListFragment";
// private AdView adView;
private AdView adView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
* New ads Logic
*/
setHasOptionsMenu(true);
getSherlockActivity().setTitle(R.string.app_name);
mBxxxx = BxxxxLab.get(getSherlockActivity()).getBxxxx();
BxxxxAdapter adapter = new BxxxxAdapter(mBxxxx);
setListAdapter(adapter);
setRetainInstance(true);
mSubtitleVisible = false;
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setEmptyText(getResources().getString(string.new_bxxxx_attack_empty_desc));
registerForContextMenu(getListView());
setHasOptionsMenu(true);
}
#TargetApi(11)
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
View v = super.onCreateView(inflater, parent, savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (mSubtitleVisible) {
getSherlockActivity().getSupportActionBar().setSubtitle(R.string.subtitle);
}
}
ListView listView = (ListView)v.findViewById(android.R.id.list);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
// Use floating point context menus on Froyer and Gingerbread
registerForContextMenu(listView);
} else {
// Use contextual action bar on Honeycomb and higher
listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
public boolean onActionItemClicked(
android.view.ActionMode arg0, android.view.MenuItem arg1) {
// TODO Auto-generated method stub
return false;
}
public boolean onCreateActionMode(android.view.ActionMode mode,
android.view.Menu menu) {
// TODO Auto-generated method stub
return false;
}
public void onDestroyActionMode(android.view.ActionMode mode) {
// TODO Auto-generated method stub
}
public boolean onPrepareActionMode(
android.view.ActionMode mode, android.view.Menu menu) {
// TODO Auto-generated method stub
return false;
}
public void onItemCheckedStateChanged(
android.view.ActionMode mode, int position, long id,
boolean checked) {
// TODO Auto-generated method stub
}
// ActionMode.Callback methods
});
}
return v;
}
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
Bxxxx c = ((BxxxxAdapter)getListAdapter()).getItem(position);
// Start Bxxxx Activity
Intent i = new Intent(getSherlockActivity(), BxxxxPagerActivity.class);
i.putExtra(BxxxxFragment.EXTRA_BULLIED_ID, c.getId());
startActivityForResult(i, 0);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {>
((BxxxxAdapter)getListAdapter()).notifyDataSetChanged();
}
#Override
public void onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.fragment_bxxxx_list, menu);
}
#TargetApi(11)
#Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item)
{
switch (item.getItemId()) {
case R.id.settings:
Intent i=new Intent(getSherlockActivity(), Preferences.class);
startActivity(i);
return(true);
case R.id.about:
i=new Intent(getSherlockActivity(),BxxxxContentActivity.class);
i.putExtra(BxxxxContentActivity.EXTRA_FILE,
"file:///android_asset/misc/about.html");
startActivity(i);
return(true);
case R.id.help:
i=new Intent(getSherlockActivity(),BxxxxContentActivity.class);
i.putExtra(BxxxxContentActivity.EXTRA_FILE,
"file:///android_asset/misc/help.html");
startActivity(i);
return(true);
case R.id.disclaimer:
i=new Intent(getSherlockActivity(),BxxxxContentActivity.class);
i.putExtra(BxxxxContentActivity.EXTRA_FILE,
"file:///android_asset/misc/disclaimer.html");
startActivity(i);
return(true);
case R.id.menu_item_new_bxxxx:
Bxxxx bxxxx = new Bxxxx();
BxxxxLab.get(getSherlockActivity()).addBxxxx(bxxxx);
i = new Intent(getSherlockActivity(), BxxxxPagerActivity.class);
i.putExtra(BxxxxFragment.EXTRA_BULLIED_ID, bxxxx.getId());
startActivityForResult(i,0);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public void onCreateContextMenu(ContextMenu menu,View v, ContextMenuInfo menuInfo) {
getActivity().getMenuInflater().inflate(R.menu.bxxxx_list_item_context, menu);
}
#Override
public boolean onContextItemSelected(android.view.MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
int position = info.position;
BxxxxAdapter adapter = (BxxxxAdapter)getListAdapter();
Bxxxx bxxxx = adapter.getItem(position);
switch (item.getItemId()) {
case R.id.menu_item_delete_bxxxx:
BxxxxLab.get(getActivity()).deleteBxxxx(bxxxx);
adapter.notifyDataSetChanged();
return true;
}
return super.onContextItemSelected(item);
}
private class BxxxxAdapter extends ArrayAdapter<Bxxxx> {
public BxxxxAdapter(ArrayList<Bxxxx> bxxxx) {
super(getSherlockActivity(), android.R.layout.simple_list_item_1, bxxxx);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
/*
* New ads Logic
*/
Log.i("1", "msg1");
if (position == 0)
{
if (convertView == null || !(convertView instanceof AdView)) {
if (adView == null) {
Log.i("2", "msg2");
adView = new AdView(mainActivity); <=== Abends on this line
Log.i("3", "msg3");
adView.setAdUnitId("ca-app-pub-4409647944042499/8301167762");
Log.i("4", "msg4");
adView.setAdSize(AdSize.BANNER);
Log.i("5", "msg5");
// Convert the default layout parameters so that they play nice with
// ListView.
float density = mainActivity.getResources().getDisplayMetrics().density;
int height = Math.round(AdSize.BANNER.getHeight() * density);
AbsListView.LayoutParams params = new AbsListView.LayoutParams(
AbsListView.LayoutParams.FILL_PARENT,
height);
adView.setLayoutParams(params);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
}
convertView = adView;
return convertView;
}
return convertView;
} else {
if (convertView == null || convertView instanceof AdView) {
// If we weren't given a view, inflate one
if (convertView == null) {
convertView = getSherlockActivity().getLayoutInflater()
.inflate(R.layout.list_item_bxxxx, null);
}
// Enter the view of this Bxxxx Attack
Bxxxx c = getItem(position);
TextView titleTextView =
(TextView)convertView.findViewById(R.id.bxxxx_list_item_titleTextView);
titleTextView.setText(c.getTitle());
TextView dateTextView =
(TextView)convertView.findViewById(R.id.bxxxx_list_item_dateTextView);
dateTextView.setText(DateFormat.format("EEEE, MMM dd, yyyy hh : mm a", c.getDate()).toString());
CheckBox resolvedCheckBox =
(CheckBox)convertView.findViewById(R.id.bxxxx_list_item_resolvedCheckBox);
resolvedCheckBox.setChecked(c.isResolved());
return convertView;
}
return convertView;
}
}
}
#Override
public void onResume() {
super.onResume();
((BxxxxAdapter)getListAdapter()).notifyDataSetChanged();
}
}
03-18 06:52:29.785: D/dalvikvm(932): VFY: replacing opcode 0x6f at 0x0006
03-18 06:52:30.085: I/1(932): msg1
03-18 06:52:30.085: I/2(932): msg2
03-18 06:52:30.085: D/AndroidRuntime(932): Shutting down VM
03-18 06:52:30.095: W/dalvikvm(932): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-18 06:52:30.135: E/AndroidRuntime(932): FATAL EXCEPTION: main
03-18 06:52:30.135: E/AndroidRuntime(932): java.lang.NullPointerException
03-18 06:52:30.135: E/AndroidRuntime(932): at android.view.ViewConfiguration.get(ViewConfiguration.java:228)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.view.View.(View.java:1878)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.view.ViewGroup.(ViewGroup.java:281)
03-18 06:52:30.135: E/AndroidRuntime(932): at com.google.android.gms.ads.AdView.(Unknown Source)
03-18 06:52:30.135: E/AndroidRuntime(932): at com.robertrichardson.bxxxyxxxxzxxxLite.BxxxxListFragment$BxxxxAdapter.getView(BxxxxListFragment.java:251)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.ListView.makeAndAddView(ListView.java:1745)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.ListView.fillDown(ListView.java:670)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.ListView.fillFromTop(ListView.java:727)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.ListView.layoutChildren(ListView.java:1598)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.view.View.layout(View.java:7175)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.view.View.layout(View.java:7175)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.view.View.layout(View.java:7175)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.view.View.layout(View.java:7175)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.view.View.layout(View.java:7175)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.view.View.layout(View.java:7175)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
03-18 06:52:30.135: E/AndroidRuntime(932): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
It looks like you are hiding the class variable 'adView' in the new code by declaring a local variable of the same name. Due to the scope, you're setting convertView to the global adView, which is always null. Just change "AdView adView =" to "adView ="