public class MainClass extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent1 = new Intent(MainClass.this, SecondClass.class);
startActivity(intent1);
}
//---------------------------------------------
public class SecondClass extends Activity {
ThirdClass thirdclass;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.keyboard);
thirdclass.Random_Method('A');
}
//---------------------------------------------
public class ThirdClass extends Activity {
public void Random_Method(char NewChar) {
}
答案 0 :(得分:1)
我发现了几个可能的问题:
答案 1 :(得分:0)
ThirdClass第三类从未被初始化。将代码更改为
thirdclass = new ThirdClass();
thirdclass.Random_Method(‘A’);
或者,或者,这样做:
new ThirdClass().RandomMethod('A');
此外,ThirdClass不需要扩展Activity(除非你能解释它为什么需要,否则它不应该)。
编辑:
如果它确实需要扩展Activity,那么你应该像MainClass用Intent切换到SecondClass一样切换到ThirdClass。或者重新考虑您的活动的工作方式,以便此TextView在SecondClass中发生。第二个就像:
public class SecondClass extends Activity {
TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.keyboard);
textView = (TextView) findViewById(R.id.something);
random_Method('A');
}
public void random_Method(char NewChar) {
}
答案 2 :(得分:0)
ThirdClass尚未初始化。您将需要使Random_Method静态或使用
thirdclass = new ThirdClass()