Fixing error with Gridlayout casting to ImageView - java

I have the .xml file set up as
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:columnCount="4"
android:rowCount="6"
android:onClick="dropIn"
android:layout_alignParentEnd="true"
android:id="#+id/gridLayout">
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_column="0"
tools:layout_editor_absoluteX="288dp"
tools:layout_editor_absoluteY="180dp"
android:layout_row="0"
android:onClick="dropIn"
android:contentDescription="#null"
android:tag="1"
app:srcCompat="#drawable/stone" />
Anyways, I have plenty more of ImageViews and the thing that makes them different is the id and the tag. I decided to have them recognized by code by their tag. So this is what I currently have:
int[] gameState = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
public void dropIn(View view) {
ImageView counter = (ImageView) view;
counter.setImageResource(R.drawable.stone);
int tappedCounter = Integer.parseInt(counter.getTag().toString());
try {
if (gameState[tappedCounter] == 2 && gameIsActive) {
gameState[tappedCounter] = 3;
countMe = countMe - 1;
counter.setVisibility(View.INVISIBLE);
} else if (gameState[tappedCounter] == 3 && gameIsActive) {
Toast.makeText(MainActivity.this, "That field is already played!",
Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Toast.makeText(MainActivity.this, "Oho!",
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
This all works fine, except when I click an ImageView that has already been clicked and is now invisible, it crashes the app with the following message:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nedim.lastonestanding, PID: 9758
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.view.View$DeclaredOnClickListener.onClick(View.java:5374)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:5369)
at android.view.View.performClick(View.java:6294) 
at android.view.View$PerformClick.run(View.java:24770) 
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
Caused by: java.lang.ClassCastException: android.widget.GridLayout cannot be cast to android.widget.ImageView
at com.nedim.lastonestanding.MainActivity.dropIn(MainActivity.java:32)
at java.lang.reflect.Method.invoke(Native Method) 
at android.view.View$DeclaredOnClickListener.onClick(View.java:5369) 
at android.view.View.performClick(View.java:6294) 
at android.view.View$PerformClick.run(View.java:24770) 
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
Application terminated.
From what I understand, the Image from the ImageView disappears and now I am clicking on the GridLayout and not the ImageView which causes it to crash as it's not the thing that I want to be working with. I also suppose that the problem is that counter is making all views become ImageViews, but I am not sure how I could fix this. Any ideas? Thanks!
EDIT: The onCreate method
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView winMessage = findViewById(R.id.winMessage);
winMessage.setText("Let's play! It's Player " + activePlayer + "'s turn.");
}

You have the same attribute android:onClick="dropIn" declared both for GridLayout and ImageView. The 1st one causes the ClassCastException at the line ImageView counter = (ImageView) view;

The view which is passed to dropIn function is a GirdLayout which you are trying to cast as an ImageView.
GridLayout counter = (GridLayout) view;
However, I see you are using the same function to handle the onClick of the ImageView as well, which you cannot. If you want to handle them both using the same function, you might consider doing something like this.
public void dropIn(View view) {
if(view.getId() == R.id.gridLayout) {
// Handle action for GridLayout click
} else if(view.getId() == R.id.imageView1) {
// Handle the actions for ImageView click
}
}
Personally I think, you have put your onClick in your GridLayout wrongly. So just omit the onClick attribute from the GridLayout xml.
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:columnCount="4"
android:rowCount="6"
<!-- android:onClick="dropIn" -->
android:layout_alignParentEnd="true"
android:id="#+id/gridLayout">

Related

NullPointerException at onClick method

I am making an app on Android Studio and I ran into the NullPointerException in my onClick method. How do I fix it?
The debugger of my app gives me this:
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
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:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
at android.view.View.performClick(View.java:6256) 
at android.view.View$PerformClick.run(View.java:24701) 
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:6541) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageDrawable(android.graphics.drawable.Drawable)' on a null object reference
at com.example.venttome.ventingPage.onClick(ventingPage.java:66)
at java.lang.reflect.Method.invoke(Native Method) 
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409) 
at android.view.View.performClick(View.java:6256) 
at android.view.View$PerformClick.run(View.java:24701) 
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:6541) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
The code (the onClick() method) that is wrong:
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.record_btn:
if (isRecording){
//stop recording
recordButton.setImageDrawable(getResources().getDrawable(R.drawable.record_btn_stopped, null));
isRecording = false;
} else {
//start recording
recordButton.setImageDrawable(getResources().getDrawable(R.drawable.record_btn_recording, null));
isRecording = true;
}
break;
}
}
And this is my XML file for that class, and it is a constraint layout. This is what I use for my onClick method and I don't know what's wrong with it:
<ImageView
android:id="#+id/record_btn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:layout_marginBottom="28dp"
android:background="#android:color/white"
android:clickable="true"
android:cropToPadding="true"
android:onClick="onClick"
android:src="#drawable/record_btn_stopped"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="#id/final_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/inputFeelings"
app:layout_constraintVertical_bias="1.0"
android:focusable="true"
tools:ignore="ContentDescription" />
you are not initializing the button in your method.Please first do this in your onCreate() method or if you are using fragment then in onCreateView():
ImageView record_btn= findViewById(R.id.record_btn);
Please initialize the view inside onCreate()
Here is the working code snippet
public class SecondActivity extends AppCompatActivity implements View.OnClickListener {
ImageView recordButton;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recordButton = findViewById(R.id.record_btn);
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.record_btn:
Toast.makeText(this, "Called", Toast.LENGTH_SHORT).show();
recordButton.setImageResource(R.drawable.ic_launcher_foreground);
break;
}
}}

