Error when taking a screenshot in Android - android

I'm trying to take a screen shot of a chart I'm drawing, but everytime I try I get a NullExceptionPointer.
Here is my code :
lineChart.setChartData(array1,array2,xd);
View v1 = lineChart.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
Where lineChart is a custom View
This logcat indicates this line as null: bitmap = Bitmap.createBitmap(v1.getDrawingCache());
here is my logcat :
04-01 19:21:11.524: E/AndroidRuntime(333): FATAL EXCEPTION: main
04-01 19:21:11.524: E/AndroidRuntime(333): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.appui/com.example.appui.CompareActivity}: java.lang.NullPointerException
04-01 19:21:11.524: E/AndroidRuntime(333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-01 19:21:11.524: E/AndroidRuntime(333): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-01 19:21:11.524: E/AndroidRuntime(333): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-01 19:21:11.524: E/AndroidRuntime(333): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-01 19:21:11.524: E/AndroidRuntime(333): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 19:21:11.524: E/AndroidRuntime(333): at android.os.Looper.loop(Looper.java:123)
04-01 19:21:11.524: E/AndroidRuntime(333): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-01 19:21:11.524: E/AndroidRuntime(333): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 19:21:11.524: E/AndroidRuntime(333): at java.lang.reflect.Method.invoke(Method.java:507)
04-01 19:21:11.524: E/AndroidRuntime(333): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-01 19:21:11.524: E/AndroidRuntime(333): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-01 19:21:11.524: E/AndroidRuntime(333): at dalvik.system.NativeStart.main(Native Method)
04-01 19:21:11.524: E/AndroidRuntime(333): Caused by: java.lang.NullPointerException
04-01 19:21:11.524: E/AndroidRuntime(333): at android.graphics.Bitmap.createBitmap(Bitmap.java:367)
04-01 19:21:11.524: E/AndroidRuntime(333): at com.example.appui.CompareActivity.onCreate(CompareActivity.java:37)
04-01 19:21:11.524: E/AndroidRuntime(333): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-01 19:21:11.524: E/AndroidRuntime(333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-01 19:21:11.524: E/AndroidRuntime(333): ... 11 more

I haven't used getRootView, but the documentation states it
Returns the topmost view containing this view
If it is the topmost View by itself, it would return null. Try
View v1 = (View)lineChart;
instead.
From the documentation (and from here) , I guess you could force the Drawing Cache to be built by adding
// this is the important code :)
// Without it the view will have a dimension of 0,0 and the bitmap will be null
v1.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v1.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v1.buildDrawingCache();
before you get the bitmap with
bitmap = Bitmap.createBitmap(v1.getDrawingCache());

The documentation for View.getDrawingCache(boolean) states:
Returns the bitmap in which this view drawing is cached. The returned
bitmap is null when caching is disabled.
Set the drawing cache to true using setDrawingCacheEnabled(boolean). You can also check if the drawing cache is enabled using isDrawingCacheEnabled().

Related

Unfortunately application has stopped using google map api v2

this is my log file
04-01 17:21:32.460: E/dalvikvm(296): Could not find class 'android.app.Notification$Builder', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
04-01 17:21:32.470: E/dalvikvm(296): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
04-01 17:21:32.651: E/AndroidRuntime(296): FATAL EXCEPTION: main
04-01 17:21:32.651: E/AndroidRuntime(296): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tutos.android.gmapv2/com.tutos.android.gmapv2.MyMapActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
04-01 17:21:32.651: E/AndroidRuntime(296): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.os.Looper.loop(Looper.java:123)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-01 17:21:32.651: E/AndroidRuntime(296): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 17:21:32.651: E/AndroidRuntime(296): at java.lang.reflect.Method.invoke(Method.java:521)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-01 17:21:32.651: E/AndroidRuntime(296): at dalvik.system.NativeStart.main(Native Method)
04-01 17:21:32.651: E/AndroidRuntime(296): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
04-01 17:21:32.651: E/AndroidRuntime(296): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:582)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.app.Activity.setContentView(Activity.java:1647)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.tutos.android.gmapv2.MyMapActivity.onCreate(MyMapActivity.java:19)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-01 17:21:32.651: E/AndroidRuntime(296): ... 11 more
04-01 17:21:32.651: E/AndroidRuntime(296): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 7095000 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
04-01 17:21:32.651: E/AndroidRuntime(296): at com.google.android.gms.common.GooglePlayServicesUtil.zzJ(Unknown Source)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.google.android.gms.maps.internal.zzx.zzad(Unknown Source)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.google.android.gms.maps.internal.zzx.zzac(Unknown Source)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.google.android.gms.maps.SupportMapFragment$zzb.zzqs(Unknown Source)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.google.android.gms.dynamic.zza.zza(Unknown Source)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
04-01 17:21:32.651: E/AndroidRuntime(296): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
04-01 17:21:32.651: E/AndroidRuntime(296): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
04-01 17:21:32.651: E/AndroidRuntime(296): ... 19 more
04-01 17:25:30.440: E/dalvikvm(305): Could not find class 'android.app.Notification$Builder', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
04-01 17:25:30.460: E/dalvikvm(305): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
04-01 17:25:30.530: E/AndroidRuntime(305): FATAL EXCEPTION: main
04-01 17:25:30.530: E/AndroidRuntime(305): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tutos.android.gmapv2/com.tutos.android.gmapv2.MyMapActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
04-01 17:25:30.530: E/AndroidRuntime(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.os.Looper.loop(Looper.java:123)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-01 17:25:30.530: E/AndroidRuntime(305): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 17:25:30.530: E/AndroidRuntime(305): at java.lang.reflect.Method.invoke(Method.java:521)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-01 17:25:30.530: E/AndroidRuntime(305): at dalvik.system.NativeStart.main(Native Method)
04-01 17:25:30.530: E/AndroidRuntime(305): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
04-01 17:25:30.530: E/AndroidRuntime(305): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:582)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.app.Activity.setContentView(Activity.java:1647)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.tutos.android.gmapv2.MyMapActivity.onCreate(MyMapActivity.java:19)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-01 17:25:30.530: E/AndroidRuntime(305): ... 11 more
04-01 17:25:30.530: E/AndroidRuntime(305): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 7095000 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
04-01 17:25:30.530: E/AndroidRuntime(305): at com.google.android.gms.common.GooglePlayServicesUtil.zzJ(Unknown Source)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.google.android.gms.maps.internal.zzx.zzad(Unknown Source)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.google.android.gms.maps.internal.zzx.zzac(Unknown Source)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.google.android.gms.maps.SupportMapFragment$zzb.zzqs(Unknown Source)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.google.android.gms.dynamic.zza.zza(Unknown Source)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
04-01 17:25:30.530: E/AndroidRuntime(305): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
04-01 17:25:30.530: E/AndroidRuntime(305): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
04-01 17:25:30.530: E/AndroidRuntime(305): ... 19 more
Your manifest.xml file is missing the below line, just add it and it should fix your problem.
Edit your application's AndroidManifest.xml file, and add the following declaration within the element. This embeds the version of Google Play services that the app was compiled with.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Android developers guide for more details https://developers.google.com/maps/documentation/android/start

My app freezes crashes when it's supposed to go to the next activity

I don't know why the app crashes whenever it's supposed to go to the next Activity. I made a practice app that works as it should when using the same format. I uploaded the files to gist.github.
The error is
1216-1216/com.example.chiozokamalu.newfreshstart E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ArrayIndexOutOfBoundsException
at com.example.chiozokamalu.newfreshstart.MainActivity.onClick(MainActivity.java:164)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
On line 164 of MainActivity.java:
questionView.setText(questions[questionIndex]); // set the text to the next question
EDIT: After Varun helped me, I get a new error which is
1307-1307/com.example.chiozokamalu.newfreshstart E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chiozokamalu.newfreshstart/com.example.chiozokamalu.newfreshstart.Results1}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.chiozokamalu.newfreshstart.Results1.onCreate(Results1.java:58)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3683)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
            at dalvik.system.NativeStart.main(Native Method)
