当我在手机中试用时,文字没有到来,应用程序将停止.......任何人都可以帮忙? 调试无法找到错误,其他帧没有问题,除此之外。 问题来自TextView ......如果我剪掉线条,错误就不会出现
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);
}
}
答案 0 :(得分:2)
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);
}
答案 1 :(得分:0)
它会帮助你
更改
的位置而不是你的编码将这些行放在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);