App starts normally But crashes when I click Button "oneplus" - java

First of all let me tell you that I am a beginner at this... I started to try developing apps about a week ago.
When I start my app on a real device it starts normally But when I click the button "oneplus" it says that app isn't responding...
this app adds one number to the number in TextView .Earlier I faced same problem and thought it was because of fragments.So i removed them and made a very simple app But still the problem persists
activity_main.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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="0"
android:id="#+id/num"
android:textSize="70sp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="100dp"
android:text=" + 1 "
android:textSize="50sp"
android:id="#+id/plusone"
android:onClick="onClick"
/>
</RelativeLayout>`
mainactivity.java
package com.example.tjain.oneup;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onClick(View v) {
final TextView number = (TextView) findViewById(R.id.num);
int original = Integer.parseInt(number.getText().toString());
int newnum = original + 1;
number.setText(newnum);
}
}
I am facing this error in other apps too. Maybe I am repeating my mistake . Please point it out. Thanks in advance

As I doubt for two scenario in your onClick for Exception
NumberFormat Exception
ResourceNotFound Exception
For First,
try
{
int original = Integer.parseInt(number.getText().toString());
}catch(Exception ex)
{
ex.printStacktrace();
}
For Second,
Because int is not a argument for TextView's setText (only if its not a part of String resource id), as it will find with resource id not accepting as String value. and obvious Resource Not Found exception
you have to convert int to String,
number.setText(String.valueOf(newnum));

What I would recommend doing is adding your UI elements at the class level of your activity so you have one TextView object and one Button object, that way you only have to search for the resource once and you can add a click listener to the button itself like this:
public class MainActivity extends Activity{
private TextView mNumberTextView;
private Button mOnePlusButton;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNumberTextView = findViewbyId(R.id.num);
mOnePlusButton = findViewbyId(R.id.plusone);
mOnePlusButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
int original = Integer.parseInt(mNumberTextView.getText().toString());
mNumberTextView.setText(original + 1);
}
});
}
}
Edit: Since you're still new at this, it's always a good idea to check the documentation.

You should use
number.setText(+newnum);
instead
number.setText(newnum);

Related

Youtube player custom app force closes every time

I'm now trying something with a youtube custom player. I'm trying to have it play a video containing a playlist of a certain game's original soundtracks.
The thing is, everything was done by the book (again), yet I still have this concurring problem of force stopping every time I tried to open the APK. Here are the code :
XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context=".MainActivity">
<view
android:id="#+id/YoutubePlayView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/buttonPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Play Video" />
</LinearLayout>
Java :
package my.videoplayerapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
YouTubePlayerView mYoutubePlayerView;
Button PlayVidButton;
YouTubePlayer.OnInitializedListener mOnInitializedListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate: Starting.");
PlayVidButton = findViewById(R.id.buttonPlay);
mYoutubePlayerView = findViewById(R.id.YoutubePlayView);
mOnInitializedListener = new YouTubePlayer.OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
Log.d(TAG, "onClick: Initialization Done.");
youTubePlayer.loadVideo("DBToMwdYBME");
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Log.d(TAG, "onClick: Initialization Failed.");
}
};
PlayVidButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: Initializing Youtube Player.");
mYoutubePlayerView.initialize((YoutubeVidPlayerConfig.getApiKey()), mOnInitializedListener);
Log.d(TAG, "onClick: Initialization Done.");
}
});
}
}
Logcat, linked : https://drive.google.com/open?id=1w5TfCIfyCWCrOZmrjb0lzTpndoQc2SJ0
I'm trying to actually be able to play the video through the button, I know the method of playing the next video or even playing sequence of videos, I just don't know why it keeps on crashing as I speak right now...
Any help would be appreciated in advance!
You have a view with the id of "YoutubePlayView" but your class is called "YoutubePlayerView". Change one of them and it should work (well it shouldn't force close at this spot).

Android Studio error: #Override not applicable to field

I am fairly new to android development and as my first app I want to make a flashlight app. So the first steps I want to do is to make a button in the center such that it changes it's text to "ON" and "OFF" alternately after every click. I made the java code but it Android studio gives me this error: '#Override' not applicable to field. Here is my java code:
package com.danielfernandzz.flashlight;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
public boolean switchState = false;
Button switchbutton = (Button) findViewById(R.id.Switch);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Switched(View v){
if(!switchState){
switchState = true;
switchbutton.setText("OFF");
}else{
switchState = false;
switchbutton.setText("ON");
}
}
}
And here is my xml code (in case you need it):
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.danielfernandzz.flashlight.MainActivity">
<Button
android:id="#+id/Switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="8dp"
android:onClick="Switched"
android:text="ON"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
I tried commenting out the #Override and no error came. But when I ran the app, it crashed so I assume that the app crashed because #Override wasn't there?
I don't understand why this is happening to me, I have seen other questions but their error is something different.
NOTE: I am using the latest version Android Studio 3.0
try this
1.move you switchbutton = (Button) findViewById(R.id.Switch); inside your onCreate() method
2.place #Override before onCreate()
sample code
public class MainActivity extends AppCompatActivity {
public boolean switchState = false;
Button switchbutton ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
switchbutton = (Button) findViewById(R.id.Switch);
}
public void Switched(View v){
if(!switchState){
switchState = true;
switchbutton.setText("OFF");
}else{
switchState = false;
switchbutton.setText("ON");
}
}
}
As according #Jerrol you can place the #Override before onCreate. There is no need to place it before variable initialization.Could you give us the crash log that you are getting after removal.

TextView and scale

I use this code
TextView.animate().setDuration(0).scaleX(scale).scaleY(scale).start();
When scale value increase to some point, it make TextView disappear. I dont know why, and how to prevent it?
[Edit] Attach my test code
[test_text_scale.xml] It is Layout xml file for TestTextScale.java
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:orientation="vertical">
<TextView
android:id="#+id/tv_test_scale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Test" />
<Button
android:id="#+id/bt_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toEndOf="#+id/bt_down"
android:layout_toRightOf="#+id/bt_down"
android:text="Up" />
<Button
android:id="#+id/bt_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Down" />
</RelativeLayout>
[TestTextScale.java]
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TestTextScale extends AppCompatActivity {
// View
private TextView mTvTestZoom;
private Button mBtUp, mBtDown;
// Model
private int mCurrentScale = 1;
// OnClick listener
private View.OnClickListener mOnClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bt_up : {
upScale();
setText();
} break;
case R.id.bt_down : {
downScale();
setText();
} break;
}
}
};
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_text_scale);
initView();
initEvent();
}
private void initView() {
mTvTestZoom = (TextView) findViewById(R.id.tv_test_scale);
mBtUp = (Button) findViewById(R.id.bt_up);
mBtDown = (Button) findViewById(R.id.bt_down);
}
private void initEvent() {
mBtDown.setOnClickListener(mOnClickListener);
mBtUp.setOnClickListener(mOnClickListener);
}
private void upScale() {
mCurrentScale += 1;
mTvTestZoom.animate().setDuration(0).scaleX(mCurrentScale).scaleY(mCurrentScale).start();
}
private void downScale() {
mCurrentScale -= 1;
mTvTestZoom.animate().setDuration(0).scaleX(mCurrentScale).scaleY(mCurrentScale).start();
}
private void setText() {
mTvTestZoom.setText(mCurrentScale + "");
}
}
This may happen because the textview exceeds the layout bounds of its parent. To overcome this, simple put android:clipChildren="false" in the xml description of the immediate parent of the textview. You may also need to do it for their parents too.
EDIT:
Upon testing the code myself, I found that the textview did disappear with following log message:
E/OpenGLRenderer: Font size too large to fit in cache. width, height = 635, 1028
This is due to a possible issue in the Android Hardware acceleration modules. One of the ways to avoid this is:
mTvTestZoom.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
This works well and the textView does not disappear after a certain size but, since it disables hardware acceleration for the specific textview, it may lose antialiasing.

SeekBar Android crash Java

I just started learning android development using android studio, and i finished the "Starting another activity" , I tried practicing on what I've learned by changing the code a bit and messing with it.
(The tutorial was about displaying text sent by another activity)
So i added a seekBar in order to change the text size. After i send the text to another activity using an intent it crashes, but if i remove the seekBar listener , it works fine.
DisplayMessageActivity.java:
package com.keddy.myfirstapp;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.content.Intent;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
public class DisplayMessageActivity extends ActionBarActivity {
public SeekBar _seekbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Getting the intent received by some other activity
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
//Text view initialization
final TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
//Showing text on screen
setContentView(textView);
_seekbar = (SeekBar)findViewById(R.id.seekBar1);
_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Toast.makeText(getApplicationContext(),"Progress Changing",Toast.LENGTH_SHORT).show();
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
Toast.makeText(getApplicationContext(),"Started Tracking",Toast.LENGTH_SHORT).show();
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(getApplicationContext(),"Progress Stopped Changing",Toast.LENGTH_SHORT).show();
}
});
}
I included the onCreate() method only , because that was the only thing I've changed.
activity_display_message.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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.keddy.myfirstapp.DisplayMessageActivity">
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/seekBar1"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:indeterminate="false"
android:max="100"
/>
</RelativeLayout>
I've searched around and saw the reason was NullPointerException , but i dont know how to fix it , since i have no experience with Java nor Android Development.
if you find a solution please provide:
Code Example
How to avoid it again
Why did it happen
Any help whatsoever will be appreciated.
Change
setContentView(textView);
to
setContentView(R.layout.activity_display_message);
You must setContentView(...) and after add _seekbar = (SeekBar)findViewById(R.id.seekBar1);
The reason is you are adding textview in your Content
i.e. setContentView(textview);
Your activity is unable to find seekbar1 view. This is the reason why your app is crashing.
Instead of adding textview in Javacode add in xml and use it same way you are using seekbar, and change setContentView(textView) to setContentView(R.layout.your_xml_file_name);

Methods in extended class are not working

I created a menu, where you can swipe up and down. I created this menu as another activity. Now, I need this menu to be added to on other activities.
Following is the code of my menu(SlidingDrawer)
Java
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class DropDownMenu extends Activity {
private TextView addInquiry, addEvent, additionalInfo, addToContacts;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drop_down_menu);
//Intializing instance variables
addInquiry = (TextView)findViewById(R.id.menu_add_inquiry);
addEvent = (TextView)findViewById(R.id.menu_add_event);
additionalInfo = (TextView)findViewById(R.id.menu_additional_info);
addToContacts = (TextView)findViewById(R.id.menu_add_to_contacts);
//Register the Listeners
addInquiry.setOnClickListener(new AddInquiryEvent());
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.drop_down_menu, menu);
return true;
}
//Test Button
private class AddInquiryEvent implements OnClickListener
{
#Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
Intent intent = new Intent(DropDownMenu.this,NewLead.class);
startActivity(intent);
}
}
}
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<SlidingDrawer
android:id="#+id/SlidingDrawer"
android:layout_width="wrap_content"
android:layout_height="250dip"
android:layout_alignParentBottom="true"
android:content="#+id/contentLayout"
android:handle="#+id/slideButton"
android:orientation="vertical" >
<Button
android:id="#+id/slideButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:drawable/bottom_bar" >
</Button>
<LinearLayout
android:id="#+id/contentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip"
android:background="#cbcbcc" >
<TextView
android:id="#+id/menu_add_inquiry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="#string/add_inquiry"
android:textColor="#ffffff"
android:clickable="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
Following is the Code of the other activity
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/sales_inqury_main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".SalesInqury" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:text="#string/sales_inqury"
android:textSize="40sp" />
<include layout = "#layout/activity_drop_down_menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Java
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class SalesInqury extends DropDownMenu {
private ImageView addNewSalesInqury;
private RelativeLayout salesInquryMainLayout;
private TextView testEditSales;
#Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sales_inqury);
//Intializing instance variables
addNewSalesInqury = (ImageView)findViewById(R.id.add_new_sales_inqury_btn);
salesInquryMainLayout = (RelativeLayout)findViewById(R.id.sales_inqury_main_layout);
testEditSales = (TextView)findViewById(R.id.testWord);
}
}
But, there is an issue. Even thougn I can open the menu in this other activity, I can't click on it's Buttons (TextViews) and navigate to other activities. Why is this?
I think it's because after you've set a contentView in your DropDownMenu activity and bound the listener to the button, in SalesInquiry you set a different contentView. Although this includes the menu-layout, the Views are created anew, so there's no Listener bound to the button anymore.
A solution would either be to specify the menu callbacks in the layout xml via android:onClick="..." or by having a separate method in DropDownMenu that adds the Listener and that you call from your SalesInquiry class after setting the content view.
Example 1, specifying callback in XML
Add android:onClick="onMenuItemClicked" to menu item TextView
<TextView
android:id="#+id/menu_add_inquiry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="#string/add_inquiry"
android:textColor="#ffffff"
android:clickable="true"
android:onClick="onMenuItemClicked"
android:textAppearance="?android:attr/textAppearanceMedium"/>
Add this method to DropDownMenu class and remove the AddInquiryEvent class and the registering of the listeners.
public void onMenuItemClicked(View view) {
switch (view.getId()) {
case R.id.menu_add_inquiry:
Intent intent = new Intent(DropDownMenu.this,NewLead.class);
startActivity(intent);
break;
case R.id.menu_other:
// handle other menu item
break;
// ... and so on ...
default:;
}
}
Example 2, bind listeners in a separate method
In DropDownMenu move the registering of the Listeners to a separate method:
protected void registerListeners() {
//Register the Listeners
findViewById(R.id.menu_add_inquiry).setOnClickListener(new AddInquiryEvent());
}
Note, that you have to find the view again, as the one kept in the local variable is the wrong one, after SalesInquiry set it's content view.
Call the method in SalesInquiry after setting the content view.
setContentView(R.layout.activity_sales_inqury);
registerListeners();
I'm not sure. but can you please try with extending the DropDownMenu-Activity instead of Activity.
public class NewActivity extends DropDownMenu {
// override which you want to override
}
And make sure DropDownMenu in such a way that you can extends what you want to implements. Hope you have got my point.
Consistency Issue (Recommendation)
There is a HUGE misnomer in your class name, you should NOT call an Activity DropDownMenu.
This is confusing, you should instead call it DropDownActivity or something like that. Also do you really need to use an Activity? You do realize a View can still listen to the click of a button right? Not only an Activity can listen to button clicks. If you encapsulate all of this in a View and have a dedicated listener for that view, then you wouldn't have any need for another Activity.
Possible Solution
It's likely related to the activity/component you have registered to listen to the buttons is not correct. Validate your code so that you can at least get the correct response of the onClick.
The problem is that you are attaching the listener to addInquiry in the DropDownMenu:
//Register the Listeners
addInquiry.setOnClickListener(new AddInquiryEvent());
This listener is not attached to the TextView in the extended class, since the setContentView is called and layout is refreshed.
Possible solution, if you are not using the DropDownMenu activity on its own then simply (remove setContentView):
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //in DropDownMenu
// setContentView(R.layout.activity_drop_down_menu);
...
...
Not the best solution but would work.
Update: Better Solution
(1) Let the subclass decide which layout to show. This layout must contain the menu (which is true in your case).
public class DropDownMenu extends Activity {
private TextView addInquiry, addEvent, additionalInfo, addToContacts;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_setContentView();
//Intializing instance variables
addInquiry = (TextView)findViewById(R.id.menu_add_inquiry);
addEvent = (TextView)findViewById(R.id.menu_add_event);
additionalInfo = (TextView)findViewById(R.id.menu_additional_info);
addToContacts = (TextView)findViewById(R.id.menu_add_to_contacts);
//Register the Listeners
addInquiry.setOnClickListener(new AddInquiryEvent());
}
protected void _setContentView() {
setContentView(R.layout.activity_drop_down_menu);
}
...
...
}
#override the _setContentView method so that we do not set the view twice.
public class SalesInqury extends DropDownMenu {
...
...
#Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
//Intializing instance variables
addNewSalesInqury = (ImageView)findViewById(R.id.add_new_sales_inqury_btn);
salesInquryMainLayout = (RelativeLayout)findViewById(R.id.sales_inqury_main_layout);
testEditSales = (TextView)findViewById(R.id.testWord);
}
#Override
protected void _setContentView() {
// need to make sure this layout contains the menu (otherwise NullPointerException may arise)
setContentView(R.layout.activity_sales_inqury);
}
}

Categories