こんにちは、私は関数への単純な呼び出しを行うことにこだわっています。これは、私が iPhone から取得した最初の Android アプリです。onCreate() で何かをしているたびに、アプリがクラッシュします..問題は非常に単純だと確信しています
public class AndroidReaderActivity extends Activity {
public void test(){
File dir=new File("/assets");
String[] listefichiers;
int i;
listefichiers = dir.list();
for (i = 0; i < listefichiers.length; i++) {
System.out.println(listefichiers[i]);
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
test();
}
}
助けてくれてありがとう。
編集:ここに猫のログがあります
05-15 19:52:55.710: E/AndroidRuntime(1956): FATAL EXCEPTION: main
05-15 19:52:55.710: E/AndroidRuntime(1956): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.infotel/com.infotel.AndroidReaderActivity}: java.lang.NullPointerException
05-15 19:52:55.710: E/AndroidRuntime(1956): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-15 19:52:55.710: E/AndroidRuntime(1956): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-15 19:52:55.710: E/AndroidRuntime(1956): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-15 19:52:55.710: E/AndroidRuntime(1956): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-15 19:52:55.710: E/AndroidRuntime(1956): at android.os.Handler.dispatchMessage(Handler.java:99)
05-15 19:52:55.710: E/AndroidRuntime(1956): at android.os.Looper.loop(Looper.java:137)
05-15 19:52:55.710: E/AndroidRuntime(1956): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-15 19:52:55.710: E/AndroidRuntime(1956): at java.lang.reflect.Method.invokeNative(Native Method)
05-15 19:52:55.710: E/AndroidRuntime(1956): at java.lang.reflect.Method.invoke(Method.java:511)
05-15 19:52:55.710: E/AndroidRuntime(1956): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-15 19:52:55.710: E/AndroidRuntime(1956): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-15 19:52:55.710: E/AndroidRuntime(1956): at dalvik.system.NativeStart.main(Native Method)
05-15 19:52:55.710: E/AndroidRuntime(1956): Caused by: java.lang.NullPointerException
05-15 19:52:55.710: E/AndroidRuntime(1956): at com.infotel.AndroidReaderActivity.test(AndroidReaderActivity.java:14)
05-15 19:52:55.710: E/AndroidRuntime(1956): at com.infotel.AndroidReaderActivity.onCreate(AndroidReaderActivity.java:23)
05-15 19:52:55.710: E/AndroidRuntime(1956): at android.app.Activity.performCreate(Activity.java:4465)
05-15 19:52:55.710: E/AndroidRuntime(1956): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-15 19:52:55.710: E/AndroidRuntime(1956): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-15 19:52:55.710: E/AndroidRuntime(1956): ... 11 more