Checking if RadioButtons are not checked in java

I'm learning android making a simple calculator in Java like the one in the image. my calculator
When I try the app, neither of the Radio Buttons are checked, so when I press the 'calculate' button the app shuts down.
I tried making a comprobation and if neither of the buttons are checked the app shows a Toast but the app shuts down anyway.
This is the comprobation code (where btnSumar and btnRestar are the RadioButtons):
if(!btnSumar.isChecked() && !btnRestar.isChecked()) {
Toast.makeText(MainActivity.this, "Please, select one option", Toast.LENGTH_SHORT).show();
}
It seems logic to me, but it doesn't work.
Thanks for helping!
this is logcat
2020-09-06 18:51:48.814 10245-10245/com.triopsstudio.seccion01 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.triopsstudio.seccion01, PID: 10245
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414)
at android.view.View.performClick(View.java:7448)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
at android.view.View.performClick(View.java:7448) 
at android.view.View.performClickInternal(View.java:7425) 
at android.view.View.access$3600(View.java:810) 
at android.view.View$PerformClick.run(View.java:28305) 
at android.os.Handler.handleCallback(Handler.java:938) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:223) 
at android.app.ActivityThread.main(ActivityThread.java:7656) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.Integer.parseInt(Integer.java:627)
at java.lang.Integer.parseInt(Integer.java:650)
at com.triopsstudio.seccion01.MainActivity.Calcular(MainActivity.java:53)
According to your stacktrace you have a NumberFormatException because you have no input yet. You try to parse number from empty string. Integer.parseInt("") leads to Exception ( lines 53 MainActivity class)
You can make one of radiobutton checked by default and it's id from radioGroup
ex:
<RadioGroup
android:id="#+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_male"
android:checked="true" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_female" />
</RadioGroup>
MainActivity:
//top level declaration..
private RadioGroup radioSexGroup;
private RadioButton radioSexButton;
Inside onCreate(Bundle savedInstanceState)
radioSexGroup = (RadioGroup) findViewById(R.id.radioSex);
// get selected radio button from radioGroup
int selectedId = radioSexGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
radioSexButton = (RadioButton) findViewById(selectedId);//this will have selected button id
Use the isChecked() function for every radioButton you have to check.
RadioButton maleRadioButton, femaleRadioButton;
maleRadioButton = (RadioButton) findViewById(R.id.maleRadioButton);
femaleRadioButton = (RadioButton) findViewById(R.id.femaleRadioButton);
Then use the result for your code case consideration to check radiobutton.
if (maleRadioButton.isChecked() || femaleRadioButton.isChecked()) {
Log.d("QAOD", "Gender is Selected");
} else {
Toast.makeText(getApplicationContext(), "Please select Gender", Toast.LENGTH_SHORT).show();
Log.d("QAOD", "Gender is Null");
}

How to check which radio buttons are checked upon pressing a button

