별도의 클래스 파일에 포함 된 함수를 사용하는 방법을 찾는 데 문제가 있습니다.안드로이드 애플 리케이션에서 별도의 클래스 파일을 사용할 때이 오류를 도와주세요
내 별도의 클래스 파일은 EncounterGenerator.java라고합니다. 그래서 아래
EncounterGenerator Encounter;
testString = Encounter.EncounterGeneratorText();
package mot.HelloAndroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
TextView tvIntro;
TextView tvNavigator;
TextView tvAction;
EncounterGenerator Encounter ;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
//setup text views
this.setContentView(R.layout.main);
tvIntro = (TextView)findViewById(R.id.tvIntro);
tvNavigator = (TextView)findViewById(R.id.tvNavigator);
tvAction = (TextView)findViewById(R.id.tvAction);
//display game intro
tvIntro.setText("Text Adventure");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tvIntro.setText("This is a really cool text adventure game!");
//define navigation buttons
Button btnNorth = (Button)findViewById(R.id.btnNorth);
btnNorth.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tvIntro.setText("You go north");
String testString = "nothing";
try {
testString = Encounter.EncounterGeneratorText();
} catch (Exception e) {
e.printStackTrace();
}
testString = Encounter.EncounterGeneratorText();
tvIntro.setText(testString);
}
});
}
}
을하고이 EncounterGenerator라는 내 별도의 클래스 파일입니다 그리고 다음과 같이 호출. java :
package mot.HelloAndroid;
public class EncounterGenerator {
public String EncounterGeneratorText() {
String encounterText = "test value";
return encounterText;
}
}
매번 내가 그것을 실행 한 다음 함수 EncounterGeneratorText() 내 AVP이 오류 얻을 호출 버튼을 클릭
사람이 만약 다시 시도하십시오 ...
안녕하세요 안드로이드 애플리케이션이 예기치 않게 중지되었습니다를 도울 수있어, 크게 감사하겠습니다!
@MByD의 답이 맞습니다. 일반적으로 오류가 발생하면 Eclipse에서'adb logcat', DDMS 또는 DDMS 퍼스펙티브를 사용하여 LogCat을 검사하고 오류와 관련된 스택 추적을 살펴보십시오. 이 경우, 당신은'NullPointerException'을 가질 것이고, 예외가 발생한 라인 번호를 나타낼 것이다. – CommonsWare