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) {

    }

最佳答案

ThirdClass thirdclass从未被初始化。将代码更改为

thirdclass = new ThirdClass();
thirdclass.Random_Method(‘A’);


或者,也可以这样做:

new ThirdClass().RandomMethod('A');


同样,ThirdClass不需要扩展Activity(除非您可以解释为什么需要扩展,否则它不需要扩展)。

编辑:

如果确实需要扩展Activity,那么您应该以与MainClass意图切换到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) {

    }

10-05 17:45