I am porting my C/C++ code into an Android Game using the NDK, but I'm having trouble getting started.
I have downloaded the NDK-r5b from developer.android.com and I have installed Cygwin.
I am not even able to run the Hello-jni program provided within the NDK samples.
When I run:
$ cd /cygdrive/c/android/android-ndk-r5b/samples/hello-jni
$ ndk-build
I get an ERROR: You are using a non-Cygwin compatible Make program.
I tried installing GNUMake 3.81 but the problem persists.
I tried to run the HELLO-JNI sample program in the NDK through Eclipse IDE. There is a force close on the Android AVD, and logcat was showing an exception as follows:
04-08 12:32:11.609: ERROR/AndroidRuntime(274): FATAL EXCEPTION: main
04-08 12:32:11.609: ERROR/AndroidRuntime(274):
java.lang.ExceptionInInitializerError
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.Class.newInstanceImpl(Native Method)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.Class.newInstance(Class.java:1429)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2577)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2679)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.os.Handler.dispatchMessage(Handler.java:99)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.os.Looper.loop(Looper.java:123)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
android.app.ActivityThread.main(ActivityThread.java:4627)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.reflect.Method.invokeNative(Native Method)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.reflect.Method.invoke(Method.java:521)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
dalvik.system.NativeStart.main(Native Method)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): Caused by:
java.lang.UnsatisfiedLinkError: Library hello-jni not found
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.Runtime.loadLibrary(Runtime.java:461)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
java.lang.System.loadLibrary(System.java:557)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): at
com.example.hellojni.HelloJni.<clinit>(HelloJni.java:67)
04-08 12:32:11.609: ERROR/AndroidRuntime(274): ... 15 more
04-08 12:32:11.678: WARN/ActivityManager(59): Force finishing
activity com.example.hellojni/.HelloJni
04-08 12:32:12.340: WARN/ActivityManager(59): Activity pause timeout
for HistoryRecord{44f925c8 com.example.hellojni/.HelloJni}
How can I make this work?
I had this same issue and I figured it out. The thing that was causing it to mess up for me was in Project Properties -> C/C++ Build -> Build command: was set to 'bash ndk-build' instead of 'bash C:\android-ndk-r6\ndk-build'
I had this problem. It turned out that the GNU tool chain was not installed when I installed Cygwin, and make was being picked up from another SDK installed on my build machine. The fix was to reinstall Cygwin and check that the Gnu tools were installed. (I think the heading is 'Devel' in the Cygwin setup. The default is not to install, change to 'install'). HTH
I tackled this in Eclipse by doing the following:
Right click on the project name and choose "properties"
In the "C/C++ Build" choose "builder section" then in the "builder" group put the following in the "build command" textbox:
bash "_cygwin_home_\home\android-ndk-r6b\ndk-build"
replace "_cygwin_home_" with your actual path to cygwin,
I place the ndk folder inside the home folder in the cygwin installtion folder(as you can see).
I hope this help you.
Related
Decided to use Scandit SDK to get the barcode scanning feature in my app. Unfortunately, since I'm relatively new to Android development and Java in general I've run into a few issues that I can't seem to work out. The demo that Scandit provided doesn't give any errors(runs fine) but crashes when I try to start it up (pressing a button from one activity is meant to start it up). I've tried reading the logcat and googling a solution to the problems but I'm not getting the right solutions. Does anyone have an idea of what I'm doing wrong?
Logcat is provided below:
10-08 23:30:00.807 21563-21563/com.kwesimbia.management D/AndroidRuntime? Shutting down VM
10-08 23:30:00.807 21563-21563/com.kwesimbia.management W/dalvikvm? threadid=1: thread exiting with uncaught exception (group=0x40aa4228)
10-08 23:30:00.817 21563-21563/com.kwesimbia.management E/AndroidRuntime? FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3082)
at android.view.View.performClick(View.java:3549)
at android.view.View$PerformClick.run(View.java:14393)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4944)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3077)
at android.view.View.performClick(View.java:3549)
at android.view.View$PerformClick.run(View.java:14393)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4944)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com.kwesimbia.management.ScanditSDKDemoSimple
at com.kwesimbia.management.Activity_D.initiateCodeScan(Activity_D.java:63)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3077)
at android.view.View.performClick(View.java:3549)
at android.view.View$PerformClick.run(View.java:14393)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4944)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
10-08 23:30:00.817 32726-587/? E/EmbeddedLogger? App crashed!
Process: com.kwesimbia.management
10-08 23:30:00.817 32726-587/? E/EmbeddedLogger? App crashed!
Package: com.kwesimbia.management v1 (1.0)
10-08 23:30:00.817 32726-587/? E/EmbeddedLogger?
Application Label: firstapp
10-08 23:30:00.827 32726-587/? W/ActivityManager?
Force finishing activity com.kwesimbia.management/.Activity_D
I came across this problem as well, my solution was to extract the library files and put them as their files in the lib folder
The library basically isn't being exported with it
EDIT
So I checked out my project, basically I did these things:
In the libs folder I have a new folder called armeabi and inside that I have libscanditsdk-android-3.3.1.so
Then in my build path I have also referenced the jar file that they provide:
<classpathentry exported="true" kind="lib" path="C:/GIT/Android/FwayScannerProject/FwayScanner/libs/scanditsdk-barcodepicker-android-3.3.1.jar"/>
i know this question has been treated so much time, but i really don't find the answer to my problem.
This is an application which connect to a server, so, there's a socket, that's why i'm using thread (i can't do anything else since android 4.0), but even if i'm disable the code of my socket, it still crash.
Here's the logCat error :
04-08 08:36:39.366: D/AndroidRuntime(16604): Shutting down VM
04-08 08:36:39.366: W/dalvikvm(16604): threadid=1: thread exiting with uncaught exception (group=0x4122f300)
04-08 08:36:39.366: E/AndroidRuntime(16604): FATAL EXCEPTION: main
04-08 08:36:39.366: E/AndroidRuntime(16604): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.projetlyres2013/com.example.projetlyres2013.PlanDMX}: java.lang.NullPointerException
04-08 08:36:39.366: E/AndroidRuntime(16604): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
04-08 08:36:39.366: E/AndroidRuntime(16604): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-08 08:36:39.366: E/AndroidRuntime(16604): at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-08 08:36:39.366: E/AndroidRuntime(16604): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-08 08:36:39.366: E/AndroidRuntime(16604): at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 08:36:39.366: E/AndroidRuntime(16604): at android.os.Looper.loop(Looper.java:137)
04-08 08:36:39.366: E/AndroidRuntime(16604): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-08 08:36:39.366: E/AndroidRuntime(16604): at java.lang.reflect.Method.invokeNative(Native Method)
04-08 08:36:39.366: E/AndroidRuntime(16604): at java.lang.reflect.Method.invoke(Method.java:511)
04-08 08:36:39.366: E/AndroidRuntime(16604): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-08 08:36:39.366: E/AndroidRuntime(16604): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-08 08:36:39.366: E/AndroidRuntime(16604): at dalvik.system.NativeStart.main(Native Method)
04-08 08:36:39.366: E/AndroidRuntime(16604): Caused by: java.lang.NullPointerException
04-08 08:36:39.366: E/AndroidRuntime(16604): at android.app.Activity.findViewById(Activity.java:1825)
04-08 08:36:39.366: E/AndroidRuntime(16604): at com.example.projetlyres2013.PlanDMX.<init>(PlanDMX.java:27)
04-08 08:36:39.366: E/AndroidRuntime(16604): at java.lang.Class.newInstanceImpl(Native Method)
04-08 08:36:39.366: E/AndroidRuntime(16604): at java.lang.Class.newInstance(Class.java:1319)
04-08 08:36:39.366: E/AndroidRuntime(16604): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
04-08 08:36:39.366: E/AndroidRuntime(16604): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
04-08 08:36:39.366: E/AndroidRuntime(16604): ... 11 more
04-08 08:36:41.326: I/Process(16604): Sending signal. PID: 16604 SIG: 9
04-08 08:46:26.556: D/AndroidRuntime(16825): Shutting down VM
///////// Manifest /////////
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.projetlyres2013"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.projetlyres2013.PlanDMX"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I don't know what's happened when i want to launch it on my tablet (android 4.1).
I really need help for that :/
Thanks
NullPointer here means that you did not set your layout XML as contentView to your Activity.
Inside onCreate(...) method of Activity add
setContentView(R.layout.some_layout-file)
i'm getting this message when i run my application i don't know why i'm getting it could any one help me. here is the logcat.
java.lang.VerifyError: com.kosh.me.Smaller
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
at dalvik.system.NativeStart.main(Native Method)
This happens when the build library classes conflict with those at run-time. Try performing a Clean of your project followed by a build.
Two days ago, when my android project in eclipse still worked, I added "android SDK 4.0.3" to my SDKs (in addition to android SDK 2.1).
From that moment on, I have a trouble with slf4j-android library; here's the exception:
Uncaught handler: thread main exiting due to uncaught exception
java.lang.ExceptionInInitializerError
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1479)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at it.cefriel.swa.urbanopoly.client.game.UrbanopolyActivity.<clinit>(UrbanopolyActivity.java:11)
The JAR I use is slf4j-android-1.5.8.jar. The build path seems correctly setted. I also tried to create another project using slf4j and I got the same error..
Any Ideas?
Thanks in advance
Try adding the slf4j-api-1.5.8.jar or latest version as well with the current slf4j-android-1.5.8.jar
I have added the Results class to the Android Manifest, so yes, you can cross that off the list.
Is it an error in the way I've set out the method?
package com.kenning.foreveralone;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
public class Results extends Activity{
EditText fbFriends;
TextView resulting;
String value;
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.rslt);
TextView resulting = (TextView) findViewById(R.id.result);
EditText fbFriends = (EditText) findViewById(R.id.noFacebookFriends);
String value = fbFriends.getText().toString();
resulting.setText("Your score is " + value);
}
}
When I start this class, it always seems to force close my app. Can anyone tell me what I'm doing wrong?
Here's the log cat:
04-08 20:05:24.169: E/AndroidRuntime(589): FATAL EXCEPTION: main
04-08 20:05:24.169: E/AndroidRuntime(589): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kenning.foreveralone/com.kenning.foreveralone.Results}: java.lang.NullPointerException
04-08 20:05:24.169: E/AndroidRuntime(589): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-08 20:05:24.169: E/AndroidRuntime(589): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-08 20:05:24.169: E/AndroidRuntime(589): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-08 20:05:24.169: E/AndroidRuntime(589): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-08 20:05:24.169: E/AndroidRuntime(589): at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 20:05:24.169: E/AndroidRuntime(589): at android.os.Looper.loop(Looper.java:123)
04-08 20:05:24.169: E/AndroidRuntime(589): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-08 20:05:24.169: E/AndroidRuntime(589): at java.lang.reflect.Method.invokeNative(Native Method)
04-08 20:05:24.169: E/AndroidRuntime(589): at java.lang.reflect.Method.invoke(Method.java:521)
04-08 20:05:24.169: E/AndroidRuntime(589): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-08 20:05:24.169: E/AndroidRuntime(589): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-08 20:05:24.169: E/AndroidRuntime(589): at dalvik.system.NativeStart.main(Native Method)
04-08 20:05:24.169: E/AndroidRuntime(589): Caused by: java.lang.NullPointerException
04-08 20:05:24.169: E/AndroidRuntime(589): at com.kenning.foreveralone.Results.onCreate(Results.java:20)
04-08 20:05:24.169: E/AndroidRuntime(589): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-08 20:05:24.169: E/AndroidRuntime(589): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-08 20:05:24.169: E/AndroidRuntime(589): ... 11 more
It's a null pointer exception in onCreate, so why not try stepping through onCreate to see what variable is null?
That said, I'm guessing R.id.noFacebookFriends is not part of the R.layout.rslt.
You are getting a NullPointerException somewhere in your OnCreate. I am guessing that either the ids are wrong in your rslt.xml layout so result and fbFriends is null, or fbFriends doesn't have any text in it so getText() returns null.