The questions array at line no. 164 is going out of bound that means questionIndex is greater than the total length of the questions array. So you should add a check on the length before extracting value from the array.
You have added the check but after that you incremented the value so either you modify the if condition to if (questionIndex < questions.length -1)
or modify the questionIndex variable before the if condition
You are getting problem because you haven't initiated resultView9 that is why it is null and giving nullpointer, just initiatlise it as you done with other and everything is fine. You have initialised the resultView8 twice just add resultview9 over there

How to properly name native functions when using the NDK

I am trying to run my application, but whenever I make a call to a native function it gives me an error and the program crashes. I'm sure it has to do with how I am naming something either in Java or in C.
Here is my call to the functions in Java :
package my.commander;
public class RelayAPIModel {
public static class NativeCalls {
static {
System.loadLibrary( "RelayAPI");
}
public native static byte InitRelayJava();
public native static void FreeRelayJava();
}
Here are the functions in the .c file:
void Java_my_commander_RelayAPIModel_FreeRelayJava( JNIEnv * env, jobject this ) {
RelayAPI_DataValid = 0;
RelayAPI_SetBaud = 0;
RelayAPI_get = 0;
RelayAPI_put = 0;
RelayAPI_flush = 0;
RelayAPI_delay = 0;
RelayAPI_initilized = 0;
}
BYTE Java_my_commander_RelayAPIModel_InitRelayJava( JNIEnv *env, jobject obj ) {
...
...
}
Here they are in the .h file :
void Java_my_commander_RelayAPIModel_FreeRelayJava( JNIEnv * env, jobject obj );
BYTE Java_my_commander_RelayAPIModel_InitRelayJava( JNIEnv *env, jobject obj );
Here is my LogCat:
08-01 09:58:21.933: E/AndroidRuntime(17170): FATAL EXCEPTION: main
08-01 09:58:21.933: E/AndroidRuntime(17170): java.lang.UnsatisfiedLinkError: InitRelayJava
08-01 09:58:21.933: E/AndroidRuntime(17170): at my.eti.commander.RelayAPIModel$NativeCalls.InitRelayJava(Native Method)
08-01 09:58:21.933: E/AndroidRuntime(17170): at my.eti.commander.MainMenu.initMain(MainMenu.java:241)
08-01 09:58:21.933: E/AndroidRuntime(17170): at my.eti.commander.MainMenu.onCreate(MainMenu.java:81)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.os.Looper.loop(Looper.java:130)
08-01 09:58:21.933: E/AndroidRuntime(17170): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 09:58:21.933: E/AndroidRuntime(17170): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 09:58:21.933: E/AndroidRuntime(17170): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 09:58:21.933: E/AndroidRuntime(17170): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 09:58:21.933: E/AndroidRuntime(17170): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 09:58:21.933: E/AndroidRuntime(17170): at dalvik.system.NativeStart.main(Native Method)
I would like to clarify now, that I have tried changing the C method names to Java_my_commander_RelayAPIModel_NativeCalls_FreeRelayJava and Java_my_commander_RelayAPIModel_NativeCalls_InitRelayJava. The application still failed to launch and this was the LogCat for that:
08-01 11:22:10.735: E/AndroidRuntime(17441): FATAL EXCEPTION: main
08-01 11:22:10.735: E/AndroidRuntime(17441): java.lang.UnsatisfiedLinkError: InitRelayJava
08-01 11:22:10.735: E/AndroidRuntime(17441): at my.eti.commander.RelayAPIModel$NativeCalls.InitRelayJava(Native Method)
08-01 11:22:10.735: E/AndroidRuntime(17441): at my.eti.commander.MainMenu.initMain(MainMenu.java:241)
08-01 11:22:10.735: E/AndroidRuntime(17441): at my.eti.commander.MainMenu.onCreate(MainMenu.java:81)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.os.Looper.loop(Looper.java:130)
08-01 11:22:10.735: E/AndroidRuntime(17441): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 11:22:10.735: E/AndroidRuntime(17441): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 11:22:10.735: E/AndroidRuntime(17441): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 11:22:10.735: E/AndroidRuntime(17441): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 11:22:10.735: E/AndroidRuntime(17441): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 11:22:10.735: E/AndroidRuntime(17441): at dalvik.system.NativeStart.main(Native Method)
Now, I think that the error lies in the code above. If you all think there is nothing wrong with it, I'm going to add some more information down here just in case the problem lies elsewhere.
This application that I'm creating, uses the functions above to call a library that has been being used for a while. This library was previously used to call functions in a Palm Pilot program which utilize the Palm's bluetooth capabilities. Since Android devices have different bluetooth libraries/capabilities, I am adding code to the native library to call BACK to the java code, to access the Android device's bluetooth capabilities. I do not want to post all of the code pertaining to this here, but if someone feels that it needs to be posted I will.
The error message says it's at:
my.eti.commander.RelayAPIModel$NativeCalls.InitRelayJava (Native Method)
So make sure that:
the native method declaration is indeed inside the RelayAPIModel class, not insude the RelayAPIModel.NativeCalls nested class.
the package name on Java side is my.commander as opposed to my.eti.commander
EDIT: or you can fix that on the C side. If you want to create native methods in the nested class, the proper name for it would be:
Java_my_commander_RelayAPIModel_00024NativeCalls_InitRelayJava()
The 00024 is the code of the $ character, which is the nested class delimiter in Java internals. Also, the meaning of the of second parameter (jobject Obj) will be different - instead of this pointer/class pointer for RelayAPIModel, it will be the one for the RelayAPIModel.NativeCalls. You won't be able to use it to resolve/call methods in the RelayAPIModel.
You can use javah to generate a .h file with the correctly named native files:
javah -jni -classpath bin/classes com.example.app.MyClass

ClassNotFound when trying to implement AdMob banner

I am getting a very annoying ClassNotFound exception when trying to implement an admob banner in my android app, using admob sdk 4.3.1. I have used the following implementation:
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10"
/>
....
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/bigmainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#color/grey">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="xxxx"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR"
ads:loadAdOnCreate="true"/>
</LinearLayout>
Project.properties
target=android-14
Error:
03-21 22:00:25.993: E/AndroidRuntime(333): FATAL EXCEPTION: main 03-21
22:00:25.993: E/AndroidRuntime(333): java.lang.RuntimeException:
Unable to start activity
ComponentInfo{com.xxxx/com.xxxx.MainActivity}:
android.view.InflateException: Binary XML file line #125: Error
inflating class com.google.ads.AdView 03-21 22:00:25.993:
E/AndroidRuntime(333): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-21 22:00:25.993: E/AndroidRuntime(333): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-21 22:00:25.993: E/AndroidRuntime(333): at
android.app.ActivityThread.access$1500(ActivityThread.java:117) 03-21
22:00:25.993: E/AndroidRuntime(333): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-21 22:00:25.993: E/AndroidRuntime(333): at
android.os.Handler.dispatchMessage(Handler.java:99) 03-21
22:00:25.993: E/AndroidRuntime(333): at
android.os.Looper.loop(Looper.java:123) 03-21 22:00:25.993:
E/AndroidRuntime(333): at
android.app.ActivityThread.main(ActivityThread.java:3683) 03-21
22:00:25.993: E/AndroidRuntime(333): at
java.lang.reflect.Method.invokeNative(Native Method) 03-21
22:00:25.993: E/AndroidRuntime(333): at
java.lang.reflect.Method.invoke(Method.java:507) 03-21 22:00:25.993:
E/AndroidRuntime(333): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-21 22:00:25.993: E/AndroidRuntime(333): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 03-21
22:00:25.993: E/AndroidRuntime(333): at
dalvik.system.NativeStart.main(Native Method) 03-21 22:00:25.993:
E/AndroidRuntime(333): Caused by: android.view.InflateException:
Binary XML file line #125: Error inflating class com.google.ads.AdView
03-21 22:00:25.993: E/AndroidRuntime(333): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
03-21 22:00:25.993: E/AndroidRuntime(333): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 03-21
22:00:25.993: E/AndroidRuntime(333): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:626) 03-21
22:00:25.993: E/AndroidRuntime(333): at
android.view.LayoutInflater.inflate(LayoutInflater.java:408) 03-21
22:00:25.993: E/AndroidRuntime(333): at
android.view.LayoutInflater.inflate(LayoutInflater.java:320) 03-21
22:00:25.993: E/AndroidRuntime(333): at
android.view.LayoutInflater.inflate(LayoutInflater.java:276) 03-21
22:00:25.993: E/AndroidRuntime(333): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
03-21 22:00:25.993: E/AndroidRuntime(333): at
android.app.Activity.setContentView(Activity.java:1657) 03-21
22:00:25.993: E/AndroidRuntime(333): at
com.xxxx.MainActivity.onCreate(FreeMedsActivity.java:55) 03-21
22:00:25.993: E/AndroidRuntime(333): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-21 22:00:25.993: E/AndroidRuntime(333): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-21 22:00:25.993: E/AndroidRuntime(333): ... 11 more 03-21
22:00:25.993: E/AndroidRuntime(333): Caused by:
java.lang.ClassNotFoundException: com.google.ads.AdView in loader
dalvik.system.PathClassLoader[/data/app/com.xxxx-2.apk] 03-21
22:00:25.993: E/AndroidRuntime(333): at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
03-21 22:00:25.993: E/AndroidRuntime(333): at
java.lang.ClassLoader.loadClass(ClassLoader.java:551) 03-21
22:00:25.993: E/AndroidRuntime(333): at
java.lang.ClassLoader.loadClass(ClassLoader.java:511) 03-21
22:00:25.993: E/AndroidRuntime(333): at
android.view.LayoutInflater.createView(LayoutInflater.java:471) 03-21
22:00:25.993: E/AndroidRuntime(333): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570
)
I get a similar classnotfound exception when creating the adview in code and adding it to the layout. I get this error on OS 2.2, 2.3.3, 2.3.7, and 4.0. I have added the admobsdk.jar to the build path. I have tried switching the minSSdkVersion to 14. I am using eclipse indigo.
I am wondering if this has to do with how I am adding the .jar. I have it copied into a /lib folder in the project, and then either do add to build path or preferences-->build path-->add JAR. I am wondering if somehow the app doesn't know where to find the .jar still...
Turns out r17 of Android Tools requires the /lib folder to be /libs, and the SDK has to be placed in there and referenced internally in order for it to be included in the apk.
Check out this link for more information.
I have same problem
I was fix it in Eclipse by
Project -> Clean
Project -> propertise -> Java build path -> Order and Export (Check googleAdmod jar)
Hope this help!

