my app crashes whenever i click the button - android

whenever i click the increment button while running the app on my device my app forces unexpectedly
this is my activity_main.xml code
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".MainActivity"
>
<RelativeLayout
android:padding="20dp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center_vertical"
>
<EditText
android:id="#+id/name_text_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:inputType="textCapWords"
></EditText>
<TextView
android:layout_centerVertical="true"
android:id="#+id/heading1"
style="#style/HeaderTextStyle"
android:text="Toppings"
android:layout_below="#id/name_text_field"
/>
<CheckBox
android:layout_below="#id/heading1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/whipped_cream"
android:textSize="16sp"
android:paddingLeft="24dp"
android:layout_marginTop="20dp"
android:text="Whipped Cream"
/>
<CheckBox
android:layout_marginTop="20dp"
android:layout_below="#id/whipped_cream"
android:id="#+id/chocolate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="chocolate"
android:textSize="16sp"
android:paddingLeft="24dp"
/>
<TextView
android:layout_below="#id/chocolate"
android:id="#+id/quantity_text_view"
style="#style/HeaderTextStyle"
android:text="Quantity"
android:layout_marginBottom="20dp"
/>
<Button
android:layout_below="#id/quantity_text_view"
android:id="#+id/decrement_button"
android:layout_width="48dp"
android:layout_height="48dp"
android:onClick="decrement"
android:text="-"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="48dp"
android:paddingLeft="10dp"
android:layout_below="#id/quantity_text_view"
android:paddingRight="10dp"
android:textSize="15sp"
android:layout_toRightOf="#id/decrement_button"
android:id="#+id/initial_qty"
android:gravity="center_vertical"
android:text="1"
/>
<Button
android:layout_toRightOf="#id/initial_qty"
android:layout_below="#id/quantity_text_view"
android:id="#+id/increment_button"
android:onClick="increment"
android:layout_width="48dp"
android:layout_height="48dp"
android:text="+"
/>
<Button
android:id="#+id/submit_button"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="order"
android:onClick="submitOrder"
android:gravity="center_vertical"
android:layout_below="#id/decrement_button"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
android:id="#+id/order_summary_text_view"
android:textAllCaps="true"
android:textStyle="bold"
android:textSize="16sp"
android:layout_below="#id/submit_button"
/>
</RelativeLayout>
</ScrollView>
and this is my MainActivity.java file
package com.orton.birthdaycard;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import java.text.NumberFormat;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
int quantity=1;
private void increment(View view)
{
if(quantity==100)
return;
else
quantity++;
displayQuantity(quantity);
}
private void decrement(View view)
{
if(quantity==1)
return;
else
quantity--;
displayQuantity(quantity);
}
private void displayQuantity(int qty)
{
TextView quantityTextView=(TextView) findViewById(R.id.initial_qty);
quantityTextView.setText(String.valueOf(quantity));
Log.v("MainActivity","the quantity is " + quantity);
}
int basePrice;
private int calculatePrice(boolean hasWhippedCream,boolean hasChocolate)
{
basePrice = 5;
if(hasWhippedCream==true)
basePrice += 1;
if(hasChocolate==true)
basePrice +=2 ;
return basePrice=basePrice*quantity;
}
String priceMessage="";
private void submitOrder(View view)
{
EditText nameField = (EditText) findViewById(R.id.name_text_field);
String name = nameField.getText().toString();
CheckBox whippedCream = (CheckBox) findViewById(R.id.whipped_cream);
boolean hasWhippedCream = whippedCream.isChecked();
CheckBox chocolate = (CheckBox) findViewById(R.id.chocolate);
boolean hasChocolate = chocolate.isChecked();
int price=calculatePrice(hasWhippedCream,hasChocolate);
String orderSummary=createOrderSummary(name,price,hasWhippedCream,hasChocolate);
displayMessage(orderSummary);
}
private void displayMessage(String orderSummary)
{
TextView summary= (TextView) findViewById(R.id.order_summary_text_view);
summary.setText(""+orderSummary);
}
private String createOrderSummary(String name, int price, boolean hasWhippedCream, boolean hasChocolate)
{
String priceMessage = "Name :" + name;
if(hasWhippedCream)
priceMessage += "\nWhipped Cream Added" ;
if(hasChocolate)
priceMessage += "\nChocolate Added" ;
priceMessage+="\nQuantity : "+quantity;
priceMessage+="\nTotal : $"+price;
priceMessage+="Thank You!" ;
return priceMessage;
}
}
this is debugging report
05-23 22:14:45.695 29736-29736/com.orton.birthdaycard E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.orton.birthdaycard, PID: 29736
java.lang.IllegalStateException: Could not find method increment(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'increment_button'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:5612)
at android.view.View$PerformClick.run(View.java:22285)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

