I have SDK and NDK installed for which I have written  a small program
in .c file which displays "Hello from Native code".

The java code for the native code is as follows:

public class flash extends Activity {
          // load the library - name matches jni/Android.mk
        static {
                System.loadLibrary("AndroidFlash");
                }
        // declare the native code function - must match ndkfoo.c
        private native String invokeNativeFunction();
    /** Called when the activity is first created. */
    //@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

     // this is where we call the native code
       String hello = invokeNativeFunction();
       new AlertDialog.Builder(this).setMessage(hello).show();
    }
}




The native .C code for the above is as follows:


jstring
Java_com_mindtherobot_samples_ndkfoo_NdkFooActivity_invokeNativeFunction(JNIEnv*
env, jobject javaThis){
        return (*env)->NewStringUTF(env, "Hello from native code!");
}



When I build, it builds successfully,but when I run the program as
emulator, the application crashes after some time and my native code
is never displayed. Plz let me know what could be the problem.


This is the log which I have dumped during error using DDMS:

Error Dump:


04-06 10:10:35.674: INFO/vold(27): Aborting start of /sdcard
(bootstrap = 1)
04-06 10:10:35.674: INFO/vold(27): Volmgr not ready to handle device
04-06 10:10:35.674: ERROR/vold(27): Error opening switch name path '/
sys/class/switch/test' (No such file or directory)
04-06 10:10:35.674: ERROR/vold(27): Error bootstrapping switch '/sys/
class/switch/test' (No such file or directory)
04-06 10:10:35.674: ERROR/vold(27): Error opening switch name path '/
sys/class/switch/test2' (No such file or directory)
04-06 10:10:35.674: ERROR/vold(27): Error bootstrapping switch '/sys/
class/switch/test2' (No such file or directory)

04-06 10:10:46.755: INFO/dalvikvm(30): System server process 52 has
been created
04-06 10:10:46.755: INFO/Zygote(30): Accepting command socket
connections
04-06 10:10:46.864: DEBUG/dalvikvm(52): Trying to load lib /system/lib/
libandroid_servers.so 0x0
04-06 10:10:47.044: DEBUG/dalvikvm(52): Added shared lib /system/lib/
libandroid_servers.so 0x0
04-06 10:10:47.054: ERROR/BatteryService(52): usbOnlinePath not found
04-06 10:10:47.054: ERROR/BatteryService(52): batteryVoltagePath not
found
04-06 10:10:47.054: ERROR/BatteryService(52): batteryTemperaturePath
not found
04-06 10:10:47.064: INFO/sysproc(52): Entered system_init()

04-06 10:10:47.064: INFO/SurfaceFlinger(52): SurfaceFlinger's main
thread ready to run. Initializing graphics H/W...
04-06 10:10:47.073: ERROR/SurfaceFlinger(52): Couldn't open /sys/power/
wait_for_fb_sleep or /sys/power/wait_for_fb_wake
04-06 10:10:47.085: INFO/gralloc(52): using (fd=22)
04-06 10:10:47.085: INFO/gralloc(52): id           =

devname='qwerty' propName='hw.keyboards.0.devname' keylayout='/system/
usr/keylayout/qwerty.kl'
04-06 10:10:51.014: INFO/EventHub(52): New device: path=/dev/input/
event0 name=qwerty id=0x10000 (of 0x1) index=1 fd=48 classes=0x2f
04-06 10:10:51.014: ERROR/EventHub(52): could not get driver version
for /dev/input/mouse0, Not a typewriter
04-06 10:10:51.014: ERROR/EventHub(52): could not get driver version
for /dev/input/mice, Not a typewriter
04-06 10:10:51.014: INFO/KeyInputQueue(52): Device added: id=0x0,
name=qwerty, classes=2f
04-06 10:10:51.014: INFO/KeyInputQueue(52):   X: unknown values
04-06 10:10:51.023: INFO/KeyInputQueue(52):   Y: unknown values