I'm getting this error when I click on the button that executes a method.
Process: com.example.myapplication, PID: 7757
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6304)
at android.view.View$PerformClick.run(View.java:24803)
at android.os.Handler.handleCallback(Handler.java:794)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6635)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6304) 
at android.view.View$PerformClick.run(View.java:24803) 
at android.os.Handler.handleCallback(Handler.java:794) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:176) 
at android.app.ActivityThread.main(ActivityThread.java:6635) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823) 
Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatButton cannot be cast to android.widget.RadioButton
at com.example.myapplication.MockTest.submitbtn(MockTest.java:66)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) 
at android.view.View.performClick(View.java:6304) 
at android.view.View$PerformClick.run(View.java:24803) 
at android.os.Handler.handleCallback(Handler.java:794) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:176) 
at android.app.ActivityThread.main(ActivityThread.java:6635) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823) 
The method is called upon by android:onClick through xml upon clicking the button.
This is the method,
public void submitbtn(View view)
{
boolean checked = ((RadioButton) view).isChecked();
switch (view.getId()) {
case R.id.q1r1: if (checked)
score++;
break;
case R.id.q2r4: if (checked)
score++;
break;
case R.id.q3r4: if (checked)
score++;
break;
case R.id.q4r2: if (checked)
score++;
break;
}
}
this is the xml entry for the button,
<Button
android:id="#+id/submitbtn"
android:layout_width="100dp"
android:layout_height="65dp"
android:layout_marginStart="150dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="150dp"
android:text="Submit"
android:onClick="submitbtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/q4r" />
I looked at the error and noticed that it says it's caused because radiobutton widget cannot be cast to button widget, is that right? if so how can I implement this. What I'm trying to do is simply check the radio button's current state(checked or not) once the button is clicked. My previous approach, which worked, was this exact method but called from a radiobutton. I had put an android:onClick on the radiobutton's xml file. But this somehow does not work.
Found the solution, apparently I need to use radiogroups instead of directly using radiobuttons, the only change I made is in the code, here it is,
public void submitbtn(View view)
{
RadioGroup q4r = findViewById(R.id.q4r);
//Checking which radio button is checked, if any, and then executing tasks
if(q1r.getCheckedRadioButtonId() == R.id.q1r1)
{
//execute tasks
}
else if(q1r.getCheckedRadioButtonId() == -1)
{
//Nothing
}
else
{
//execute tasks
}
}

Error inflating class <unknown> - app crashes

