Reputation: 11
when i try it in my phone , text is not coming and the app will stopped .......anyone can help?? the debug can't find the error and the other frame have no problem, except this . the problem is coming from TextView ...... if I cut the lines the error won't come
package com.example.soo;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.MenuItem;
import android.widget.TextView;
public class Res2Activity extends ActionBarActivity {
TextView ans3;
TextView ans;
TextView ans2;
TextView ans4;
@Override
public void onCreate(Bundle savedInstanceState) {
ans3=(TextView)findViewById(R.id.textView5);
ans=(TextView)findViewById(R.id.textView2);
ans2=(TextView)findViewById(R.id.textView4);
ans4=(TextView)findViewById(R.id.textView6);
super.onCreate(savedInstanceState);
setContentView(R.layout.res2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.res2, menu);
return true;
}
public void mai()
{
Bundle bundle = getIntent().getExtras();
double r1 =bundle.getDouble("some_key");
double r2 =bundle.getDouble("some_key2");
int bet =bundle.getInt("bet");
double a2x1;
double a2x;
a2x1=r1*r2*bet;
a2x=a2x1+(r1+r2)*bet;
String aa="if u both match wins: "+ a2x1;
String aa2="if u both match wins: "+a2x;
String aa3="if first match wins: "+(r1*bet);
String aa4="if second match wins: "+(r2*bet);
ans.setText(aa);
ans2.setText(aa2);
ans3.setText(aa3);
ans4.setText(aa4);
}
@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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Upvotes: 1
Views: 40
Reputation: 288
it will help you
change the position of your
instead of your coding put these lines in the oncreate
super.onCreate(savedInstanceState);
setContentView(R.layout.res2);
ans3=(TextView)findViewById(R.id.textView5);
ans=(TextView)findViewById(R.id.textView2);
ans2=(TextView)findViewById(R.id.textView4);
ans4=(TextView)findViewById(R.id.textView6);
Upvotes: 0
Reputation: 714
Change your oncreate() method
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.res2);
ans3=(TextView)findViewById(R.id.textView5);
ans=(TextView)findViewById(R.id.textView2);
ans2=(TextView)findViewById(R.id.textView4);
ans4=(TextView)findViewById(R.id.textView6);
}
Upvotes: 2