Your method must use the public modifier:
public void increment(View view)
{
if(quantity==100)
return;
else
quantity++;
displayQuantity(quantity);
}

Do this
increment_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
}
});
instead of android:onClick="increment"

Related

RecyclerView with CardView is laging and not scrolls smoothly

Trying to load around 500 rows of data in recycler view, but it is lagging while scrolling.
Data doesn't include any kind of images, it is just plain text. Thus could not find any reason of laging.
The xml and java code used is as follows:-
xml
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/markeListCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardPreventCornerOverlap="true"
android:layout_alignParentTop="true"
card_view:cardUseCompatPadding="true"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
android:layout_marginBottom="14dp"
android:paddingBottom="#dimen/_150sdp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/_125sdp"
android:background="#drawable/compltedtlist"
android:layout_gravity="center">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="#dimen/_30sdp"
android:layout_marginTop="#dimen/_10sdp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/_5sdp"
android:text="School Name :"
android:singleLine="true"
android:inputType="textPostalAddress"
android:imeOptions="actionNext"
android:textStyle="bold"
android:textSize="#dimen/_10ssp"
android:textColor="#0E9CE0"
android:paddingLeft="#dimen/_10sdp"
android:id="#+id/scndprsnname" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/_10sdp"
android:maxLines="1"
android:text="Divisional Public School"
android:ems="10"
android:singleLine="true"
android:textColor="#000"
android:imeOptions="actionNext"
android:textSize="#dimen/_10ssp"
android:id="#+id/scholnametxt" >
</TextView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_30sdp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/_5sdp"
android:text="District :"
android:singleLine="true"
android:inputType="textPostalAddress"
android:imeOptions="actionNext"
android:textStyle="bold"
android:textSize="#dimen/_10ssp"
android:textColor="#0E9CE0"
android:paddingLeft="#dimen/_10sdp"
android:id="#+id/detaildadresedit" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/_38sdp"
android:maxLines="1"
android:text="Aleem Ahmed"
android:ems="10"
android:singleLine="true"
android:textColor="#000"
android:imeOptions="actionNext"
android:textSize="#dimen/_10ssp"
android:id="#+id/tehsilname" >
</TextView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="#dimen/_30sdp"
android:layout_marginTop="#dimen/_48sdp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/_5sdp"
android:text="Tehsil :"
android:singleLine="true"
android:inputType="textPostalAddress"
android:imeOptions="actionNext"
android:textStyle="bold"
android:textSize="#dimen/_10ssp"
android:textColor="#0E9CE0"
android:paddingLeft="#dimen/_10sdp"
android:id="#+id/pcname" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/_45sdp"
android:maxLines="1"
android:text="Lahore"
android:ems="10"
android:singleLine="true"
android:textColor="#000"
android:imeOptions="actionNext"
android:textSize="#dimen/_10ssp"
android:id="#+id/citytxt" >
</TextView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="#dimen/_30sdp"
android:layout_marginTop="#dimen/_65sdp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/_5sdp"
android:text="Address :"
android:textStyle="bold"
android:ems="10"
android:singleLine="true"
android:textColor="#0E9CE0"
android:imeOptions="actionNext"
android:textSize="#dimen/_10ssp"
android:paddingLeft="#dimen/_10sdp"
android:id="#+id/provnceedit" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/_10sdp"
android:layout_marginLeft="-40dp"
android:maxLines="1"
android:text="h#10 stret no 17 sabzar lahore"
android:ems="30"
android:singleLine="true"
android:textColor="#000"
android:imeOptions="actionNext"
android:textSize="#dimen/_10ssp"
android:id="#+id/addrestxt" >
</TextView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="#dimen/_50sdp"
android:layout_marginTop="#dimen/_70sdp"
android:layout_gravity="center"
android:paddingTop="#dimen/_10sdp"
android:gravity="center"
android:textAlignment="center"
android:layout_marginLeft="#dimen/_170sdp"
android:layout_marginRight="#dimen/_10sdp"
android:orientation="horizontal">
<Button
android:id="#+id/uploadbtn"
android:layout_width="#dimen/_140sdp"
android:layout_height="#dimen/_30sdp"
android:background="#drawable/yelowbtn"
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="#dimen/_10sdp"
android:textAlignment="center"
android:layout_marginTop="#dimen/_20sdp"
android:layout_marginBottom="#dimen/_15sdp"
android:gravity="center"
android:text="Stage 2"
android:textColor="#000" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<!--
</LinearLayout>-->
adapter
import android.animation.Animator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.preference.PreferenceManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.offlinemap.R;
import com.offlinemap.form.FormStage2;
import com.offlinemap.form.FormToUpdateData;
import java.util.ArrayList;
import java.util.List;
public class Stage2RecyclerViewAdapterViewCompleteList extends RecyclerView.Adapter<Stage2RecyclerViewAdapterViewCompleteList.SearchViewHolder> {
private Context mCtx;
private List<ModeClassCompleteListStage2> searcList;
View thumb1View;
private String jobid;
private Animator mCurrentAnimator;
private int mShortAnimationDuration;
private modelclascompletelist model;
String job;
private Matrix matrix = new Matrix();
Matrix savedMatrix = new Matrix();
//ImageView image;
private ArrayList<String> list = new ArrayList<String>();
String pos;
// We can be in one of these 3 states
static final int NONE = 0;
static final int DRAG = 1;
/*static final int ZOOM = 2;*/
private static final int ZOOM = 2;
int mode = NONE;
// Remember some things for zooming
PointF start = new PointF();
PointF mid = new PointF();
float oldDist = 1f;
String savedItemClicked,scholid,tehsilo ,distrcto ,province ,sgtsID ;
SharedPreferences preferences;
public Stage2RecyclerViewAdapterViewCompleteList(Context mCtx, List<ModeClassCompleteListStage2> searcList)
{
this.mCtx = mCtx;
this.searcList = searcList;
}
#Override
public Stage2RecyclerViewAdapterViewCompleteList.SearchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(mCtx);
View view = inflater.inflate(R.layout.carview_introcomplete, null);
return new Stage2RecyclerViewAdapterViewCompleteList.SearchViewHolder(view);
}
#SuppressLint("SetTextI18n")
#Override
public void onBindViewHolder(final Stage2RecyclerViewAdapterViewCompleteList.SearchViewHolder holder, final int position)
{
final ModeClassCompleteListStage2 model = searcList.get(position);
holder.adres.setText(model.getDetailsadres());
holder.scholname.setText(model.getScholname());
holder.district.setText(model.getDistrict());
holder.city.setText(model.getTehsil());
/* Glide.with(mCtx)
.load(model.getImage1())
.into(holder.image);*/
if(model.getStg_id().equals("0")){
holder.edit.setText("Add");
}
else {
holder.edit.setText("Update");
}
holder.edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
/* String mtoid = searcList.get(position).get();*/
scholid = searcList.get(position).getScholid();
tehsilo = searcList.get(position).getTehsil();
distrcto = searcList.get(position).getDistrict();
province = searcList.get(position).getProvince();
sgtsID = searcList.get(position).getStg_id();
preferences = PreferenceManager.getDefaultSharedPreferences(mCtx);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("scholid", scholid);
editor.putString("thsillo", tehsilo);
editor.putString("distrctto", distrcto);
editor.putString("prov", province);
editor.putString("sgts",sgtsID);
editor.apply();
if(holder.edit.getText().toString().equals("Add")) {
Intent intent = new Intent(mCtx.getApplicationContext(), FormStage2.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
mCtx.getApplicationContext().startActivity(intent);
}
else {
Intent intent = new Intent(mCtx.getApplicationContext(), FormToUpdateData.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
mCtx.getApplicationContext().startActivity(intent);
}
}
});
}
#Override
public int getItemCount() {
/*if (searcList.size() == 0) {
.setVisibility(View.INVISIBLE);
} else {
mRecyclerView.setVisibility(View.VISIBLE);
}*/
return searcList.size();
}
class SearchViewHolder extends RecyclerView.ViewHolder {
/*TextView movingitem, pickup, dropoff,currentbid,date,edit,delete,acceptbid,message,invitetransport,viewquote,similarjob,mesagecount,simlarcount;
ImageView image,largeimage,editimage;
CardView cardView;
ImageView delicon,similaricon,inviteicon,mainimageicon,mesageicon;*/
TextView adres, city, scholname, principalname, secondpersonname, entryno,district;
Button edit;
public SearchViewHolder(View itemView)
{
super(itemView);
adres = itemView.findViewById(R.id.addrestxt);
scholname = itemView.findViewById(R.id.scholnametxt);
edit= itemView.findViewById(R.id.uploadbtn);
district = itemView.findViewById(R.id.tehsilname);
city = itemView.findViewById(R.id.citytxt);
/* movingitem = itemView.findViewById(R.id.MovingItemServlivep);
pickup = itemView.findViewById(R.id.pickupservlivep);
dropoff = itemView.findViewById(R.id.DropOffServlivep);
image = itemView.findViewById(R.id.imagecardlivep);
currentbid = itemView.findViewById(R.id.BidServlivep);
date = itemView.findViewById(R.id.dateservlivep);
edit = itemView.findViewById(R.id.editjob);
delete = itemView.findViewById(R.id.deletejob);
// similarjob = itemView.findViewById(R.id.similarjobtext);
acceptbid = itemView.findViewById(R.id.biddetailslivep);
viewquote = itemView.findViewById(R.id.offerpricelivep);
// invitetransport = itemView.findViewById(R.id.invitetransportertext);
mesagecount = itemView.findViewById(R.id.countermsgs);
// simlarcount = itemView.findViewById(R.id.countersimlar);
editimage= itemView.findViewById(R.id.imageView98);
mesageicon= itemView.findViewById(R.id.imagy98);
delicon= itemView.findViewById(R.id.imagy971);
cardView = itemView.findViewById(R.id.markeListCard);
// similaricon= itemView.findViewById(R.id.imagy981);
// inviteicon= itemView.findViewById(R.id.ima98);
mainimageicon= itemView.findViewById(R.id.imagecardlivep);*/
}
/* public void setFilter(List<UserInfo> newList){
data=new ArrayList<>();
data.addAll(newList);
notifyDataSetChanged();
}*/
}
}

