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
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);
}
}
Related
My drawing app is crashing on start up when I try to add image Buttons outside of the table in the bottom linear layout. Can anyone point me in the right direction?
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true">
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFCCCCCC"
android:orientation="vertical"
tools:context=".MainActivity" >
<!-- Top Buttons -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/new_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="#string/start_new"
android:src="#drawable/new_pic" />
<ImageButton
android:id="#+id/draw_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="#string/brush"
android:src="#drawable/brush" />
<ImageButton
android:id="#+id/erase_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="#string/erase"
android:src="#drawable/eraser" />
<ImageButton
android:id="#+id/save_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="#string/save"
android:src="#drawable/save" />
</LinearLayout>
<!-- Custom View -->
<com.example.drawingfun.DrawingView
android:id="#+id/drawing"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:layout_weight="1"
android:background="#FFFFFFFF"
android:scaleType="centerInside" />
</LinearLayout>
<!-- Color Palette -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:clickable="true">
<!-- Top Row -->
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TableRow>
<LinearLayout
android:id="#+id/paint_colors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background = "#drawable/colorbutton1"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton1"
android:tag="#FFE21A1A" />
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background="#drawable/colorbutton2"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton2"
android:tag="#FFF2D820" />
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background="#drawable/colorbutton3"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton3"
android:tag="#FF35EF22" />
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background="#drawable/colorbutton4"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton4"
android:tag="#FF26D3EA" />
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background="#drawable/colorbutton5"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton5"
android:tag="#FFF73E9B" />
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background="#drawable/colorbutton6"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton6"
android:tag="#FFFFFFFF" />
</LinearLayout>
</TableRow>
<!-- Bottom Row -->
<TableRow>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background="#drawable/colorbutton7"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton7"
android:tag="#FF7A4426"/>
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background="#drawable/colorbutton8"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton8"
android:tag="#FFF74F1C"/>
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background="#drawable/colorbutton9"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton9"
android:tag="#FF217C14" />
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background="#drawable/colorbutton10"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton10"
android:tag="#FF312EBC"/>
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background="#drawable/colorbutton11"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton11"
android:tag="#FF5D1F93" />
<ImageButton
android:layout_width="#dimen/large_brush"
android:layout_height="#dimen/large_brush"
android:layout_margin="4dp"
android:background="#drawable/colorbutton12"
android:contentDescription="#string/paint"
android:onClick="paintClicked"
android:src="#drawable/colorbutton12"
android:tag="#FF000000"/>
</LinearLayout>
</TableRow>
</TableLayout>
<ImageButton
android:id="#+id/botDrag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:gravity="center_horizontal"
android:background = "#drawable/sendbutton"
android:contentDescription="#string/drag"
android:src="#drawable/sendbutton"
android:tag="#FFE21A1A" />
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>
Java:
package com.example.drawingfun;
import java.util.UUID;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TableRow;
import android.widget.TableLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelSlideListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
/**
* This is demo code to accompany the Mobiletuts+ tutorial series:
* - Android SDK: Create a Drawing App
*
* Sue Smith
* August 2013
*
*/
public class MainActivity extends Activity implements OnClickListener {
//custom drawing view
private DrawingView drawView;
private View botDrag;
//buttons
private ImageButton currPaint, drawBtn, eraseBtn, newBtn, saveBtn;
//sizes
private float mediumBrush;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//get drawing view
drawView = (DrawingView)findViewById(R.id.drawing);
//get bottom panel drag view
botDrag = (View)findViewById(R.id.botDrag);
//get the palette and first color button
LinearLayout paintLayout = (LinearLayout)findViewById(R.id.paint_colors);
currPaint = (ImageButton)paintLayout.getChildAt(0);
currPaint.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed));
//Send current brush size to color palette
//sizes from dimensions
mediumBrush = getResources().getInteger(R.integer.medium_size);
//draw button
drawBtn = (ImageButton)findViewById(R.id.draw_btn);
drawBtn.setOnClickListener(this);
//set initial size
drawView.setBrushSize(mediumBrush);
//erase button
eraseBtn = (ImageButton)findViewById(R.id.erase_btn);
eraseBtn.setOnClickListener(this);
//new button
newBtn = (ImageButton)findViewById(R.id.new_btn);
newBtn.setOnClickListener(this);
//save button
saveBtn = (ImageButton)findViewById(R.id.save_btn);
saveBtn.setOnClickListener(this);
SlidingUpPanelLayout layout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
layout.setShadowDrawable(getResources().getDrawable(R.drawable.above_shadow));
layout.setAnchorPoint(0.3f);
layout.setDragView(botDrag);
layout.setPanelSlideListener(new PanelSlideListener() {
#Override
public void onPanelSlide(View panel, float slideOffset) {
if (slideOffset < 0.2) {
if (getActionBar().isShowing()) {
getActionBar().hide();
}
} else {
if (!getActionBar().isShowing()) {
getActionBar().show();
}
}
}
#Override
public void onPanelExpanded(View panel) {
}
#Override
public void onPanelCollapsed(View panel) {
}
#Override
public void onPanelAnchored(View panel) {
}
});
}
#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;
}
//user clicked paint
public void paintClicked(View view){
//use chosen color
//set erase false
drawView.setErase(false);
drawView.setBrushSize(drawView.getLastBrushSize());
if(view!=currPaint){
ImageButton imgView = (ImageButton)view;
String color = view.getTag().toString();
drawView.setColor(color);
//update ui
imgView.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed));
currPaint.setImageDrawable(getResources().getDrawable(R.drawable.paint));
currPaint=(ImageButton)view;
}
}
#Override
public void onClick(View view){
if(view.getId()==R.id.draw_btn){
//draw button clicked
final Dialog brushDialog = new Dialog(this);
brushDialog.setTitle("Brush size:");
brushDialog.setContentView(R.layout.brush_seekbar);
brushDialog.setCancelable(true);
SeekBar brushSeekbar = (SeekBar) brushDialog.findViewById(R.id.brushSize_seekbar);
int brushSize = brushSeekbar.getProgress();
brushSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if (fromUser)
drawView.setErase(false); //turn off eraser
drawView.setBrushSize(progress); //Change StrokeWidth
}
});
Button closeBrushBtn = (Button) brushDialog.findViewById(R.id.closeBrushBtn);
// if decline button is clicked, close the custom dialog
closeBrushBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
brushDialog.dismiss();
}
});
brushDialog.show();
//pass brush size to DrawingView
}
else if(view.getId()==R.id.erase_btn){
//switch to erase - choose size
final Dialog brushDialog = new Dialog(this);
brushDialog.setTitle("Erase size:");
brushDialog.setContentView(R.layout.brush_seekbar);
brushDialog.setCancelable(true);
SeekBar brushSeekbar = (SeekBar) brushDialog.findViewById(R.id.brushSize_seekbar);
brushSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if (fromUser)
drawView.setErase(true);
drawView.setBrushSize(progress); //Change StrokeWidth
}
});
Button closeBrushBtn = (Button) brushDialog.findViewById(R.id.closeBrushBtn);
// if decline button is clicked, close the custom dialog
closeBrushBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
brushDialog.dismiss();
}
});
brushDialog.show();
}
else if(view.getId()==R.id.new_btn){
//new button
AlertDialog.Builder newDialog = new AlertDialog.Builder(this);
newDialog.setTitle("New drawing");
newDialog.setMessage("Start new drawing (you will lose the current drawing)?");
newDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
drawView.startNew();
dialog.dismiss();
}
});
newDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
dialog.cancel();
}
});
newDialog.show();
}
else if(view.getId()==R.id.save_btn){
//save drawing
AlertDialog.Builder saveDialog = new AlertDialog.Builder(this);
saveDialog.setTitle("Save drawing");
saveDialog.setMessage("Save drawing to device Gallery?");
saveDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
//save drawing
drawView.setDrawingCacheEnabled(true);
//attempt to save
String imgSaved = MediaStore.Images.Media.insertImage(
getContentResolver(), drawView.getDrawingCache(),
UUID.randomUUID().toString()+".png", "drawing");
//feedback
if(imgSaved!=null){
Toast savedToast = Toast.makeText(getApplicationContext(),
"Drawing saved to Gallery!", Toast.LENGTH_SHORT);
savedToast.show();
}
else{
Toast unsavedToast = Toast.makeText(getApplicationContext(),
"Oops! Image could not be saved.", Toast.LENGTH_SHORT);
unsavedToast.show();
}
drawView.destroyDrawingCache();
}
});
saveDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
dialog.cancel();
}
});
saveDialog.show();
}
}
}
LogCat:
10-26 20:55:10.716: E/AndroidRuntime(883): FATAL EXCEPTION: main
10-26 20:55:10.716: E/AndroidRuntime(883): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.drawingfun/com.example.drawingfun.MainActivity}: java.lang.ClassCastException: android.widget.TableRow cannot be cast to android.widget.ImageButton
10-26 20:55:10.716: E/AndroidRuntime(883): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
10-26 20:55:10.716: E/AndroidRuntime(883): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-26 20:55:10.716: E/AndroidRuntime(883): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-26 20:55:10.716: E/AndroidRuntime(883): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-26 20:55:10.716: E/AndroidRuntime(883): at android.os.Handler.dispatchMessage(Handler.java:99)
10-26 20:55:10.716: E/AndroidRuntime(883): at android.os.Looper.loop(Looper.java:137)
10-26 20:55:10.716: E/AndroidRuntime(883): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-26 20:55:10.716: E/AndroidRuntime(883): at java.lang.reflect.Method.invokeNative(Native Method)
10-26 20:55:10.716: E/AndroidRuntime(883): at java.lang.reflect.Method.invoke(Method.java:525)
10-26 20:55:10.716: E/AndroidRuntime(883): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-26 20:55:10.716: E/AndroidRuntime(883): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-26 20:55:10.716: E/AndroidRuntime(883): at dalvik.system.NativeStart.main(Native Method)
10-26 20:55:10.716: E/AndroidRuntime(883): Caused by: java.lang.ClassCastException: android.widget.TableRow cannot be cast to android.widget.ImageButton
10-26 20:55:10.716: E/AndroidRuntime(883): at com.example.drawingfun.MainActivity.onCreate(MainActivity.java:53)
10-26 20:55:10.716: E/AndroidRuntime(883): at android.app.Activity.performCreate(Activity.java:5133)
10-26 20:55:10.716: E/AndroidRuntime(883): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-26 20:55:10.716: E/AndroidRuntime(883): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-26 20:55:10.716: E/AndroidRuntime(883): ... 11 more
Thanks for any help, I'm new to Android Development and pretty lost here.
Your bottom linear layout is inside the tablelayout. Or you are referring to imagebutton botDrag?
Can you see if there is anything wrong with my code?
I tried to create dialog box when the button is pressed.
I don't see something wrong here, But the logcat shows java.lang.NullPointerException in this line "agree.setOnClickListener(new OnClickListener() {"
package com.sociyo;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //Lock Orientation
requestWindowFeature(Window.FEATURE_NO_TITLE); //Hide Action menu
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //Load main activity
//viewPager default page
ViewPagerAdapter adapter = new ViewPagerAdapter();
ViewPager myPager = (ViewPager) findViewById(R.id.pager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
//textView clickable
Button agree = (Button)findViewById(R.id.btnTerms);
agree.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder tpDialog = new AlertDialog.Builder(null);
tpDialog.setTitle("Terms and Policy");
tpDialog.setMessage(R.string.action_settings)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
MainActivity.this.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.main, menu);
return true;
}
}
And this is the complete log cat :
E/AndroidRuntime(13076): FATAL EXCEPTION: main
E/AndroidRuntime(13076): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sociyo/com.sociyo.MainActivity}: java.lang.NullPointerException
E/AndroidRuntime(13076): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
E/AndroidRuntime(13076): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095)
E/AndroidRuntime(13076): at android.app.ActivityThread.access$600(ActivityThread.java:137)
E/AndroidRuntime(13076): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
E/AndroidRuntime(13076): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(13076): at android.os.Looper.loop(Looper.java:213)
E/AndroidRuntime(13076): at android.app.ActivityThread.main(ActivityThread.java:4793)
E/AndroidRuntime(13076): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(13076): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(13076): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
E/AndroidRuntime(13076): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
E/AndroidRuntime(13076): at dalvik.system.NativeStart.main(Native Method)
**E/AndroidRuntime(13076): Caused by: java.lang.NullPointerException**
E/AndroidRuntime(13076): at com.sociyo.MainActivity.onCreate(MainActivity.java:34)
E/AndroidRuntime(13076): at android.app.Activity.performCreate(Activity.java:5008)
E/AndroidRuntime(13076): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime(13076): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
E/AndroidRuntime(13076): ... 11 more
My activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</android.support.v4.view.ViewPager>
</RelativeLayout>
And my activity_register.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical" >
<TextView
android:id="#+id/tvRegisterTitle"
style="#style/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#string/register_text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/etNameReg"
style="#style/textfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spMlmList"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/name_hint"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/etEmailReg"
style="#style/textfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/etNameReg"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/email_hint"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/etPasswordReg"
style="#style/textfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/etEmailReg"
android:layout_below="#+id/etEmailReg"
android:layout_centerVertical="true"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="#string/password_hint"
android:inputType="textPassword" />
<Spinner
android:id="#+id/spMlmList"
style="#style/textfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvRegisterTitle"
android:layout_below="#+id/tvRegisterTitle"
android:layout_marginTop="15dp"
android:entries="#array/mlm_list" />
<Button
android:id="#+id/btnRegister"
style="#style/buttonBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/etPasswordReg"
android:layout_below="#+id/chkAgree"
android:layout_marginTop="15dp"
android:text="#string/register_text" />
<CheckBox
android:id="#+id/chkAgree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/etPasswordReg"
android:text="#string/agree_text"
android:layout_marginTop="15dp"
style="#style/checkbox"/>
<Button
android:id="#+id/btnTerms"
android:background="#android:color/transparent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/chkAgree"
android:layout_alignBottom="#+id/chkAgree"
android:layout_toRightOf="#+id/tvRegisterTitle"
android:layout_marginLeft="10dp"
android:text="#string/terms_policy"
style="#style/smallLink"/>
</RelativeLayout>
Yes the button doesnt exist at that point.
Your R.id.btnTermsR.id.btnTerms is defined in activity_register.xml, but that layout is never inflated. or not accessible at that point :)
Its the button that has the Problem, not the OnClickListener. A nullpointer within the Listener would appear the moment you click the button, not while attaching it.
// Before Replace
AlertDialog.Builder tpDialog = new AlertDialog.Builder(null);
// After Replace
AlertDialog.Builder tpDialog = new AlertDialog.Builder(MainActivity.this);
AlertDialog.Builder tpDialog = new AlertDialog.Builder(null);
change this line too
AlertDialog.Builder tpDialog = new AlertDialog.Builder(MainActivity.this);
I was working on a GUI inside of my app. I originally had a crappy look to it that just contained all of the basic stuff to test my java functions in. After I had all the functions up and running I redisgned the GUI using the graphical editor in Eclipse. The next time I ran my app I had the android.webkit.WebView cannot be cast to android.widget.Button in my LogCat. I didn't change anything in the java and all the declarations in the GUI are the same as far as I can tell. I can easily revert the GUI back to the crappy version but that doesn't help me much. I hope someone on here can help me find my problem. I have posted the xml, java, and LogCat.
05-09 13:25:19.756: E/AndroidRuntime(10424): FATAL EXCEPTION: main
05-09 13:25:19.756: E/AndroidRuntime(10424): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dcc/com.example.dcc.ActionItem}:
java.lang.ClassCastException: android.webkit.WebView cannot be cast to android.widget.Button
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.ActivityThread.access$600(ActivityThread.java:130)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.os.Looper.loop(Looper.java:137)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-09 13:25:19.756: E/AndroidRuntime(10424): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:25:19.756: E/AndroidRuntime(10424): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 13:25:19.756: E/AndroidRuntime(10424): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-09 13:25:19.756: E/AndroidRuntime(10424): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-09 13:25:19.756: E/AndroidRuntime(10424): at dalvik.system.NativeStart.main(Native Method)
05-09 13:25:19.756: E/AndroidRuntime(10424): Caused by: java.lang.ClassCastException: android.webkit.WebView cannot be cast to android.widget.Button
05-09 13:25:19.756: E/AndroidRuntime(10424): at com.example.dcc.ActionItem.onCreate(ActionItem.java:54)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.Activity.performCreate(Activity.java:5008)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
05-09 13:25:19.756: E/AndroidRuntime(10424): ... 11 more
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="4" >
<LinearLayout
android:layout_width="212dp"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="left"
android:layout_row="0"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Button1_name"
android:drawableRight="#drawable/news"/>
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Button2_name" />
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Button3_name"
android:drawableRight="#drawable/cal"/>
<Button
android:id="#+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Button4_name"
android:drawableRight="#drawable/mail"/>
<Button
android:id="#+id/button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Button5_name"
android:drawableRight="#drawable/gallery" />
<Button
android:id="#+id/button6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Button6_name"
android:drawableRight="#drawable/report" />
<Button
android:id="#+id/button7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Button7_name"
android:drawableRight="#drawable/ep" />
<Button
android:id="#+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Button8_name"
android:drawableRight="#drawable/directory" />
</LinearLayout>
<GridLayout
android:id="#+id/a"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_gravity="left"
android:layout_row="0"
android:columnCount="2" >
</GridLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="10dp"
android:layout_height="fill_parent"
android:layout_column="2"
android:layout_gravity="left"
android:layout_row="0"
android:background="#drawable/black"
tools:ignore="ContentDescription" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="238dp"
android:layout_height="fill_parent"
android:layout_column="3"
android:layout_gravity="left|top"
android:layout_row="0"
android:background="#android:color/black" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/feedtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/feeddescribtion"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/feedpubdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/feedlink"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="594dp" >
</ListView>
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="waiting" />
</LinearLayout>
</ScrollView>
<WebView
android:id="#+id/webView1"
android:layout_width="830dp"
android:layout_height="555dp"
android:layout_column="3"
android:layout_gravity="right|bottom"
android:layout_row="0" />
<Button
android:id="#+id/email_button1"
android:layout_width="585dp"
android:layout_height="114dp"
android:layout_column="3"
android:layout_gravity="center_horizontal|top"
android:layout_row="0"
android:text="Submit Action Item Now" />
<TextView
android:id="#+id/actionView"
android:layout_width="243dp"
android:layout_height="113dp"
android:layout_column="3"
android:layout_gravity="right|top"
android:layout_row="0"
android:text="Loading" />
</GridLayout>
package com.example.dcc;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
public class ActionItem extends ListActivity implements OnClickListener {
// Create buttons Globally so they are available to all methods
public static RSSFeed myRssFeed = null;
private Button btnEmail = null;
static WebView webView;
Button newsB;
Button loginB;
Button calB;
Button mailB;
Button photoB;
Button reportB;
Button actionB;
Button directoryB;
String currentItem;
TextView thisAction;
int currentLocation;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.action_item);
btnEmail = (Button) findViewById(R.id.email_button1);
newsB = (Button) findViewById(R.id.button1);
loginB = (Button) findViewById(R.id.button2);
calB = (Button) findViewById(R.id.button3);
mailB = (Button) findViewById(R.id.button4);
photoB = (Button) findViewById(R.id.button5);
reportB = (Button) findViewById(R.id.button6);
actionB = (Button) findViewById(R.id.button7);
directoryB = (Button) findViewById(R.id.button8);
thisAction = (TextView) findViewById(R.id.actionView);
newsB.setOnClickListener(this);
loginB.setOnClickListener(this);
calB.setOnClickListener(this);
mailB.setOnClickListener(this);
photoB.setOnClickListener(this);
reportB.setOnClickListener(this);
actionB.setOnClickListener(this);
directoryB.setOnClickListener(this);
btnEmail.setOnClickListener(this);
new MyTask().execute();
// this portion of the onCreate is dedicated to running the webView
// another webpage: http://creflodollarministries.org/
// main webpage: http://www.virtualDiscoveryCenter.net
webView = (WebView) findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://www.virtualDiscoveryCenter.net");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
Uri data = getIntent().getData();
if (savedInstanceState == null) {
String url = getIntent().getDataString();
// do something with this URL.
webView.loadUrl(url);
}
}
private class MyTask extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... arg0) {
try {
URL rssUrl = new URL(
"http://www.virtualdiscoverycenter.net/feed/");// http://www.virtualdiscoverycenter.net/feed/
SAXParserFactory mySAXParserFactory = SAXParserFactory
.newInstance();
SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
XMLReader myXMLReader = mySAXParser.getXMLReader();
RSSHandler myRSSHandler = new RSSHandler();
myXMLReader.setContentHandler(myRSSHandler);
InputSource myInputSource = new InputSource(rssUrl.openStream());
myXMLReader.parse(myInputSource);
myRssFeed = myRSSHandler.getFeed();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void result) {
if (myRssFeed != null) {
TextView feedTitle = (TextView) findViewById(R.id.feedtitle);
TextView feedDescribtion = (TextView) findViewById(R.id.feeddescribtion);
TextView feedPubdate = (TextView) findViewById(R.id.feedpubdate);
TextView feedLink = (TextView) findViewById(R.id.feedlink);
feedTitle.setText(myRssFeed.getTitle());
feedDescribtion.setText(myRssFeed.getDescription());
feedPubdate.setText(myRssFeed.getPubdate());
feedLink.setText(myRssFeed.getLink());
ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(
getApplicationContext(),
android.R.layout.simple_list_item_1,
myRssFeed.getList());
setListAdapter(adapter);
thisAction.setText(myRssFeed.getItem(0).getTitle());
} else {
TextView textEmpty = (TextView) findViewById(android.R.id.empty);
textEmpty.setText("No Feed Found!");
}
super.onPostExecute(result);
}
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// Uri feedUri = Uri.parse(myRssFeed.getItem(position).getLink());
// Intent myIntent = new Intent(Intent.ACTION_VIEW, feedUri);
// startActivity(myIntent);
String url = myRssFeed.getItem(position).getLink();
currentItem = myRssFeed.getItem(position).getTitle();
currentLocation = position;
thisAction.setText(currentItem);
webView.loadUrl(url);
}
public void sendEmail(View v) {
// The following code is the implementation of Email client
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
String[] address = { "bevins2012#hotmail.com" };
i.putExtra(android.content.Intent.EXTRA_EMAIL, address);
i.putExtra(android.content.Intent.EXTRA_SUBJECT, myRssFeed.getItem(currentLocation).getDescription());
i.putExtra(android.content.Intent.EXTRA_TEXT,
"Action Item from DCC app.");
startActivityForResult((Intent.createChooser(i, "Email")), 1);
}
public void onClick(View v) {
// this switch listens for any and all click actions in the app
// each case is a button in the menu.
switch (v.getId()) {
case R.id.button1:
startActivity(new Intent(this, AndroidRssReader.class));
break;
case R.id.button2:
startActivity(new Intent(this, MainActivity.class));
break;
case R.id.button3:
startActivity(new Intent(this, MainActivity.class));
break;
case R.id.button4:
startActivity(new Intent(this, EmailMain.class));
break;
case R.id.button5:
startActivity(new Intent(this, CustomizedListView.class));
break;
case R.id.button6:
startActivity(new Intent(this, LaunchActivity.class));
break;
case R.id.button7:
startActivity(new Intent(this, ActionItem.class));
break;
case R.id.button8:
startActivity(new Intent(this, MainActivity.class));
finish();
break;
case R.id.email_button1:
// Calling sendEmail from the activity class
sendEmail(v);
break;
}
}
}
Perhaps the auto-generated R class is messed up. Try to clean and rebuild your project by using Project > Clean... in Eclipse.
I'm a bit new to StackOverflow and I was wondering if I could have a bit of input on the following issue: I'm attempting to save a bit of data in a sqlite database but each time I attempt to do so the app force closes and I'm not sure why. I've cleaned the file and there are no issues. (I have no idea what I've done wrong - but something has been programmed incorrectly.)
JAVA:
import android.app.Activity;
import android.app.AlertDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TimePicker;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.text.format.DateFormat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;
import android.widget.TimePicker;
import com.nfc.linkingmanager.TimePickerFragment.TimePickedListener;
import java.util.Calendar;
public class AddEditCountry extends Activity implements TimePickedListener
{
private TextView mPickedTimeText;
private Button mPickTimeButton;
private long rowID;
private EditText nameEt;
private EditText capEt;
private EditText codeEt;
private TimePicker timeEt;
public static final String KEY_BUNDLE_TIME = "time";
public static final String KEY_BUNDLE_MIN = "min";
#Override
public void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.add_country); // where your_layout is the name of the xml file with the layout you want to use minus the .xml extention
//this layout must contain all of these views below that you are trying to initialize
nameEt = (EditText) findViewById(R.id.nameEdit);
capEt = (EditText) findViewById(R.id.capEdit);
codeEt = (EditText) findViewById(R.id.codeEdit);
timeEt = (TimePicker) findViewById(R.id.timeEdit);
Bundle extras = getIntent().getExtras();
if (extras != null)
{
rowID = extras.getLong("row_id");
nameEt.setText(extras.getString("name"));
capEt.setText(extras.getString("cap"));
codeEt.setText(extras.getString("code"));
String time = extras.getString("time");
String[] parts = time.split(":");
timeEt.setCurrentHour(Integer.valueOf(parts[0]));
timeEt.setCurrentMinute(Integer.valueOf(parts[1]));
timeEt.setIs24HourView(false);
}
Button saveButton =(Button) findViewById(R.id.saveBtn);
saveButton.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
if (nameEt.getText().length() != 0)
{
AsyncTask<Object, Object, Object> saveContactTask =
new AsyncTask<Object, Object, Object>()
{
#Override
protected Object doInBackground(Object... params)
{
saveContact();
return null;
}
#Override
protected void onPostExecute(Object result)
{
finish();
}
};
saveContactTask.execute((Object[]) null);
}
else
{
AlertDialog.Builder alert = new AlertDialog.Builder(AddEditCountry.this);
alert.setTitle(R.string.errorTitle);
alert.setMessage(R.string.errorMessage);
alert.setPositiveButton(R.string.errorButton, null);
alert.show();
}
}
});
}
private void saveContact()
{
DatabaseConnector dbConnector = new DatabaseConnector(this);
if (getIntent().getExtras() == null)
{
dbConnector.insertContact(nameEt.getText().toString(),
capEt.getText().toString(),
timeEt.getCurrentHour().toString() + ":"
+ timeEt.getCurrentMinute().toString(),
codeEt.getText().toString());
}
else
{
dbConnector.insertContact(nameEt.getText().toString(),
capEt.getText().toString(),
timeEt.getCurrentHour().toString() + ":"
+ timeEt.getCurrentMinute().toString(),
codeEt.getText().toString());
}
}
#Override
public void onTimePicked(Calendar time)
{
// display the selected time in the TextView
mPickedTimeText.setText(DateFormat.format("h:mm a", time));
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
<LinearLayout android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<EditText android:id="#+id/nameEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="#string/name_hint"
android:inputType="textPersonName|textCapWords"/>
<EditText android:id="#+id/capEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="#string/cap_hint"
android:inputType="textPersonName|textCapWords"/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Limit"
android:textColor="#ffffff"
android:textAppearance="?android:textAppearanceMedium" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="left"
android:textColor="#ffffff"
android:text="10MB" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="right"
android:textColor="#ffffff"
android:text="Unlimited Data" />
</LinearLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bandwidth Limit"
android:textColor="#ffffff"
android:textAppearance="?android:textAppearanceMedium" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="left"
android:textColor="#ffffff"
android:text="10kbs" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:textColor="#ffffff"
android:gravity="right"
android:text="Unlimited Bandwidth" />
</LinearLayout>
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceSmall" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WiFi Time Limit"
android:textColor="#ffffff"
android:textAppearance="?android:textAppearanceMedium" />
<TimePicker
android:id="#+id/timeEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1.0" />
<EditText
android:id="#+id/codeEdit"
android:inputType="textUri"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:lines="1"
android:hint="#string/code_hint"
android:imeOptions="actionNext" />
<Button android:id="#+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_gravity="center_horizontal"
android:text="#string/save_btn"/>
</LinearLayout>
</ScrollView>
PROBLEMS:
Cleaned - No Problems
LOGCAT:
03-29 13:23:28.950: D/OpenGLRenderer(20744): Enabling debug mode 0
03-29 13:23:33.780: D/AndroidRuntime(20744): Shutting down VM
03-29 13:23:33.780: W/dalvikvm(20744): threadid=1: thread exiting with uncaught exception (group=0x41f7b930)
03-29 13:23:33.790: E/AndroidRuntime(20744): FATAL EXCEPTION: main
03-29 13:23:33.790: E/AndroidRuntime(20744): android.app.SuperNotCalledException: Activity {com.app.gamedemo/com.app.gamedemo.AddEditCountry} did not call through to super.onCreate()
03-29 13:23:33.790: E/AndroidRuntime(20744): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2146)
03-29 13:23:33.790: E/AndroidRuntime(20744): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-29 13:23:33.790: E/AndroidRuntime(20744): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-29 13:23:33.790: E/AndroidRuntime(20744): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-29 13:23:33.790: E/AndroidRuntime(20744): at android.os.Handler.dispatchMessage(Handler.java:99)
03-29 13:23:33.790: E/AndroidRuntime(20744): at android.os.Looper.loop(Looper.java:137)
03-29 13:23:33.790: E/AndroidRuntime(20744): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-29 13:23:33.790: E/AndroidRuntime(20744): at java.lang.reflect.Method.invokeNative(Native Method)
03-29 13:23:33.790: E/AndroidRuntime(20744): at java.lang.reflect.Method.invoke(Method.java:511)
03-29 13:23:33.790: E/AndroidRuntime(20744): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-29 13:23:33.790: E/AndroidRuntime(20744): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-29 13:23:33.790: E/AndroidRuntime(20744): at dalvik.system.NativeStart.main(Native Method)
03-29 13:23:35.390: I/Process(20744): Sending signal. PID: 20744 SIG: 9
The problem is here in your onCreate()
#Override
public void onCreate(Bundle savedInstanceState)
{
nameEt = (EditText) findViewById(R.id.nameEdit);
capEt = (EditText) findViewById(R.id.capEdit);
codeEt = (EditText) findViewById(R.id.codeEdit);
timeEt = (TimePicker) findViewById(R.id.timeEdit);
You need to call setContentView() before trying to access your EditTexts and so on. Your Views "live" within your layout (xml file) so they are null until you inflate the layout. Change it to someting like
#Override
public void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.your_layout); // where your_layout is the name of the xml file with the layout you want to use minus the .xml extention
//this layout must contain all of these views below that you are trying to initialize
nameEt = (EditText) findViewById(R.id.nameEdit);
capEt = (EditText) findViewById(R.id.capEdit);
codeEt = (EditText) findViewById(R.id.codeEdit);
timeEt = (TimePicker) findViewById(R.id.timeEdit);
Edit
Just like the error says, you are trying to cast a TextView to a TimePicker. Here
timeEt = (TimePicker) findViewById(R.id.timeEdit);
(R.id.timeEdit) points to a TextView but here
private TimePicker timeEt;
you declare it as a TimePicker. If you want it to be a TimePicker then change it in your xml
`<TimePicker
android:id="#+id/timeEdit"
style="#style/StyleText"/> `
Also, you have multiple ids in your xml
android:id="#+id/codeText"
might want to change that
Second Edit
03-29 13:23:33.790: E/AndroidRuntime(20744): android.app.SuperNotCalledException: Activity {com.app.gamedemo/com.app.gamedemo.AddEditCountry} did not call through to super.onCreate()
This line in the logcat says it all. You didn't call super.onCreate(). Add the following line as the first line in your onCreate() method
super.onCreate(savedInstanceState);
When reading your logcat, look for where it says Fatal Exception. The next line should say what it is (Null Pointer Exception, Class Cast Exception, etc...) then look for the first line that references your package name and it will tell you where to start looking for the error. Ex. Main.java 57 tells you that whatever the fatal exception was occurs in your Main.java file at line 57. The problem may originally come from somewhere else but this is always a good place to start so you can narrow it down and post relevant code if you need help.
I'm trying to implement a TimePicker into my source code from the following tutorial:
http://www.lukehorvat.com/blog/android-time-picker-example/
However when implementing it in my app - I'm getting force close issues.
Any suggestions?
JAVA:
import android.app.Activity;
import android.app.AlertDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TimePicker;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.text.format.DateFormat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;
import android.widget.TimePicker;
import com.nfc.linkingmanager.TimePickerFragment.TimePickedListener;
import java.util.Calendar;
public class AddEditCountry extends Activity implements TimePickedListener
{
private TextView mPickedTimeText;
private Button mPickTimeButton;
private long rowID;
private EditText nameEt;
private EditText capEt;
private EditText codeEt;
private TimePicker timeEt;
public static final String KEY_BUNDLE_TIME = "time";
public static final String KEY_BUNDLE_MIN = "min";
#Override
public void onCreate(Bundle savedInstanceState)
{
nameEt = (EditText) findViewById(R.id.nameEdit);
capEt = (EditText) findViewById(R.id.capEdit);
codeEt = (EditText) findViewById(R.id.codeEdit);
timeEt = (TimePicker) findViewById(R.id.timeEdit);
Bundle extras = getIntent().getExtras();
if (extras != null)
{
rowID = extras.getLong("row_id");
nameEt.setText(extras.getString("name"));
capEt.setText(extras.getString("cap"));
codeEt.setText(extras.getString("code"));
timeEt.setCurrentHour(extras.containsKey(KEY_BUNDLE_TIME) ? extras.getInt(KEY_BUNDLE_TIME) : 0);
}
Button saveButton =(Button) findViewById(R.id.saveBtn);
saveButton.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
if (nameEt.getText().length() != 0)
{
AsyncTask<Object, Object, Object> saveContactTask =
new AsyncTask<Object, Object, Object>()
{
#Override
protected Object doInBackground(Object... params)
{
saveContact();
return null;
}
#Override
protected void onPostExecute(Object result)
{
finish();
}
};
saveContactTask.execute((Object[]) null);
}
else
{
AlertDialog.Builder alert = new AlertDialog.Builder(AddEditCountry.this);
alert.setTitle(R.string.errorTitle);
alert.setMessage(R.string.errorMessage);
alert.setPositiveButton(R.string.errorButton, null);
alert.show();
}
}
});
}
private void saveContact()
{
DatabaseConnector dbConnector = new DatabaseConnector(this);
if (getIntent().getExtras() == null)
{
dbConnector.insertContact(nameEt.getText().toString(),
capEt.getText().toString(),
timeEt.getCurrentHour().toString(),
codeEt.getText().toString());
}
else
{
dbConnector.updateContact(rowID,
nameEt.getText().toString(),
capEt.getText().toString(),
timeEt.getCurrentHour().toString(),
codeEt.getText().toString());
}
}
#Override
public void onTimePicked(Calendar time)
{
// display the selected time in the TextView
mPickedTimeText.setText(DateFormat.format("h:mm a", time));
}
}
ADD COUNTRY XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
<LinearLayout android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<EditText android:id="#+id/nameEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="#string/name_hint"
android:inputType="textPersonName|textCapWords"/>
<EditText android:id="#+id/capEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="#string/cap_hint"
android:inputType="textPersonName|textCapWords"/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Limit"
android:textColor="#ffffff"
android:textAppearance="?android:textAppearanceMedium" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="left"
android:textColor="#ffffff"
android:text="10MB" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="right"
android:textColor="#ffffff"
android:text="Unlimited Data" />
</LinearLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bandwidth Limit"
android:textColor="#ffffff"
android:textAppearance="?android:textAppearanceMedium" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="left"
android:textColor="#ffffff"
android:text="10kbs" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:textColor="#ffffff"
android:gravity="right"
android:text="Unlimited Bandwidth" />
</LinearLayout>
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceSmall" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WiFi Time Limit"
android:textColor="#ffffff"
android:textAppearance="?android:textAppearanceMedium" />
<TextView
android:id="#+id/text_picked_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<Button
android:id="#+id/button_pick_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="#id/text_picked_time"
android:text="Pick a time" />
<EditText
android:id="#+id/codeEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/code_hint"
android:imeOptions="actionNext"
android:inputType="textUri"
android:lines="1" >
<requestFocus />
</EditText>
<Button android:id="#+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_gravity="center_horizontal"
android:text="#string/save_btn"/>
</LinearLayout>
</ScrollView>
TIMEPICKERFRAGMENT.JAVA
package com.nfc.linkingmanager;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;
import android.widget.TimePicker;
import java.util.Calendar;
public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener
{
private TimePickedListener mListener;
#Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
// use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}
#Override
public void onAttach(Activity activity)
{
// when the fragment is initially shown (i.e. attached to the activity), cast the activity to the callback interface type
super.onAttach(activity);
try
{
mListener = (TimePickedListener) activity;
}
catch (ClassCastException e)
{
throw new ClassCastException(activity.toString() + " must implement " + TimePickedListener.class.getName());
}
}
#Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute)
{
// when the time is selected, send it to the activity via its callback interface method
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, hourOfDay);
c.set(Calendar.MINUTE, minute);
mListener.onTimePicked(c);
}
public static interface TimePickedListener
{
public void onTimePicked(Calendar time);
}
}
LOGCAT:
03-25 02:50:06.783: I/Adreno200-EGLSUB(27045): <ConfigWindowMatch:2165>: Format RGBA_8888.
03-25 02:50:06.783: D/memalloc(27045): ion: Mapped buffer base:0x5ca43000 size:614400 offset:0 fd:57
03-25 02:50:06.783: E/(27045): Can't open file for reading
03-25 02:50:06.783: E/(27045): Can't open file for reading
03-25 02:50:06.823: D/memalloc(27045): ion: Mapped buffer base:0x5d234000 size:614400 offset:0 fd:61
03-25 02:50:08.695: D/Activity(27045): Activity.onPause(), editTextTapSensorList size: 0
03-25 02:50:08.715: W/dalvikvm(27045): threadid=1: thread exiting with uncaught exception (group=0x4108b9d8)
03-25 02:50:08.715: E/AndroidRuntime(27045): FATAL EXCEPTION: main
03-25 02:50:08.715: E/AndroidRuntime(27045): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nfc.linkingmanager/com.nfc.linkingmanager.AddEditCountry}: java.lang.NullPointerException
03-25 02:50:08.715: E/AndroidRuntime(27045): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1960)
03-25 02:50:08.715: E/AndroidRuntime(27045): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
03-25 02:50:08.715: E/AndroidRuntime(27045): at android.app.ActivityThread.access$600(ActivityThread.java:127)
03-25 02:50:08.715: E/AndroidRuntime(27045): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
03-25 02:50:08.715: E/AndroidRuntime(27045): at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 02:50:08.715: E/AndroidRuntime(27045): at android.os.Looper.loop(Looper.java:137)
03-25 02:50:08.715: E/AndroidRuntime(27045): at android.app.ActivityThread.main(ActivityThread.java:4477)
03-25 02:50:08.715: E/AndroidRuntime(27045): at java.lang.reflect.Method.invokeNative(Native Method)
03-25 02:50:08.715: E/AndroidRuntime(27045): at java.lang.reflect.Method.invoke(Method.java:511)
03-25 02:50:08.715: E/AndroidRuntime(27045): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
03-25 02:50:08.715: E/AndroidRuntime(27045): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
03-25 02:50:08.715: E/AndroidRuntime(27045): at dalvik.system.NativeStart.main(Native Method)
03-25 02:50:08.715: E/AndroidRuntime(27045): Caused by: java.lang.NullPointerException
03-25 02:50:08.715: E/AndroidRuntime(27045): at com.nfc.linkingmanager.AddEditCountry.onCreate(AddEditCountry.java:73)
03-25 02:50:08.715: E/AndroidRuntime(27045): at android.app.Activity.performCreate(Activity.java:4701)
03-25 02:50:08.715: E/AndroidRuntime(27045): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051)
03-25 02:50:08.715: E/AndroidRuntime(27045): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1924)
03-25 02:50:08.715: E/AndroidRuntime(27045): ... 11 more
You don't have an element called TimeEdit in your xml. So when you try to set its text, it crashes with a null pointer exception.
where you define Timepicker
timeEt = (TimePicker) findViewById(R.id.timeEdit);
in your xml file.
Check your xml file and give different id to all.