大家好,我坚持对函数进行简单的调用。这是我来自 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