How to indicate an error if an user inputs letters into the edit text for age? (Android Studio)

I am trying to make an app which intakes student details. Part of that detail is the students age which is supposed to be only a number input. If letters are entered into the edit text field, the app must indicate an error.
I have the coding below, however it seems like there are no changes to the app as it still crashes whenever I enter a letter for age.
//xml content
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="40dp"
android:background="#F0F8FF"
>
<TableLayout
android:id="#+id/add_table"
android:layout_width="match_parent"
android:layout_height="606dp"
android:paddingTop="40dp">
<TableRow>
<TextView
android:layout_marginLeft="25dp"
android:padding="3dip"
android:text="Student ID:" />
<EditText
android:id="#+id/sid"
android:layout_width="190dp"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView
android:layout_marginLeft="25dp"
android:padding="3dip"
android:text="First Name:" />
<EditText
android:id="#+id/fn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="150dip" />
</TableRow>
<TableRow>
<TextView
android:layout_marginLeft="25dp"
android:padding="3dip"
android:text="Last Name:" />
<EditText
android:id="#+id/ln"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="150dip" />
</TableRow>
<TableRow>
<TextView
android:layout_marginLeft="25dp"
android:padding="3dip"
android:layout_marginTop="5dp"
android:text="Gender:" />
<RadioGroup
android:id="#+id/ge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<RadioButton
android:id="#+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.9"
android:scaleY="0.9"
android:text="Male" />
<RadioButton
android:id="#+id/female"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleX="0.9"
android:scaleY="0.9"
android:text="Female" />
</RadioGroup>
</TableRow>
<TableRow>
<TextView
android:layout_marginLeft="25dp"
android:padding="3dip"
android:text="Course Study:" />
<EditText
android:id="#+id/cs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="150dip" />
</TableRow>
<TableRow>
<TextView
android:layout_marginLeft="25dp"
android:inputType="number"
android:digits="0123456789"
android:padding="3dip"
android:text="Age:" />
<EditText
android:id="#+id/ag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="150dip" />
</TableRow>
<TableRow>
<TextView
android:layout_marginLeft="25dp"
android:padding="3dip"
android:text="Address:" />
<EditText
android:id="#+id/ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="150dip" />
</TableRow>
<Button
android:id="#+id/add_button"
android:layout_width="207dp"
android:layout_height="wrap_content"
android:layout_marginLeft="118dp"
android:layout_marginRight="52dp"
android:layout_marginTop="14dp"
android:padding="6dip"
android:text="Add Student" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
app:srcCompat="#mipmap/man" />
</TableLayout>
//Java
package com.user.project3;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class Addrecord extends AppCompatActivity {
DatabaseManager myDb;
EditText sid, fn, ln, cs, ag, ad;
RadioGroup radioGenderGroup;
RadioButton radioGenderButton;
Button btnAddStudent;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
myDb = new DatabaseManager(this);
sid = (EditText)findViewById(R.id.sid);
fn = (EditText)findViewById(R.id.fn);
ln = (EditText)findViewById(R.id.ln);
cs = (EditText)findViewById(R.id.cs);
ag = (EditText)findViewById(R.id.ag);
ad = (EditText)findViewById(R.id.ad);
btnAddStudent = (Button)findViewById(R.id.add_button);
AddStudentRecord();
}
public void AddStudentRecord() {
btnAddStudent.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
radioGenderGroup = (RadioGroup) findViewById(R.id.ge);
int selectedid = radioGenderGroup.getCheckedRadioButtonId();
radioGenderButton = (RadioButton) findViewById(selectedid);
boolean isInserted = myDb.insertDataStudent(
Integer.parseInt(sid.getText().toString()),
fn.getText().toString(),
ln.getText().toString(),
radioGenderButton.getText().toString(),
cs.getText().toString(),
Integer.parseInt(ag.getText().toString()),
ad.getText().toString()
);
String strNumber=ag.getText().toString().trim();
if(TextUtils.isEmpty(strNumber) || Integer.parseInt(strNumber)>100){
Toast.makeText(Addrecord.this,"Please input a number",Toast.LENGTH_LONG).show();
}
if(isInserted == true)
Toast.makeText(Addrecord.this,"Data Inserted",Toast.LENGTH_LONG).show();
else
Toast.makeText(Addrecord.this,"Data not Inserted",Toast.LENGTH_LONG).show();
}
}
);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.screen2_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.home2) {
Intent intent = new Intent(Addrecord.this, Home.class);
startActivity(intent);
return true;
}
if (id == R.id.viewarecord) {
Intent intent = new Intent(Addrecord.this, Viewstudent.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
//crash log
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.supriya.project3, PID: 2274
java.lang.NumberFormatException: For input string: "j"
at java.lang.Integer.parseInt(Integer.java:608)
at java.lang.Integer.parseInt(Integer.java:643)
at
com.supriya.project3.Addrecord$1.onClick(Addrecord.java:72)
at android.view.View.performClick(View.java:6891)
at
android.widget.TextView.performClick(TextView.java:12651)
at
android.view.View$PerformClick.run(View.java:26083)
at
android.os.Handler.handleCallback(Handler.java:789)
at
android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at
android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Application terminated.
Try this
youredittext.addTextChangedListener(new TextWatcher()
{
#Override
public void afterTextChanged(Editable mEdit)
{
String regexStr = "^[0-9]*$";
if(your_editText.getText().toString().trim().matches(regexStr))
{
//write code here for success
}
else{
// write code here on failure
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){}
});
let me know if this is working or not
You can use android:inputType="number" . If you also want to filter the number that user input, you can addTextChangeListener.
String strNumber = ag.getText().toString().trim();
if(TextUtils.isEmpty(strNumber)){
Toast.makeText(Addrecord.this,"Please input a number",Toast.LENGTH_LONG).show();
}else{
String regexStr = "^[0-9]*$";
if(your_editText.getText().toString().trim().matches(regexStr))
{
//write code here for success
your_editText.setError(null) // to clear any errors
}
else{
your_editText.setError(“please insert numbers only”);
}
}
}
Use this regex to find if a string has numbers or not:
Pattern pattern = Pattern.compile(".*[^0-9].*");
pattern.matcher(you input in edittext).matches());

How to add onClick for buttons?

I'm trying to figure out why my app crashes when my AddThreeToTeamA button crashes my application upon clicking. I have addded my XML and my Java code.
I am following a tutorial however it obviously does not crash and I have tried several different solutions.
Any hint will be appreciated.
package com.themovingmonkey.courtcounter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int score = 0;
int scoreTeamA;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void addThreeForTeamA() {
scoreTeamA = score + 3;
displayForTeamA(scoreTeamA);
}
public void addTwoForTeamA() {
scoreTeamA = score + 2;
displayForTeamA(scoreTeamA);
}
public void addOneForTeamA() {
scoreTeamA = score + 1;
displayForTeamA(scoreTeamA);
}
public void displayForTeamA(int score) {
TextView scoreView = (TextView) findViewById(R.id.Team_A_Score);
scoreView.setText(String.valueOf(scoreTeamA));
}
}
////////////////////////////////////////////////////////////////
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text= "Team A"
android:padding="4dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0"
android:padding="4dp"
android:id="#+id/Team_A_Score"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="3 Points"
android:layout_margin="8dp"
android:onClick="addThreeForTeamA"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2 Points"
android:layout_margin="8dp"
android:onClick="addTwoForTeamA"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1 Point"
android:layout_margin="8dp"
android:onClick="addOneForTeamA"
/>
</LinearLayout>
All methods defined using the android:onClick="someMethod" attribute. Then they have to be public and should pass a View as the only parameter, Change your methods to:
public void someMethod(View view){
//Everything else!
}
Your methods do not pass a View as the only parameter at all currently!

