我尝试在(对我来说)非静态方法中使用非静态方法,但他只是说我不能使用非静态方法而不是静态方法...
我不知道应该尝试什么,所以我只是问。
行中的问题
public void Rassen(View v){
Rassen.ContentRassen();
}
这里有一些代码:
package thetruenerathul.pathfinder001;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import thetruenerathul.pathfinder001.NewCharacter.Rassen;
import static thetruenerathul.pathfinder001.R.layout.rassen;
public class Pathfinder extends AppCompatActivity {
public static String[] Charakter = new String[3];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pathfinder);
}
public void NewCharacter(View v){
setContentView(R.layout.name);
}
public void ContentName(View v){
EditText Name = (EditText)findViewById(R.id.TfName);
Charakter[0] = Name.getText().toString();
setContentView(rassen);
}
public void Rassen(View v){
Rassen.ContentRassen();
}
public void ContentZurueck(View v){
setContentView(R.layout.activity_pathfinder);
}
}
和Content of Rassen()
public class Rassen extends AppCompatActivity {
public void ContentRassen(View View){
Rasse(View);
setContentView(R.layout.klassen);
}
private void Rasse(View View){
Button Rasse;
switch(View.getId())
{
case R.id.BtZwerg:
Rasse = (Button)findViewById(R.id.BtZwerg);
Pathfinder.Charakter[1] = Rasse.getText().toString();
break;
case R.id.BtHalbling:
Rasse = (Button)findViewById(R.id.BtHalbling);
Pathfinder.Charakter[1] = Rasse.getText().toString();
break;
case R.id.BtElf:
Rasse = (Button)findViewById(R.id.BtElf);
Pathfinder.Charakter[1] = Rasse.getText().toString();
break;
case R.id.BtMensch:
Rasse = (Button)findViewById(R.id.BtMensch);
Pathfinder.Charakter[1] = Rasse.getText().toString();
break;
case R.id.BtGnom:
Rasse = (Button)findViewById(R.id.BtGnom);
Pathfinder.Charakter[1] = Rasse.getText().toString();
break;
case R.id.BtHalbOrk:
Rasse = (Button)findViewById(R.id.BtHalbOrk);
Pathfinder.Charakter[1] = Rasse.getText().toString();
break;
case R.id.BtHalbElf:
Rasse = (Button)findViewById(R.id.BtHalbElf);
Pathfinder.Charakter[1] = Rasse.getText().toString();
break;
}
}
}
答案 0 :(得分:0)
嗯,您正在使用类而不是按对象访问该方法。
如果要按类名访问该方法,则需要将该方法定义为静态,如下面的
public static void ContentRassen(View View){
Rasse(View);
setContentView(R.layout.klassen);
}
Rassen.ContentRassen();
对于非静态 - 您需要创建实例,然后使用实例Object
调用该方法