04-06 10:10:51.254: INFO/SystemServer(52): Registering null Bluetooth
Service (emulator)
04-06 10:10:51.264: ERROR/System(52): Failure starting core service
04-06 10:10:51.264: ERROR/System(52): java.lang.SecurityException
04-06 10:10:51.264: ERROR/System(52):     at
android.os.BinderProxy.transact(Native Method)
04-06 10:10:51.264: ERROR/System(52):     at
android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:
146)
04-06 10:10:51.264: ERROR/System(52):     at
android.os.ServiceManager.addService(ServiceManager.java:72)
04-06 10:10:51.264: ERROR/System(52):     at
com.android.server.ServerThread.run(SystemServer.java:176)
04-06 10:10:51.273: ERROR/AndroidRuntime(52): Crash logging skipped,
no checkin service
04-06 10:10:51.273: INFO/SystemServer(52): Status Bar
04-06 10:10:51.443: INFO/SystemServer(52): Clipboard Service

04-06 10:11:00.477: DEBUG/dalvikvm(94): GC freed 3860 objects / 233648
bytes in 373ms
04-06 10:11:00.666: ERROR/ActivityThread(94): Failed to find provider
info for android.server.checkin
04-06 10:11:00.666: WARN/Checkin(94): Can't update stat
PHONE_GSM_REGISTERED:

04-06 10:11:02.235: DEBUG/TelephonyProvider(94): Setting numeric
'310260' to be the current operator
04-06 10:11:02.315: ERROR/ActivityThread(94): Failed to find provider
info for android.server.checkin
04-06 10:11:02.315: WARN/Checkin(94): Can't update stat
PHONE_GPRS_ATTEMPTED:
04-06 10:11:02.405: DEBUG/ConnectivityService(52): ConnectivityChange
for MOBILE: CONNECTING/CONNECTING
04-06 10:11:02.446: ERROR/ActivityThread(94): Failed to find provider
info for android.server.checkin
04-06 10:11:02.446: WARN/Checkin(94): Can't update stat
PHONE_GPRS_CONNECTED:

04-06 10:11:04.846: DEBUG/MediaPlayer(52): Couldn't open file on
client side, trying server side
04-06 10:11:04.896: ERROR/MediaPlayerService(31): Couldn't open fd for
content://settings/system/notification_sound
04-06 10:11:04.967: ERROR/MediaPlayer(52): Unable to to create media
player
04-06 10:11:05.025: INFO/ActivityThread(97): Publishing provider

04-06 10:11:11.657: DEBUG/dalvikvm(133): VM cleaning up
04-06 10:11:11.696: ERROR/AndroidRuntime(133): ERROR: thread attach
failed
04-06 10:11:11.747: DEBUG/dalvikvm(133): LinearAlloc 0x0 used 621708
of 5242880 (11%)

04-06 10:11:15.966: DEBUG/dalvikvm(199): VM cleaning up
04-06 10:11:15.986: ERROR/AndroidRuntime(199): ERROR: thread attach
failed
04-06 10:11:16.076: INFO/ActivityManager(52): Start proc
android.flash.com for activity

04-06 10:11:17.566: WARN/dalvikvm(221): threadid=3: thread exiting
with uncaught exception (group=0x4001b188)
04-06 10:11:17.575: ERROR/AndroidRuntime(221): Uncaught handler:
thread main exiting due to uncaught exception
04-06 10:11:17.636: ERROR/AndroidRuntime(221):
java.lang.UnsatisfiedLinkError: invokeNativeFunction
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
android.flash.com.flash.invokeNativeFunction(Native Method)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
android.flash.com.flash.onCreate(flash.java:22)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2459)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2512)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
android.os.Handler.dispatchMessage(Handler.java:99)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
android.os.Looper.loop(Looper.java:123)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
android.app.ActivityThread.main(ActivityThread.java:4363)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
java.lang.reflect.Method.invokeNative(Native Method)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
java.lang.reflect.Method.invoke(Method.java:521)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-06 10:11:17.636: ERROR/AndroidRuntime(221):     at
dalvik.system.NativeStart.main(Native Method)
04-06 10:11:17.665: INFO/Process(52): Sending signal. PID: 221 SIG: 3
04-06 10:11:17.677: INFO/dalvikvm(221): threadid=7: reacting to signal
3
04-06 10:11:17.677: ERROR/dalvikvm(221): Unable to open stack trace
file '/data/anr/traces.txt': Permission denied

scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at
[0x47c760:0x47c928] in 1425100 ns
04-06 10:12:19.806: ERROR/gralloc(52): [unregister] handle 0x2e0588
still locked (state=40000001)
04-06 10:12:19.846: INFO/ActivityManager(52): Displayed activity
com.android.launcher/.Launcher: 87309 ms (total 87309 ms)







-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to