how to make number picker work in fragment with on clicklistener

I have a tab layout, number picker in the fragment doesn't seem to be working, the values remain 0 always.
Basically I am making random number app.
there are three number pickers in my fragment, one gives minimum number, one gives maximum number and one gives quantity of random numbers.
after setting these values in number picker user hits a button to get random numbers.
for me button is not doing anything when the values are set.
Please suggest me how to do this.
My fragment activity
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.NumberPicker;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Collections;
public class TabFragment2 extends Fragment {
//declare Spinner object
Spinner generatorType;
Button getRandomNumberBtn;
int minimumNumber;
int maximumNumber;
int quantity1;
TextView randNumbText;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_fragment_2, container, false);
getRandomNumberBtn = (Button) view.findViewById(R.id.get_number);
NumberPicker miniText;
final TextView minimumTextView = (TextView) view.findViewById(R.id.textView3);
miniText = (NumberPicker) view.findViewById(R.id.start_number);
miniText.setMinValue(0);
miniText.setMaxValue(10000);
miniText.setWrapSelectorWheel(true);
miniText.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
#Override
public void onValueChange(NumberPicker picker, int oldVal1, int newVal1) {
//Display the newly selected number from picker
minimumTextView.setText("Min: " + newVal1);
}
});
minimumNumber = miniText.getValue();
NumberPicker maxiText;
final TextView maximumTextView = (TextView) view.findViewById(R.id.textView2);
maxiText = (NumberPicker) view.findViewById(R.id.end_number);
maxiText.setMinValue(0);
maxiText.setMaxValue(10000);
maxiText.setWrapSelectorWheel(true);
maxiText.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
#Override
public void onValueChange(NumberPicker picker, int oldVal2, int newVal2) {
//Display the newly selected number from picker
maximumTextView.setText("Max: " + newVal2);
}
});
maximumNumber = maxiText.getValue();
NumberPicker quantity;
final TextView quantityTextView = (TextView) view.findViewById(R.id.quantity_text);
quantity = (NumberPicker) view.findViewById(R.id.quantity_picker);
quantity.setMinValue(0);
quantity.setMaxValue(100);
quantity.setWrapSelectorWheel(true);
quantity.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
#Override
public void onValueChange(NumberPicker picker, int oldVal3, int newVal3) {
//Display the newly selected number from picker
quantityTextView.setText("Quantity: " + newVal3);
}
});
quantity1 = quantity.getValue();
randNumbText = (TextView) view.findViewById(R.id.random_number_display);
getRandomNumberBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int b = maximumNumber + 1;
int a = minimumNumber;
int c = quantity1;
String multipleRandoms = "";
ArrayList<Integer> list = new ArrayList<Integer>();
ArrayList<Integer> list1 = new ArrayList<Integer>();
for (int i = a; i < b; i++) {
list.add(new Integer(i));
}
int k = list.size();
Collections.shuffle(list);
if (k>c) {
for (int i = 1; i <= c; i++) {
list1.add(new Integer(list.get(i)));
multipleRandoms = list1.toString();
}
}else if (k==c) {
multipleRandoms = list.toString();
} else {
Toast toast = Toast.makeText(getActivity(),"Quantity can not be greater than numbers in range", Toast.LENGTH_LONG);
toast.show();
}
randNumbText.setText(multipleRandoms);
}
});
return view;
}
My fragment layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/tab_fragment_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context="com.example.tabstrial2.TabFragment2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:id="#+id/linear_layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/generator_type_spinner"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/linear_layout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10px"
android:text="Min" />
<NumberPicker
android:id="#+id/start_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20px"
android:layout_marginTop="20px" />
</LinearLayout>
<LinearLayout
android:layout_width="2px"
android:layout_height="match_parent"
android:background="#android:color/black">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/quantity_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10px"
android:text="Quantity" />
<NumberPicker
android:id="#+id/quantity_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20px"
android:layout_marginTop="20px" />
</LinearLayout>
<LinearLayout
android:layout_width="2px"
android:layout_height="match_parent"
android:background="#android:color/black">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10px"
android:text="Max" />
<NumberPicker
android:id="#+id/end_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView2"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20px"
android:layout_marginTop="20px" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/random_number_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linear_layout1"
android:layout_centerHorizontal="true"
android:layout_margin="10px"
android:textColor="#android:color/black"
android:textSize="40dp" />
<Button
android:id="#+id/get_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/random_number_display"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_orange_light"
android:focusable="true"
android:focusableInTouchMode="true"
android:onClick="getRandomNumber"
android:paddingLeft="20px"
android:paddingRight="20px"
android:text="Get Random Number" />
</RelativeLayout>
</ScrollView>

