Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: second activity crush only on the phone not on the emulator

Ronen Rachmani:

The first screen upload right and works fine (Toast and all other setting and parameters) until I try to save the result and open the new screen by the same button. Pushing the button crushes the app in my phone with out opening the second screen. However in the emulator all works fine.

this is the Main activity:


public class MainActivity extends AppCompatActivity {

LineChart lineChart1;
RadioGroup rg1,rg2;
Button tipBtn;
Button checkAndCont;
int [] mSlop ={-1,3};
int [] b= {-3,3};
boolean userAnswer1 = false;
boolean userAnswer2 = false;
String quesType = "Slop Recognition";



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

lineChart1 = (LineChart)findViewById(R.id.lineChart1);
rg1 = (RadioGroup)findViewById(R.id.rg1);
rg2 = (RadioGroup)findViewById(R.id.rg2);


tipBtn = (Button)findViewById(R.id.tipBtb);
tipBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"גרף במערכת צירים נקרא משמאל לימין",Toast.LENGTH_SHORT ).show();
}
});

checkAndCont = (Button)findViewById(R.id.checkAndCont);




ArrayList xAxes = new ArrayList();
ArrayList yAxesLinear1 = new ArrayList();
ArrayList yAxesLinear2 = new ArrayList();

int numberDataPoint = 21;
for (int i=0 ; i int x=i-10;
float funLinear1= mSlop[0]*x+b[0];
float funLinear2= mSlop[1]*x+b[1];
yAxesLinear1.add(new Entry(x,funLinear1));
yAxesLinear2.add(new Entry(x,funLinear2));
//xAxes.add(i,String.valueOf(x));
}
//String [] xaxes = new String[xAxes.size()];
//for (int i=0; i // xaxes[i]=xAxes.get(i);
//}

ArrayList lineDataSet= new ArrayList();

LineDataSet lineDataSet1 = new LineDataSet(yAxesLinear1,"פונקציה קווית 1");
lineDataSet1.setDrawCircles(false);
lineDataSet1.setColor(Color.CYAN);
lineDataSet1.setDrawValues(false);
lineDataSet1.setLineWidth(3);


LineDataSet lineDataSet2 = new LineDataSet(yAxesLinear2,"פונקציה קווית 2");
lineDataSet2.setDrawCircles(false);
lineDataSet2.setColor(Color.GREEN);
lineDataSet2.setDrawValues(false);
lineDataSet2.setLineWidth(3);

lineDataSet.add(lineDataSet1);
lineDataSet.add(lineDataSet2);

lineChart1.setData(new LineData(lineDataSet));

lineChart1.setDrawBorders(true);
lineChart1.setBorderColor(0xffff00ff);
lineChart1.setBorderWidth(2);
lineChart1.setScaleEnabled(true);
//lineChart1.setDrawGridBackground(true);
//lineChart1.setGridBackgroundColor(0xffff00ff);
//lineChart1.setBackgroundColor(0x00000000);

XAxis xAxis = lineChart1.getXAxis();
//xAxis.setEnabled(true);
xAxis.setDrawAxisLine(true);
xAxis.setAxisLineColor(Color.WHITE);
lineChart1.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
lineChart1.getAxisRight().setEnabled(false);
lineChart1.getXAxis().setAxisMaximum(10);
lineChart1.getXAxis().setAxisMinimum(-10);
lineChart1.getXAxis().setGridColor(0xffff00ff);
//lineChart1.getXAxis().setDrawAxisLine(true);
//lineChart1.getXAxis().setAxisLineColor(Color.WHITE); // The buttom limit line of the chart
//lineChart1.setVisibleXRangeMaximum(50);
lineChart1.getXAxis().setTextColor(Color.WHITE);
lineChart1.getXAxis().setTextSize(15);
LimitLine ll = new LimitLine(0);
ll.setLineColor(Color.WHITE);
ll.setLineWidth(1);
xAxis.addLimitLine(ll);


YAxis yAxis = lineChart1.getAxisLeft();
yAxis.setDrawZeroLine(true);
yAxis.setZeroLineColor(Color.WHITE);// no grid lines
yAxis.setZeroLineWidth(1); //Sets the line-width of the zero line.
yAxis.setAxisMinimum(-10f); // start at zero
yAxis.setAxisMaximum(10f); // the axis maximum is 100
yAxis.setGridColor(0xffff00ff);
yAxis.setTextColor(Color.WHITE);
yAxis.setTextSize(15);

Legend legend = lineChart1.getLegend();
legend.setEnabled(true);
legend.setTextColor(Color.WHITE);
legend.setTextSize(18);
legend.setFormSize(13);
legend.setForm(Legend.LegendForm.CIRCLE);
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);

rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
RadioButton rb1 = (RadioButton) radioGroup.findViewById(i);
//if(R.id.rg1==i ? userAnswer1==true : userAnswer1==false);
if (null != rb1 && i > -1) {

// checkedId is the RadioButton selected
switch (i) {
case R.id.rb1:
userAnswer1=false;
break;

case R.id.rb2:
userAnswer1=true;
break;

}
}
Toast.makeText(MainActivity.this,Boolean.toString(userAnswer1),Toast.LENGTH_SHORT ).show();
}
});

rg2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
RadioButton rb2 = (RadioButton) radioGroup.findViewById(i);
//if(R.id.rg1==i ? userAnswer1==true : userAnswer1==false);
if (null != rb2 && i > -1) {

// checkedId is the RadioButton selected
switch (i) {
case R.id.rb3:
userAnswer2=false;
break;

case R.id.rb4:
userAnswer2=true;
break;

}
}
Toast.makeText(MainActivity.this,Boolean.toString(userAnswer2),Toast.LENGTH_SHORT ).show();
}
});

}


public void result(View view) {
if (isTrue(mSlop[0])==userAnswer1 && isTrue(mSlop[1])==userAnswer2){
Toast.makeText(MainActivity.this,"תשובה נכונה",Toast.LENGTH_SHORT ).show();
}else {
Toast.makeText(MainActivity.this,"לא נכון",Toast.LENGTH_SHORT ).show();
}
startActivity(new Intent(MainActivity.this, Main2Activity.class));
}

boolean mType;
public boolean isTrue (int m){
if (m >0){
mType=true;
}else{
mType=false;
}
return mType;
}
}

this is the related XML:



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:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:background="@drawable/background_color">

android:layout_width="match_parent"
android:layout_height="400dp"
android:id="@+id/lineChart1">



android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/lineChart1"
android:layout_marginStart="187dp"
android:paddingRight="15dp"
android:text="פונקציה 1 עולה"
android:textColor="#00FFFF"
android:textSize="25sp" />

android:id="@+id/tv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/tv1"
android:layout_marginStart="187dp"
android:paddingRight="15dp"
android:text="פונקציה 2 עולה"
android:textColor="#ff00ff00"
android:textSize="25sp" />

android:id="@+id/rg1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@+id/lineChart1"
android:orientation="horizontal">

android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#00FFFF"
android:text="לא נכון"
android:textColor="#00FFFF"
android:paddingLeft="2dp"
android:textSize="25sp"
/>

android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#00FFFF"
android:text="נכון"
android:textColor="#00FFFF"
android:paddingLeft="2dp"
android:textSize="25sp"
android:layout_marginLeft="5sp"/>


android:id="@+id/rg2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@+id/rg1"
android:orientation="horizontal">

android:id="@+id/rb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#ff00ff00"
android:text="לא נכון"
android:textColor="#ff00ff00"
android:paddingLeft="2dp"
android:textSize="25sp"
/>

android:id="@+id/rb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#ff00ff00"
android:text="נכון"
android:textColor="#ff00ff00"
android:paddingLeft="2dp"
android:textSize="25sp"
android:layout_marginLeft="5dp"/>




this is the second activity:


public class Main2Activity extends AppCompatActivity {

LineChart lineChart2;
Button quickTipBtn,sendAndNext;
TextView question1,question2;
EditText answer1,answer2;
final int [] mSlop ={1,3};
final int [] b= {1,3};
private boolean userAnswer1 = false;
private boolean userAnswer2 = false;
final String quesType = "y-intercept Recognition";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);

question1 = (TextView)findViewById(R.id.question1);
question2 = (TextView)findViewById(R.id.question2);
answer1 = (EditText)findViewById(R.id.answer1);
answer2 = (EditText)findViewById(R.id.answer2);
quickTipBtn =(Button)findViewById(R.id.quickTipBtn);
quickTipBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(Main2Activity.this,"קואורדינטת החיתוך עם ציר Y ו b - שווים",Toast.LENGTH_SHORT ).show();
}
});
sendAndNext = (Button)findViewById(R.id.sendAndNext);


lineChart2 = (LineChart)findViewById(R.id.lineChart2);
ArrayList xAxes = new ArrayList();
ArrayList yAxesLinear1 = new ArrayList();
ArrayList yAxesLinear2 = new ArrayList();

int numberDataPoint = 21;
for (int i=0 ; i int x=i-10;
float funLinear1= mSlop[0]*x+b[0];
float funLinear2= mSlop[1]*x+b[1];
yAxesLinear1.add(new Entry(x,funLinear1));
yAxesLinear2.add(new Entry(x,funLinear2));
//xAxes.add(i,String.valueOf(x));
}
//String [] xaxes = new String[xAxes.size()];
//for (int i=0; i // xaxes[i]=xAxes.get(i);
//}

ArrayList lineDataSet= new ArrayList();

