Reputation: 25
So I am writing an android application that starts an activity after a notification has been clicked. I am getting this in my LogCat:
`
05-01 13:43:49.435: E/AndroidRuntime(28224): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chowpalv21/com.example.chowpalv21.SmsViewActivity}: android.view.InflateException: Binary XML file line #21: Error inflating class com.android.internal.widget.ActionBarOverlayLayout
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.app.ActivityThread.access$700(ActivityThread.java:159)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.os.Handler.dispatchMessage(Handler.java:99)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.os.Looper.loop(Looper.java:137)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.app.ActivityThread.main(ActivityThread.java:5419)
05-01 13:43:49.435: E/AndroidRuntime(28224): at java.lang.reflect.Method.invokeNative(Native Method)
05-01 13:43:49.435: E/AndroidRuntime(28224): at java.lang.reflect.Method.invoke(Method.java:525)
05-01 13:43:49.435: E/AndroidRuntime(28224): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
05-01 13:43:49.435: E/AndroidRuntime(28224): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
05-01 13:43:49.435: E/AndroidRuntime(28224): at dalvik.system.NativeStart.main(Native Method)
05-01 13:43:49.435: E/AndroidRuntime(28224): Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class com.android.internal.widget.ActionBarOverlayLayout
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
05-01 13:43:49.435: E/AndroidRuntime(28224): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3553)
05-01 13:43:49.435: E/AndroidRuntime(28224): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3616)
05-01 13:43:49.435: E/AndroidRuntime(28224): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:357)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.app.Activity.setContentView(Activity.java:1956)
05-01 13:43:49.435: E/AndroidRuntime(28224): at com.example.chowpalv21.SmsViewActivity.onCreate(SmsViewActivity.java:80)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.app.Activity.performCreate(Activity.java:5372)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
05-01 13:43:49.435: E/AndroidRuntime(28224): ... 11 more
05-01 13:43:49.435: E/AndroidRuntime(28224): Caused by: java.lang.NullPointerException
05-01 13:43:49.435: E/AndroidRuntime(28224): at com.example.chowpalv21.SmsViewActivity.onCreateView(SmsViewActivity.java:121)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.app.Activity.onCreateView(Activity.java:4924)
05-01 13:43:49.435: E/AndroidRuntime(28224): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
05-01 13:43:49.435: E/AndroidRuntime(28224): ... 22 more
`
I have scoured StackOverflow for answers because it seems others have had similar problems - I tried rebuilding and cleaning the project and restarting ADT as well as creating a new file. I was wondering if anyone here has a guidance.
Here is my layout file:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll_view_sms"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
style="?android:listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/food_title_label" />
<EditText
android:id="@+id/food_title_sms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="16dp" />
</LinearLayout>
</LinearLayout>
<TextView
style="?android:listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Units of Measurement:" />
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/imperial_checkBox_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Imperial" />
<CheckBox
android:id="@+id/metric_checkBox_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Metric" />
</TableRow>
<TextView
style="?android:listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Number of Servings:" />
<EditText
android:id="@+id/food_servings_sms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" >
</EditText>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/ingredient_text_sms"
style="?android:listSeparatorTextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ingredients" />
</TableRow>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Spinner
android:id="@+id/imperial_spinner_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/imperial_array"
android:visibility="gone" />
<Spinner
android:id="@+id/metric_spinner_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/metric_array"
android:visibility="gone" />
</RelativeLayout>
<EditText
android:id="@+id/amount_text_sms"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/ing_name_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:ems="10" />
</TableRow>
<!-- second ingredient -->
<TextView
style="?android:listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Directions" />
<EditText
android:id="@+id/directions_text_sms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine" />
<TextView
style="?android:listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Options" />
<Button
android:id="@+id/save_button_sms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save Recipe" />
<Button
android:id="@+id/dismiss_button_sms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Dismiss" />
<!-- DONE -->
</LinearLayout>
</ScrollView>
ALSO Here is the code for SMSViewActivity:
* File: SmsViewActivity.java
package com.example.chowpalv21;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class SmsViewActivity extends Activity {
private static final String TAG = "SmsViewActivity";
private FoodJSONSerializer mSerializer;
// protected TextView mReceivedFromView;
public Button mSaveButton, mDismissButton;
public int mNotificationId;
public String message;
private EditText mTitleField;
private CheckBox mImperialCheckBox;
private CheckBox mMetricCheckBox;
private EditText mServingsField;
private EditText mDirectionsField;
// set up spinners. allows for up to ten ingredients.
private Spinner mMetricSpinner;
private Spinner mImperialSpinner;
Food mFood;
//----------------------
------------------------
public void onCreate(Bundle savedInstanceState){
setContentView(R.layout.view_sms);
//super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
//View v = findViewById(R.layout.sms_view);
View v = super.onCreateView(name, context, attrs);
mSaveButton = (Button) findViewById(R.id.save_button_sms);
mDismissButton = (Button) findViewById(R.id.dismiss_button_sms);
// ------------------------------------------------------------
// Get extras and display information in view
//String sender = getIntent().getStringExtra("sender");
String msg = getIntent().getStringExtra("message");
try {
JSONObject jsonRecipe = new JSONObject(msg);
Food mFood = new Food(jsonRecipe);
Log.i(TAG, "Food = " + mFood);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// -----------------------------------------------------------------------
mNotificationId = getIntent().getIntExtra("notificationid", 0);
if (mNotificationId == 0) {
Log.e(TAG, "Could not retrieve notification ID.");
Toast.makeText(this, "A fatal error has occurred in SMS viewer.",
Toast.LENGTH_LONG).show();
finish();
}
// Cancel the notification
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationMgr = (NotificationManager) getSystemService(ns);
notificationMgr.cancel(mNotificationId);
// --------------------------------------------------
mTitleField = (EditText)v. findViewById(R.id.food_title_sms);
mTitleField.setText(mFood.getTitle());
mServingsField = (EditText)v. findViewById(R.id.food_servings_sms);
mServingsField.setText(mFood.getServings());
mDirectionsField = (EditText)v. findViewById(R.id.directions_text_sms);
mDirectionsField.setText(mFood.getDirections());
// --------------------------------------------------
// Listener for Save button click
mSaveButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
// Listener for Dismiss button click
mDismissButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
backToList();
finish();
}
});
return v;
}
public void backToList() {
Intent i = new Intent(this, FoodListFragment.class);
startActivity(i);
}
}
The odd part is, the exception is on a widget named ActionBarOverlayLayout which is not in my layout. If anyone knows that would help a lot! (project due Monday!) Claudia
Upvotes: 0
Views: 1972
Reputation: 8445
Why are you override onCreateView? In onCreate() you are setting the content using a layout resource. Your other initilization code should go here or onResume() depending on what it's doing. Try this...
public class SmsViewActivity extends Activity {
private static final String TAG = "SmsViewActivity";
private FoodJSONSerializer mSerializer;
public Button mSaveButton, mDismissButton;
public int mNotificationId;
public String message;
private EditText mTitleField;
private CheckBox mImperialCheckBox;
private CheckBox mMetricCheckBox;
private EditText mServingsField;
private EditText mDirectionsField;
private Spinner mMetricSpinner;
private Spinner mImperialSpinner;
Food mFood;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.view_sms);
mSaveButton = (Button) findViewById(R.id.save_button_sms);
mDismissButton = (Button) findViewById(R.id.dismiss_button_sms);
// ------------------------------------------------------------
// Get extras and display information in view
//String sender = getIntent().getStringExtra("sender");
String msg = getIntent().getStringExtra("message");
try {
JSONObject jsonRecipe = new JSONObject(msg);
Food mFood = new Food(jsonRecipe);
Log.i(TAG, "Food = " + mFood);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// -----------------------------------------------------------------------
mNotificationId = getIntent().getIntExtra("notificationid", 0);
if (mNotificationId == 0) {
Log.e(TAG, "Could not retrieve notification ID.");
Toast.makeText(this, "A fatal error has occurred in SMS viewer.",
Toast.LENGTH_LONG).show();
finish();
}
// Cancel the notification
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationMgr = (NotificationManager) getSystemService(ns);
notificationMgr.cancel(mNotificationId);
// --------------------------------------------------
mTitleField = (EditText)v. findViewById(R.id.food_title_sms);
mTitleField.setText(mFood.getTitle());
mServingsField = (EditText)v. findViewById(R.id.food_servings_sms);
mServingsField.setText(mFood.getServings());
mDirectionsField = (EditText)v. findViewById(R.id.directions_text_sms);
mDirectionsField.setText(mFood.getDirections());
// --------------------------------------------------
// Listener for Save button click
mSaveButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
// Listener for Dismiss button click
mDismissButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
backToList();
finish();
}
});
return v;
}
public void backToList() {
Intent i = new Intent(this, FoodListFragment.class);
startActivity(i);
}
}
Upvotes: 4