In an Android app that I developed, the app crashes when I move to a certain activity. I saw that many people encountered a similar problem before, but none of the former answers solve my problem.
Here's the relevant code:
StillsActivity.java
the code crashes on the last line of this snippet
public class StillsActivity extends SpatialFilteringActivity {
private static final int SELECT_PICTURE = 1;
private static final String TAG = "Stills";
private Uri mURI;
private Bitmap mBitmap;
private ImageView mImageView;
private Mat mImToProcess = new Mat();
private Mat mImGray = new Mat();
private Mat mFilteredImage = new Mat();
private SeekBar mSeekBarSpatial;
private SeekBar mSeekBarIntensity;
private SeekBar mSeekBarAlpha;
private SeekBar mSeekBarBeta;
private TextView mTextViewSpatial;
private TextView mTextViewIntensity;
private TextView mTextViewAlpha;
private TextView mTextViewBeta;
private MenuItem mSelectedItem;
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_PICTURE) {
if (resultCode == RESULT_OK) {
mURI = data.getData();
if (mURI != null) {
try {
mBitmap = Util.getBitmap(this, mURI);
mImageView.setImageBitmap(Util.getResizedBitmap(mBitmap,
1000));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stills);
// APP CRASHES HERE
mImageView = (ImageView) findViewById(R.id.imageView1);
Button loadButton = (Button) findViewById(R.id.loadButton);
loadButton.setOnClickListener(new View.OnClickListener() {
#SuppressLint("SimpleDateFormat")
#Override
public void onClick(View v) {
Log.i(TAG, "onClick event");
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select an image"), SELECT_PICTURE);
}
});
mSeekBarSpatial = (SeekBar) findViewById(R.id.seekBarSpatial);
mTextViewSpatial = (TextView) findViewById(R.id.sigmaSpatialTextView);
setSeekBar(mSeekBarSpatial, mTextViewSpatial, getResources().getString(R.string.stringSpatial), MyImageProc.SIGMA_SPATIAL_MAX);
mSeekBarIntensity = (SeekBar) findViewById(R.id.seekBarIntensity);
mTextViewIntensity = (TextView) findViewById(R.id.sigmaIntensityTextView);
setSeekBar(mSeekBarIntensity, mTextViewIntensity, getResources().getString(R.string.stringIntensity), MyImageProc.SIGMA_INTENSITY_MAX);
mSeekBarAlpha = (SeekBar) findViewById(R.id.seekBarAlpha);
mTextViewAlpha = (TextView) findViewById(R.id.alphaTextView);
setSeekBar(mSeekBarAlpha, mTextViewAlpha, getResources().getString(R.string.stringAlpha), MyImageProc.ALPHA_MAX);
mSeekBarBeta = (SeekBar) findViewById(R.id.seekBarBeta);
mTextViewBeta = (TextView) findViewById(R.id.betaTextView);
setSeekBar(mSeekBarBeta, mTextViewBeta, getResources().getString(R.string.stringBeta), MyImageProc.BETA_MAX);
}
// etc.
SpatialFilteringActivity.java
public class SpatialFilteringActivity extends AppCompatActivity {
private static final String TAG = "SpatialFiltering";
//menu members
private SubMenu mResolutionSubMenu;
private SubMenu mCameraSubMenu;
//flags
private Boolean mSettingsMenuAvailable =false;
protected static final int SETTINGS_GROUP_ID = 1;
protected static final int RESOLUTION_GROUP_ID = 2;
protected static final int CAMERA_GROUP_ID = 3;
protected static final int DEFAULT_GROUP_ID = 4;
protected static final int COLOR_GROUP_ID = 5;
protected static final int FILTER_GROUP_ID = 6;
protected static final int STILL_GROUP_ID = 7;
private MyJavaCameraView mOpenCvCameraView;
private CameraListener mCameraListener = new CameraListener();
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
#Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
break;
default:
super.onManagerConnected(status);
break;
}
}
};
private String[] mCameraNames = {"Front", "Rear"};
private int[] mCameraIDarray = {CameraBridgeViewBase.CAMERA_ID_FRONT, CameraBridgeViewBase.CAMERA_ID_BACK};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spatial_filtering);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mOpenCvCameraView = (MyJavaCameraView) findViewById(R.id.Java_Camera_View);
mOpenCvCameraView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_ANY);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(mCameraListener);
Button saveButton = (Button) findViewById(R.id.saveButton);
saveButton.setOnClickListener(new View.OnClickListener() {
#SuppressLint("SimpleDateFormat")
#Override
public void onClick(View v) {
Log.i(TAG, "onClick event");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String currentDateandTime = sdf.format(new Date());
String fileName = Environment.getExternalStorageDirectory().getPath() +
"/sample_picture_" + currentDateandTime + ".jpg";
mOpenCvCameraView.takePicture(fileName);
addImageToGallery(fileName, SpatialFilteringActivity.this);
Toast.makeText(SpatialFilteringActivity.this, fileName + " saved",
Toast.LENGTH_SHORT).show();
}
});
}
//etc.
activity_stills.xml
<?xml version="1.0" encoding="utf-8"?>
<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="il.ac.tau.adviplab.iplab2_hn.StillsActivity">
<ImageView
android:contentDescription="#string/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView1"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:src="#drawable/loadimage"
android:adjustViewBounds="true"
android:layout_centerVertical="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/load_button"
android:id="#+id/loadButton"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/seekBarSpatial"
android:layout_marginTop="13dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="#+id/sigmaSpatialTextView"
android:layout_alignStart="#+id/sigmaSpatialTextView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:id="#+id/sigmaSpatialTextView"
android:text="#string/stringSpatial"
android:layout_below="#+id/seekBarSpatial"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/seekBarIntensity"
android:layout_marginTop="15dp"
android:layout_below="#+id/sigmaSpatialTextView"
android:layout_alignLeft="#+id/sigmaSpatialTextView"
android:layout_alignStart="#+id/sigmaSpatialTextView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="#+id/sigmaIntensityTextView"
android:text="#string/stringIntensity"
android:layout_below="#+id/seekBarIntensity"
android:layout_alignLeft="#+id/seekBarIntensity"
android:layout_alignStart="#+id/seekBarIntensity"/>
<SeekBar
android:id="#+id/seekBarAlpha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_below="#+id/sigmaIntensityTextView"
android:layout_alignLeft="#+id/alphaTextView"
android:layout_alignStart="#+id/alphaTextView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/alphaTextView"
android:text="#string/stringAlpha"
android:layout_marginTop="12dp"
android:layout_below="#+id/seekBarAlpha"
android:layout_alignLeft="#+id/sigmaIntensityTextView"
android:layout_alignStart="#+id/sigmaIntensityTextView"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/seekBarBeta"
android:layout_marginTop="8dp"
android:layout_below="#+id/alphaTextView"
android:layout_alignLeft="#+id/alphaTextView"
android:layout_alignStart="#+id/alphaTextView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/betaTextView"
android:text="#string/stringBeta"
android:layout_below="#+id/seekBarBeta"
android:layout_alignLeft="#+id/seekBarBeta"
android:layout_alignStart="#+id/seekBarBeta"/>
</RelativeLayout>
note: the #drawable/loadimage is 1000*978 pixels, if that matters
Logs
java.lang.RuntimeException: Unable to start activity ComponentInfo{il.ac.tau.adviplab.iplab2_hn/il.ac.tau.adviplab.iplab2_hn.StillsActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5466)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at il.ac.tau.adviplab.iplab2_hn.StillsActivity.onCreate(StillsActivity.java:73)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5466) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at il.ac.tau.adviplab.iplab2_hn.StillsActivity.onCreate(StillsActivity.java:73) 
at android.app.Activity.performCreate(Activity.java:6251) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5466) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at il.ac.tau.adviplab.iplab2_hn.StillsActivity.onCreate(StillsActivity.java:73) 
at android.app.Activity.performCreate(Activity.java:6251) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5466) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:666)
at android.view.View.<init>(View.java:3969)
at android.view.ViewGroup.<init>(ViewGroup.java:573)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:248)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:244)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:240)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at il.ac.tau.adviplab.iplab2_hn.StillsActivity.onCreate(StillsActivity.java:73) 
at android.app.Activity.performCreate(Activity.java:6251) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5466) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
I'd appreciate any help.
Thanks!
Please follow background image size
For Supported device
LDPI:
Portrait: 200x320px
Landscape: 320x200px
MDPI:
Portrait: 320x480px
Landscape: 480x320px
HDPI:
Portrait: 480x800px
Landscape: 800x480px
XHDPI:
Portrait: 720px1280px
Landscape: 1280x720px