LineDataSet lineDataSet1 = new LineDataSet(yAxesLinear1,"פונקציה קווית 1");
lineDataSet1.setDrawCircles(false);
lineDataSet1.setColor(Color.CYAN);
lineDataSet1.setDrawValues(false);
lineDataSet1.setLineWidth(3);


LineDataSet lineDataSet2 = new LineDataSet(yAxesLinear2,"פונקציה קווית 2");
lineDataSet2.setDrawCircles(false);
lineDataSet2.setColor(Color.GREEN);
lineDataSet2.setDrawValues(false);
lineDataSet2.setLineWidth(3);

lineDataSet.add(lineDataSet1);
lineDataSet.add(lineDataSet2);

lineChart2.setData(new LineData(lineDataSet));

lineChart2.setDrawBorders(true);
lineChart2.setBorderColor(0xffff00ff);
lineChart2.setBorderWidth(2);
lineChart2.setScaleEnabled(true);
//lineChart1.setDrawGridBackground(true);
//lineChart1.setGridBackgroundColor(0xffff00ff);
//lineChart1.setBackgroundColor(0x00000000);

XAxis xAxis = lineChart2.getXAxis();
//xAxis.setEnabled(true);
xAxis.setDrawAxisLine(true);
xAxis.setAxisLineColor(Color.WHITE);
lineChart2.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
lineChart2.getAxisRight().setEnabled(false);
lineChart2.getXAxis().setAxisMaximum(10);
lineChart2.getXAxis().setAxisMinimum(-10);
lineChart2.getXAxis().setGridColor(0xffff00ff);
//lineChart1.getXAxis().setDrawAxisLine(true);
//lineChart1.getXAxis().setAxisLineColor(Color.WHITE); // The buttom limit line of the chart
//lineChart1.setVisibleXRangeMaximum(50);
lineChart2.getXAxis().setTextColor(Color.WHITE);
lineChart2.getXAxis().setTextSize(15);
LimitLine ll = new LimitLine(0);
ll.setLineColor(Color.WHITE);
ll.setLineWidth(1);
xAxis.addLimitLine(ll);


YAxis yAxis = lineChart2.getAxisLeft();
yAxis.setDrawZeroLine(true);
yAxis.setZeroLineColor(Color.WHITE);// no grid lines
yAxis.setZeroLineWidth(1); //Sets the line-width of the zero line.
yAxis.setAxisMinimum(-10f); // start at zero
yAxis.setAxisMaximum(10f); // the axis maximum is 100
yAxis.setGridColor(0xffff00ff);
yAxis.setTextColor(Color.WHITE);
yAxis.setTextSize(15);

Legend legend = lineChart2.getLegend();
legend.setEnabled(true);
legend.setTextColor(Color.WHITE);
legend.setTextSize(18);
legend.setFormSize(13);
legend.setForm(Legend.LegendForm.CIRCLE);
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);


}

public void sendAndNext(View view) {
String temValue1= answer1.getText().toString();
//Toast.makeText(secondScreen.this, answer1.getText(),Toast.LENGTH_LONG).show();
String temValue2= answer2.getText().toString();
if (Integer.parseInt(temValue1)==mSlop[0] && Integer.parseInt(temValue2)==mSlop[1]){
Toast.makeText(Main2Activity.this, "תשובה נכונה",Toast.LENGTH_LONG).show();
}else {
Toast.makeText(Main2Activity.this, "תשובה לא נכונה או שלא הוזנו נתונים",Toast.LENGTH_LONG).show();
}
}
}

this is the second XML:




xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5"
android:gravity="top"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:background="@drawable/background_color2">

android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3.5"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp">
android:id="@+id/lineChart2"
android:layout_width="match_parent"
android:layout_height="400dp"
>



android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:weightSum="2"
android:gravity="right">

android:id="@+id/answer1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:digits="0123456789."
android:inputType="numberSigned"
android:maxLength="2"
android:hint="הכנס מספר"
android:textColorHint="#78ffd6"
android:textSize="18dp"
android:textColor="#00FFFF"
/>
android:id="@+id/question1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:text="למה שווה הפרמטר b ?"
android:textColor="#00FFFF"
android:textSize="25sp"
>



android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:weightSum="2"
android:gravity="right"
>
android:id="@+id/answer2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:digits="0123456789."
android:maxLength="2"
android:hint="הכנס מספר"
android:textColorHint="#64f38c"
android:textSize="18dp"
android:inputType="numberSigned"
android:textColor="#ff00ff00"
/>
android:id="@+id/question2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:text="מהי נק' החיתוך עם ציר Y?"
android:textColor="#ff00ff00"
android:textSize="25sp"
>



android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:weightSum="2"
android:gravity="center">




Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: second activity crush only on the phone not on the emulator

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×