How to add AdView from AdMob to a ListView

I'm confused at how to make adview from admob work with a listview. I'm new to ads and have just finished the basic tutorial but now trying to put in in my own app. I have some things commented out that I tried to do to begin with.
// Create the adView
AdView adView = new AdView(this, AdSize.BANNER, myID);
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="#+id/mainLayout"
// LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
// Add the adView to it
lv.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
<TextView android:id="#+id/itemName" android:layout_width="wrap_content"
android:layout_height="50dip" android:text="Test view"
android:textSize = "25sp"
android:singleLine = "true"/>
04-01 19:28:58.163: ERROR/AndroidRuntime(421): FATAL EXCEPTION: main
04-01 19:28:58.163: ERROR/AndroidRuntime(421):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{org.demo.textaway2/org.demo.textaway2.TextAway2}:
java.lang.UnsupportedOperationException: addView(View) is not
supported in AdapterView 04-01 19:28:58.163:
ERROR/AndroidRuntime(421): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-01 19:28:58.163: ERROR/AndroidRuntime(421): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-01 19:28:58.163: ERROR/AndroidRuntime(421): at
android.app.ActivityThread.access$2300(ActivityThread.java:125) 04-01
19:28:58.163: ERROR/AndroidRuntime(421): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-01 19:28:58.163: ERROR/AndroidRuntime(421): at
android.os.Handler.dispatchMessage(Handler.java:99) 04-01
19:28:58.163: ERROR/AndroidRuntime(421): at
android.os.Looper.loop(Looper.java:123) 04-01 19:28:58.163:
ERROR/AndroidRuntime(421): at
android.app.ActivityThread.main(ActivityThread.java:4627) 04-01
19:28:58.163: ERROR/AndroidRuntime(421): at
java.lang.reflect.Method.invokeNative(Native Method) 04-01
19:28:58.163: ERROR/AndroidRuntime(421): at
java.lang.reflect.Method.invoke(Method.java:521) 04-01 19:28:58.163:
ERROR/AndroidRuntime(421): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-01 19:28:58.163: ERROR/AndroidRuntime(421): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 04-01
19:28:58.163: ERROR/AndroidRuntime(421): at
dalvik.system.NativeStart.main(Native Method) 04-01 19:28:58.163:
ERROR/AndroidRuntime(421): Caused by:
java.lang.UnsupportedOperationException: addView(View) is not
supported in AdapterView 04-01 19:28:58.163:
ERROR/AndroidRuntime(421): at
android.widget.AdapterView.addView(AdapterView.java:435) 04-01
19:28:58.163: ERROR/AndroidRuntime(421): at
org.demo.textaway2.TextAway2.onCreate(TextAway2.java:164) 04-01
19:28:58.163: ERROR/AndroidRuntime(421): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-01 19:28:58.163: ERROR/AndroidRuntime(421): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-01 19:28:58.163: ERROR/AndroidRuntime(421): ... 11 more
The stack trace includes this:
addView(View) is not supported in AdapterView
Which answers your question - you can't use AdMob in an AdapterView or its subclasses, which you're trying to do. You'll either need to write your own View class to render the list objects, use a different ad service (adwhirl etc - perhaps another doesn't have this limitation) or move the ad(s) outside the list, into a footer/header.

Categories

Resources