Cryt Error with clicking button

recently I've made an app with buttons and by click each button you should go to another activity with the text. And it works great. But when I decited to add another one and programming it, I have cryt error when I click this button and I dont know what's going on. Here I give you the code (if necessery I will give you link to whole project but it have 135 MB weight).
MainActivity.java:
package pl.wrweb.reikoapp;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
private Button buttonOk;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonOk = (Button) findViewById(R.id.buttonOk);
buttonOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ButtonsActivity.class);
startActivity(intent);
finish();
}
});
}
}
ButtonsActivity.java:
package pl.wrweb.reikoapp;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class ButtonsActivity extends ActionBarActivity implements View.OnClickListener {
public static final String CLOSE = "close";
public static final String OPTION = "option";
private Button firstButton, secondButton, oBlondynkach, thirdButton, forthButton, fifthButton, sixthButton, seventhButton, closeButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_buttons);
firstButton = (Button) findViewById(R.id.firstButton);
secondButton = (Button) findViewById(R.id.secondButton);
oBlondynkach = (Button) findViewById(R.id.blondynki);
thirdButton = (Button) findViewById(R.id.thirdButton);
forthButton = (Button) findViewById(R.id.forthButton);
fifthButton = (Button) findViewById(R.id.fifthButton);
sixthButton = (Button) findViewById(R.id.sixthButton);
seventhButton = (Button) findViewById(R.id.seventhButton);
closeButton = (Button) findViewById(R.id.closeButton);
firstButton.setOnClickListener(this);
secondButton.setOnClickListener(this);
oBlondynkach.setOnClickListener(this);
thirdButton.setOnClickListener(this);
forthButton.setOnClickListener(this);
fifthButton.setOnClickListener(this);
sixthButton.setOnClickListener(this);
seventhButton.setOnClickListener(this);
closeButton.setOnClickListener(this);
String androidId = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice(md5(androidId).toUpperCase())
.build();
adView.loadAd(adRequest);
}
#Override
public void onClick(View v) {
String idAsString = v.getResources().getResourceName(v.getId());
String option = idAsString.replace("pl.wrweb.reikoapp:id/", "").replace("Button", "");
if (option.equals(CLOSE)) {
finish();
} else {
Intent intent = new Intent(ButtonsActivity.this, TextActivity.class);
intent.putExtra(OPTION, option);
startActivity(intent);
}
}
public String md5(String s) {
try {
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
StringBuffer hexString = new StringBuffer();
for (int i=0; i<messageDigest.length; i++)
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
}
TextActivity.java:
package pl.wrweb.reikoapp;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TextActivity extends ActionBarActivity {
public static final String OPTION = "option";
private TextView optionTV, textTV;
private Button backButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text);
optionTV = (TextView) findViewById(R.id.optionTV);
textTV = (TextView) findViewById(R.id.textTV);
backButton = (Button) findViewById(R.id.backButton);
String option = getIntent().getStringExtra(OPTION);
String packageName = getPackageName();
int optionId = getResources().getIdentifier(option + ".option", "string", packageName);
int textId = getResources().getIdentifier(option + ".text", "string", packageName);
optionTV.setText(optionId);
textTV.setText(textId);
backButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextActivity.this.onBackPressed();
}
});
}
}
activity_main.xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="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"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false">
<TextView
android:id="#+id/helloTV"
android:text="#string/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/laugh"
android:layout_below="#+id/helloTV"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="#string/ok.click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:layout_alignBottom="#+id/imageView"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ok"
android:id="#+id/buttonOk"
android:layout_gravity="bottom|right"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true" />
</RelativeLayout>
activity_buttons.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/choose"
android:id="#+id/chooseTV"
android:paddingLeft="15dp"
android:paddingTop="15dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="#dimen/button.width"
android:layout_height="wrap_content"
android:text="#string/first.option"
android:id="#+id/firstButton"
android:layout_below="#+id/chooseTV"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />
<Button
android:layout_width="#dimen/button.width"
android:layout_height="wrap_content"
android:text="#string/second.option"
android:id="#+id/secondButton"
android:layout_below="#+id/firstButton"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="#dimen/button.width"
android:layout_height="wrap_content"
android:text="#string/third.option"
android:id="#+id/thirdButton"
android:layout_below="#+id/secondButton"
android:layout_alignLeft="#+id/secondButton"
android:layout_alignStart="#+id/secondButton"
android:layout_marginTop="50dp" />
<Button
android:layout_width="#dimen/button.width"
android:layout_height="wrap_content"
android:text="#string/forth.option"
android:id="#+id/forthButton"
android:layout_below="#+id/thirdButton"
android:layout_alignLeft="#+id/thirdButton"
android:layout_alignStart="#+id/thirdButton" />
<Button
android:layout_width="#dimen/button.width"
android:layout_height="wrap_content"
android:text="#string/fifth.option"
android:id="#+id/fifthButton"
android:layout_below="#+id/forthButton"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="#dimen/button.width"
android:layout_height="wrap_content"
android:text="#string/sixth.option"
android:id="#+id/sixthButton"
android:layout_below="#+id/fifthButton"
android:layout_alignLeft="#+id/fifthButton"
android:layout_alignStart="#+id/fifthButton" />
<Button
android:layout_width="#dimen/button.width"
android:layout_height="wrap_content"
android:text="#string/seventh.option"
android:id="#+id/seventhButton"
android:layout_below="#+id/sixthButton"
android:layout_alignLeft="#+id/sixthButton"
android:layout_alignStart="#+id/sixthButton" />
<Button
android:layout_width="#dimen/button.width"
android:layout_height="wrap_content"
android:text="#string/close.option"
android:id="#+id/closeButton"
android:layout_below="#+id/seventhButton"
android:layout_alignLeft="#+id/seventhButton"
android:layout_alignStart="#+id/seventhButton"
android:layout_marginTop="10dp" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/closeButton"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="150dp"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"></com.google.android.gms.ads.AdView>
<Button
android:layout_width="#dimen/button.width"
android:layout_height="wrap_content"
android:text="#string/oBlondynkach.option"
android:id="#+id/blondynki"
android:layout_below="#+id/secondButton"
android:layout_alignLeft="#+id/secondButton"
android:layout_alignStart="#+id/blondynki"
android:layout_alignRight="#+id/secondButton" />
</RelativeLayout>
</ScrollView>
activity_text.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: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=".MainActivity" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/imageView1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/optionTV"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textTV"
android:layout_below="#+id/optionTV"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:singleLine="false"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/back"
android:id="#+id/backButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</LinearLayout>
</ScrollView>
Logcat:
01-18 12:42:33.359 3188-3188/pl.wrweb.reikoapp E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.wrweb.reikoapp/pl.wrweb.reikoapp.TextActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2067)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092)
at android.app.ActivityThread.access$600(ActivityThread.java:133)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4794)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
at android.content.res.Resources.getText(Resources.java:243)
at android.widget.TextView.setText(TextView.java:3620)
at pl.wrweb.reikoapp.TextActivity.onCreate(TextActivity.java:30)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2031)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092) 
at android.app.ActivityThread.access$600(ActivityThread.java:133) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4794) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 
at dalvik.system.NativeStart.main(Native Method) 

Categories

Resources