Android: RNG error and button theme

I have my Random Number generator and it crashes when I I type in 0 in the 'numberTo' string and gives me int: "0". With this I cannot make remove the editText and show the hint because of the TextWatcher. Please help me with that! And guys how do I add a button with a different color, can you please explain?
This is my code:
activity_main.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="bedi.gursimran.materialtest.MainActivity">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar" />
<TextView
android:textSize="68dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/random_text"
android:text="Number"
android:layout_marginTop="12dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="false"
android:layout_marginLeft="50dp"
/>
<EditText
android:layout_width="140dp"
android:layout_height="wrap_content"
android:inputType="number"
android:padding="12dp"
android:ems="10"
android:id="#+id/text_from"
android:maxLength="6"
android:hint="From"
android:layout_below="#+id/app_bar"
android:layout_alignParentStart="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="24dp"
android:backgroundTint="#color/primaryColorDark"
android:textSize="#dimen/edit_text_size"/>
<EditText
android:layout_width="140dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:padding="12dp"
android:id="#+id/text_to"
android:layout_below="#+id/text_from"
android:layout_alignParentStart="true"
android:maxLength="8"
android:hint="To"
android:backgroundTint="#color/primaryColorDark"
android:layout_marginTop="8dp"
android:layout_marginLeft="10dp"
android:textSize="#dimen/edit_text_size"/>
<Button
android:layout_width="140dp"
android:layout_height="70dp"
android:text="Generate"
android:id="#+id/generate_button"
android:onClick="generate"
android:layout_below="#+id/app_bar"
android:layout_marginLeft="190dp"
android:layout_marginTop="51dp"
android:textColor="#fffafafa"
android:textSize="22dp"
android:backgroundTint="#color/accentColor"
/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<!--Base theme-->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar" >
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/accentColor</item>
<!-- Generate Button Color -->
<item name="android:colorButtonNormal">#color/primaryColor</item>
</style>
<!--Action Bar theme-->
<style name="MyCustomToolBarTheme" parent="ThemeOverlay.AppCompat.Light">
<!--The title-->
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:textColor">#FFFFFF</item>
<!--The 'overflow icon-->
<item name="android:textColorSecondary">#FFFFFF</item>
</style>
<style name="ActionBarPopupThemeOverlay" parent="ThemeOverlay.AppCompat.Light" >
<item name="android:background">#android:color/white</item>
<item name="android:textColor">#de000000</item>
</style>
</resources>
app_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#color/primaryColor"
app:theme="#style/MyCustomToolBarTheme"
android:paddingTop="#dimen/app_bar_top_padding"
android:elevation="#dimen/action_bar_elevation"
app:popupTheme="#style/ActionBarPopupThemeOverlay"
>
</android.support.v7.widget.Toolbar>
And most importantly... MainActivity.java
public class MainActivity extends ActionBarActivity implements TextWatcher {
private Toolbar toolbar;
TextView randomText;
EditText editTextFrom;
EditText editTextTo;
Button generate_button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//toolbar= (Toolbar) findViewById(R.id.app_bar);
toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
//Generated Number
randomText = (TextView) findViewById(R.id.random_text);
Typeface myCustomFontTextView = Typeface.createFromAsset(getAssets(), "fonts/RobotoCondensed-Light.ttf");
randomText.setTypeface(myCustomFontTextView);
//From Text
editTextFrom = (EditText) findViewById(R.id.text_from);
Typeface myCustomFontEditViewFrom = Typeface.createFromAsset(getAssets(), "fonts/RobotoCondensed-Regular.ttf");
editTextFrom.setTypeface(myCustomFontEditViewFrom);
editTextFrom.addTextChangedListener(this);
//To Text
editTextTo = (EditText) findViewById(R.id.text_to);
Typeface myCustomFontEditViewTo = Typeface.createFromAsset(getAssets(), "fonts/RobotoCondensed-Regular.ttf");
editTextTo.setTypeface(myCustomFontEditViewTo);
editTextTo.addTextChangedListener(this);
//Generate Button
generate_button = (Button) findViewById(R.id.generate_button);
Typeface myCustomFontButton = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf");
generate_button.setTypeface(myCustomFontButton);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Toast.makeText(this, item.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
// if (id == R.id.navigate) {
// startActivity(new Intent(this, SubActivity.class));
// }
return super.onOptionsItemSelected(item);
}
public void generate(View view) {
//text
EditText from = (EditText) findViewById(R.id.text_from);
EditText to = (EditText) findViewById(R.id.text_to);
String stringFrom, stringTo;
stringFrom = from.getText().toString();
stringTo = to.getText().toString();
int numberFrom, numberTo;
if (stringFrom.equals("")) {
stringFrom = "0";
}
if (stringTo.equals("")) {
stringTo = "0";
}
numberFrom = Integer.parseInt(stringFrom);
numberTo = Integer.parseInt(stringTo);
Random random = new Random();
int number = random.nextInt(numberTo + 1);
if(numberFrom != numberTo) {
while (number < numberFrom || number > numberTo) {
number = random.nextInt(numberTo + 1);
}
} else {
numberFrom = numberTo = number;
}
// } catch (NumberFormatException e) {}
try {
TextView myText = (TextView) findViewById(R.id.random_text);
String myString = String.valueOf(number);
myText.setText(myString);
} catch (NumberFormatException e) {
TextView myText = (TextView) findViewById(R.id.random_text);
myText.setText("Enter a number greater than zero");
}
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable editable) {
int numberto;
try {
numberto = Integer.parseInt(editable.toString());
} catch (NumberFormatException e) {
numberto = 0;
}
if (numberto == 0) {
editable.replace(0, editable.length(), "1");
}
}
}
edit
The errors went away as I took the implements TextWatcher out. Please help me with the button colors, I still don't know how to have 2 different colored buttons. Thanks!
edit 2 Gives me this log when I put both as null. Please help!!
2414-2414/bedi.gursimran.materialtest E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: bedi.gursimran.materialtest, PID: 2414
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:4007)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4002)
            at android.view.View.performClick(View.java:4756)
            at android.view.View$PerformClick.run(View.java:19749)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalArgumentException: n <= 0: 0
at java.util.Random.nextInt(Random.java:182)
at bedi.gursimran.materialtest.MainActivity.generate(MainActivity.java:120)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at android.view.View$1.onClick(View.java:4002)
            at android.view.View.performClick(View.java:4756)
            at android.view.View$PerformClick.run(View.java:19749)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Categories