[q] App force closes after adding admod SDK - Mobile Ad Networks

Guys,I am trying to integrate admob SDK in my app from the past 3 hours and have no luck.
I have added the jar libraries ( build path), included in build paths, everything is good there.
main activity :
Code:
// Create the adView
adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout"
RelativeLayout layout = (RelativeLayout)findViewById(R.id.ad);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
layout
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="a15XZXXXXX3"
ads:loadAdOnCreate="true" />
everything loaded on the manifest file as well!
LOGCAT :
Code:
07-09 15:33:20.362: D/dalvikvm(12621): GC_CONCURRENT freed 188K, 3% free 8916K/9132K, paused 5ms+8ms, total 46ms
07-09 15:33:20.362: E/AndroidRuntime(12621): FATAL EXCEPTION: main
07-09 15:33:20.362: E/AndroidRuntime(12621): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.PACKAGE/com.PACKAGE.MainActivity}: java.lang.NullPointerException
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.os.Looper.loop(Looper.java:137)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-09 15:33:20.362: E/AndroidRuntime(12621): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 15:33:20.362: E/AndroidRuntime(12621): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 15:33:20.362: E/AndroidRuntime(12621): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-09 15:33:20.362: E/AndroidRuntime(12621): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-09 15:33:20.362: E/AndroidRuntime(12621): at dalvik.system.NativeStart.main(Native Method)
07-09 15:33:20.362: E/AndroidRuntime(12621): Caused by: java.lang.NullPointerException
07-09 15:33:20.362: E/AndroidRuntime(12621): at com.PACKAGE.MainActivity.onCreate(MainActivity.java:42)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.Activity.performCreate(Activity.java:5104)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-09 15:33:20.362: E/AndroidRuntime(12621): ... 11 more
07-09 15:33:22.877: I/Process(12621): Sending signal. PID: 12621 SIG: 9

chintz24 said:
Guys,I am trying to integrate admob SDK in my app from the past 3 hours and have no luck.
07-09 15:33:20.362: E/AndroidRuntime(12621): Caused by: java.lang.NullPointerException
07-09 15:33:20.362: E/AndroidRuntime(12621): at com.PACKAGE.MainActivity.onCreate(MainActivity.java:42)
Click to expand...
Click to collapse
says there, line 42, your asking "NULL" to do something! No idea what is on line 42, but would assume it's your ad view, so maybe your loading the wrong layout ? or even attempting to findViewById before setContentView() ? Would need more info/code

deanwray said:
says there, line 42, your asking "NULL" to do something! No idea what is on line 42, but would assume it's your ad view, so maybe your loading the wrong layout ? or even attempting to findViewById before setContentView() ? Would need more info/code
Click to expand...
Click to collapse
or even attempting to findViewById before setContentView()
This is what I was doing.
Thanks a lot.
Also does it take time to load ads?
because I dont see anything. Not even blank "ads by google"

chintz24 said:
or even attempting to findViewById before setContentView()
This is what I was doing.
Thanks a lot.
Also does it take time to load ads?
because I dont see anything. Not even blank "ads by google"
Click to expand...
Click to collapse
No idea, not used ads yet

Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="aXXXXXXXXXXX"
ads:loadAdOnCreate="true" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:minHeight="1dip" />
</RelativeLayout>
This is my layout.xml

Thanks, its sorted, I didnt have any container for my ads. Done now

chintz24 said:
Guys,I am trying to integrate admob SDK in my app from the past 3 hours and have no luck.
I have added the jar libraries ( build path), included in build paths, everything is good there.
main activity :
Code:
// Create the adView
adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout"
RelativeLayout layout = (RelativeLayout)findViewById(R.id.ad);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
layout
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="a15XZXXXXX3"
ads:loadAdOnCreate="true" />
everything loaded on the manifest file as well!
LOGCAT :
Code:
07-09 15:33:20.362: D/dalvikvm(12621): GC_CONCURRENT freed 188K, 3% free 8916K/9132K, paused 5ms+8ms, total 46ms
07-09 15:33:20.362: E/AndroidRuntime(12621): FATAL EXCEPTION: main
07-09 15:33:20.362: E/AndroidRuntime(12621): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.PACKAGE/com.PACKAGE.MainActivity}: java.lang.NullPointerException
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.os.Looper.loop(Looper.java:137)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-09 15:33:20.362: E/AndroidRuntime(12621): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 15:33:20.362: E/AndroidRuntime(12621): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 15:33:20.362: E/AndroidRuntime(12621): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-09 15:33:20.362: E/AndroidRuntime(12621): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-09 15:33:20.362: E/AndroidRuntime(12621): at dalvik.system.NativeStart.main(Native Method)
07-09 15:33:20.362: E/AndroidRuntime(12621): Caused by: java.lang.NullPointerException
07-09 15:33:20.362: E/AndroidRuntime(12621): at com.PACKAGE.MainActivity.onCreate(MainActivity.java:42)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.Activity.performCreate(Activity.java:5104)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-09 15:33:20.362: E/AndroidRuntime(12621): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-09 15:33:20.362: E/AndroidRuntime(12621): ... 11 more
07-09 15:33:22.877: I/Process(12621): Sending signal. PID: 12621 SIG: 9
Click to expand...
Click to collapse
Hi,
You are mixing the two solutions for integration of admob banners (XML and code). The coding solution assumes that you have a layout that you want to populate with ads (useful when using different ad networks). In your case you define the admob banner in the XML so you don't need to call it at all in the code, If you think to set a listener (to do something when admob failed to show ads) in this case you can call and set your ad listener (that you implement on the activity) this way:
AdView adView = (AdView)findViewById(R.id.ad);
adView.setAdListener (this);
adView.loadAd(new AdRequest());
Hope this will help

Related

App is crashing!

Hey, i was working through intent, when I encountered this error. My app seems to crash, when any of the button is clicked..
Please help me out.. I am providing all the codes..
manifest:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.intent"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.intent.MainActivity"
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>
main_activity.xml:
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10sp" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="onClickWebBrowser"
android:onClick="onClickWebBrowser" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_alignParentBottom="true"
android:text="oClickMakeCalls"
android:onClick="onClickMakeCalls"/>
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button1"
android:layout_centerVertical="true"
android:text="onClickShowMap"
android:onClick="onClickShowMap" />
</RelativeLayout>
MainActivity.java:
Code:
package com.example.intent;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
int request_code = 1;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClickWebBrowser(View v) {
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("www.crazyandroidgalaxy.blogspot.in"));
startActivity(i);
}
public void onClickMakeCalls(View v) {
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("01123235616"));
startActivity(i);
}
public void onClickShowMap(View v) {
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("“geo:37.827500,-122.481670”"));
startActivity(i);
}
}
logcat:
Code:
07-11 12:46:55.290: D/AndroidRuntime(284): Shutting down VM
07-11 12:46:55.290: W/dalvikvm(284): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-11 12:46:55.569: E/AndroidRuntime(284): FATAL EXCEPTION: main
07-11 12:46:55.569: E/AndroidRuntime(284): java.lang.IllegalStateException: Could not execute method of the activity
07-11 12:46:55.569: E/AndroidRuntime(284): at android.view.View$1.onClick(View.java:2072)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.view.View.performClick(View.java:2408)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.view.View$PerformClick.run(View.java:8816)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.os.Handler.handleCallback(Handler.java:587)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.os.Handler.dispatchMessage(Handler.java:92)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.os.Looper.loop(Looper.java:123)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-11 12:46:55.569: E/AndroidRuntime(284): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 12:46:55.569: E/AndroidRuntime(284): at java.lang.reflect.Method.invoke(Method.java:521)
07-11 12:46:55.569: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-11 12:46:55.569: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-11 12:46:55.569: E/AndroidRuntime(284): at dalvik.system.NativeStart.main(Native Method)
07-11 12:46:55.569: E/AndroidRuntime(284): Caused by: java.lang.reflect.InvocationTargetException
07-11 12:46:55.569: E/AndroidRuntime(284): at com.example.intent.MainActivity.onClickWebBrowser(MainActivity.java:24)
07-11 12:46:55.569: E/AndroidRuntime(284): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 12:46:55.569: E/AndroidRuntime(284): at java.lang.reflect.Method.invoke(Method.java:521)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.view.View$1.onClick(View.java:2067)
07-11 12:46:55.569: E/AndroidRuntime(284): ... 11 more
07-11 12:46:55.569: E/AndroidRuntime(284): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=www.crazyandroidgalaxy.blogspot.in }
07-11 12:46:55.569: E/AndroidRuntime(284): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.app.Activity.startActivityForResult(Activity.java:2817)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.app.Activity.startActivity(Activity.java:2923)
07-11 12:46:55.569: E/AndroidRuntime(284): ... 15 more
07-11 12:46:55.569: E/AndroidRuntime(284): FATAL EXCEPTION: main
07-11 12:46:55.569: E/AndroidRuntime(284): java.lang.IllegalStateException: Could not execute method of the activity
07-11 12:46:55.569: E/AndroidRuntime(284): at android.view.View$1.onClick(View.java:2072)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.view.View.performClick(View.java:2408)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.view.View$PerformClick.run(View.java:8816)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.os.Handler.handleCallback(Handler.java:587)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.os.Handler.dispatchMessage(Handler.java:92)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.os.Looper.loop(Looper.java:123)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-11 12:46:55.569: E/AndroidRuntime(284): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 12:46:55.569: E/AndroidRuntime(284): at java.lang.reflect.Method.invoke(Method.java:521)
07-11 12:46:55.569: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-11 12:46:55.569: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-11 12:46:55.569: E/AndroidRuntime(284): at dalvik.system.NativeStart.main(Native Method)
07-11 12:46:55.569: E/AndroidRuntime(284): Caused by: java.lang.reflect.InvocationTargetException
07-11 12:46:55.569: E/AndroidRuntime(284): at com.example.intent.MainActivity.onClickWebBrowser(MainActivity.java:24)
07-11 12:46:55.569: E/AndroidRuntime(284): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 12:46:55.569: E/AndroidRuntime(284): at java.lang.reflect.Method.invoke(Method.java:521)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.view.View$1.onClick(View.java:2067)
07-11 12:46:55.569: E/AndroidRuntime(284): ... 11 more
07-11 12:46:55.569: E/AndroidRuntime(284): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=www.crazyandroidgalaxy.blogspot.in }
07-11 12:46:55.569: E/AndroidRuntime(284): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.app.Activity.startActivityForResult(Activity.java:2817)
07-11 12:46:55.569: E/AndroidRuntime(284): at android.app.Activity.startActivity(Activity.java:2923)
07-11 12:46:55.569: E/AndroidRuntime(284): ... 15 more
07-11 12:46:57.890: I/Process(284): Sending signal. PID: 284 SIG: 9
Please help me out! Thanks in advance..
Aren't there prefixes for the Uris?
Try "tel:<your number>" for example for the dial intent. (If that does not work, search for the right prefix.)
Its strange, i got this code from a book (begining android application development.)
How can it be faulty..
I dont find any prefix for the uriS
edit:
Actually, there is a prefix for the dialing intent.
But not, for the browser intent.
So, my app is still cashing
edit: actually, it.worked. But the map is still crashing
Sent from my GT-S6102 using xda app-developers app

Null Pointer Exception

Hello there,
I am trying to learn android application development through one of the online tutorials .I am stuck at a point and since,both java and android are new for me I can't figure out how to get out of it.Here's the code to my Startingpoint.java:
Code:
public class Startingpoint extends Activity {
int counter;
Button add,sub;
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
counter=0;
add=(Button)findViewById(R.id.bAdd);
sub=(Button)findViewById(R.id.bSub);
display=(TextView)findViewById(R.id.display);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
counter--;
display.setText("Your total is" + counter);
}
});
}
}
The following are the contents within the LineaLlayout in my main.xml file:
Code:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/result"
android:textSize="25sp"
android:layout_gravity="fill_horizontal"
android:gravity="center"
android:id="@+id/display"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="@string/bAdd"
android:layout_gravity="center"
android:gravity="center"
android:id="@+id/bAdd"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="@string/bSub"
android:layout_gravity="center"
android:gravity="center"
android:id="@+id/bSub"
/>
And this is what the logcat has to say :
Code:
02-13 11:44:12.076: D/AndroidRuntime(2026): Shutting down VM
02-13 11:44:12.076: W/dalvikvm(2026): threadid=1: thread exiting with uncaught exception (group=0xb2d5bb08)
02-13 11:44:12.156: E/AndroidRuntime(2026): FATAL EXCEPTION: main
02-13 11:44:12.156: E/AndroidRuntime(2026): Process: com.thenewboston.rohit, PID: 2026
02-13 11:44:12.156: E/AndroidRuntime(2026): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thenewboston.rohit/com.thenewboston.rohit.Startingpoint}: java.lang.NullPointerException
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread.access$700(ActivityThread.java:135)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.os.Handler.dispatchMessage(Handler.java:102)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.os.Looper.loop(Looper.java:137)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread.main(ActivityThread.java:4998)
02-13 11:44:12.156: E/AndroidRuntime(2026): at java.lang.reflect.Method.invokeNative(Native Method)
02-13 11:44:12.156: E/AndroidRuntime(2026): at java.lang.reflect.Method.invoke(Method.java:515)
02-13 11:44:12.156: E/AndroidRuntime(2026): atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
02-13 11:44:12.156: E/AndroidRuntime(2026): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
02-13 11:44:12.156: E/AndroidRuntime(2026): at dalvik.system.NativeStart.main(Native Method)
02-13 11:44:12.156: E/AndroidRuntime(2026): Caused by: java.lang.NullPointerException
02-13 11:44:12.156: E/AndroidRuntime(2026): at com.thenewboston.rohit.Startingpoint.onCreate(Startingpoint.java:21)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.Activity.performCreate(Activity.java:5243)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
02-13 11:44:12.156: E/AndroidRuntime(2026): ... 11 more
Being inexperienced in java , I could not figure out what's wrong with the code.May be the exception is due to my add,sub and display being null but I am not sure.Please help me figure out what's wrong with my code and how to deal with it.
Any help is greatly appreciated.
Well, you can find the line where it crashes in the logcat:
Code:
02-13 11:44:12.156: E/AndroidRuntime(2026): Caused by: java.lang.NullPointerException
02-13 11:44:12.156: E/AndroidRuntime(2026): at com.thenewboston.rohit.Startingpoint.onCreate([B]Startingpoint.java:21[/B])
It's line 21. Which one is that?
Have a look at my debugging tutorial here as well, mainly the part on understanding the logcat. It will probably be very helpful and save much time: http://forum.xda-developers.com/showthread.php?t=2325164
nikwen said:
Well, you can find the line where it crashes in the logcat:
Code:
02-13 11:44:12.156: E/AndroidRuntime(2026): Caused by: java.lang.NullPointerException
02-13 11:44:12.156: E/AndroidRuntime(2026): at com.thenewboston.rohit.Startingpoint.onCreate([B]Startingpoint.java:21[/B])
It's line 21. Which one is that?
Have a look at my debugging tutorial here as well, mainly the part on understanding the logcat. It will probably be very helpful and save much time: http://forum.xda-developers.com/showthread.php?t=2325164
Click to expand...
Click to collapse
I bet they must be the findViewById(int id);
as much i trust my counting skills line 21 is calling for one the views
i still remeber the first NPE when i started android
Sent from my GT-S5302 using Tapatalk 2
I am sorry , I should have mentioned it.
Line 21 -> add.setOnClickListener(new View.OnClickListener()
DarkMethod said:
I am sorry , I should have mentioned it.
Line 21 -> add.setOnClickListener(new View.OnClickListener()
Click to expand...
Click to collapse
It means the.view with id bAdd was not found make sure have declared it in your layout
Sent from my GT-S5302 using Tapatalk 2
I have declared the ids for each view as you can see in the layout.xml attached.This NPE is turning out to be quite frustrating now.
DarkMethod said:
I have declared the ids for each view as you can see in the layout.xml attached.This NPE is turning out to be quite frustrating now.
Click to expand...
Click to collapse
do one thing
add a breakpoint to each line
then debug your app if on Eclipse or Android Studio !
and watch the control flow through each line this should narrow you down to the root cause.
Sent from my GT-S5302 using Tapatalk 2
sak-venom1997 said:
do one thing
add a breakpoint to each line
then debug your app if on Eclipse or Android Studio !
and watch the control flow through each line this should narrow you down to the root cause.
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
More on that here as well: http://forum.xda-developers.com/showthread.php?t=2325164
nikwen said:
More on that here as well: http://forum.xda-developers.com/showthread.php?t=2325164
Click to expand...
Click to collapse
indeed a great one :thumbup:
Sent from my GT-S5302 using Tapatalk 2
sak-venom1997 said:
indeed a great one :thumbup:
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
Thanks.

[Q] Web View

Hi, im not sure if im in the right place with this. Im experienced in Java but extremely new to this hole App thing.
Im trying to like have a browser inside of my app, Display web pages. Im getting this error as far as I know This should work.
Code:
public class MainActivity extends Activity {
private static final String URL_TO_LOAD = "Link";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wv = (WebView) findViewById(R.id.main_content);
loadResource(wv, URL_TO_LOAD);
}
private void loadResource(WebView wv, String resource) {
wv.loadUrl(resource);
wv.getSettings().setJavaScriptEnabled(true);
}
}
With this error:
Code:
02-25 19:23:46.404: E/AndroidRuntime(31416): FATAL EXCEPTION: main
02-25 19:23:46.404: E/AndroidRuntime(31416): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mepo/com.example.mepo.MainActivity}: java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to android.webkit.WebView
02-25 19:23:46.404: E/AndroidRuntime(31416): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
02-25 19:23:46.404: E/AndroidRuntime(31416): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
02-25 19:23:46.404: E/AndroidRuntime(31416): at android.app.ActivityThread.access$600(ActivityThread.java:140)
02-25 19:23:46.404: E/AndroidRuntime(31416): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
02-25 19:23:46.404: E/AndroidRuntime(31416): at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 19:23:46.404: E/AndroidRuntime(31416): at android.os.Looper.loop(Looper.java:137)
02-25 19:23:46.404: E/AndroidRuntime(31416): at android.app.ActivityThread.main(ActivityThread.java:4895)
02-25 19:23:46.404: E/AndroidRuntime(31416): at java.lang.reflect.Method.invokeNative(Native Method)
02-25 19:23:46.404: E/AndroidRuntime(31416): at java.lang.reflect.Method.invoke(Method.java:511)
02-25 19:23:46.404: E/AndroidRuntime(31416): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
02-25 19:23:46.404: E/AndroidRuntime(31416): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
02-25 19:23:46.404: E/AndroidRuntime(31416): at dalvik.system.NativeStart.main(Native Method)
02-25 19:23:46.404: E/AndroidRuntime(31416): Caused by: java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to android.webkit.WebView
02-25 19:23:46.404: E/AndroidRuntime(31416): at com.example.mepo.MainActivity.onCreate(MainActivity.java:20)
02-25 19:23:46.404: E/AndroidRuntime(31416): at android.app.Activity.performCreate(Activity.java:5163)
02-25 19:23:46.404: E/AndroidRuntime(31416): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
02-25 19:23:46.404: E/AndroidRuntime(31416): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
02-25 19:23:46.404: E/AndroidRuntime(31416): ... 11 more
Please let me Know if this is in the wrong place.
You are using id of framelayout in webview.
Show your layout xml also
Sent from my GT-S5570 using XDA Premium 4 mobile app
Sure!
arpitkh96 said:
You are using id of framelayout in webview.
Show your layout xml also
Sent from my GT-S5570 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
Am i not spouse to be?
XML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="LINK WAS HERE"
android:id="@+id/fullscreen_custom_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF000000">
<FrameLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
Check the xml.main_content id that you used to identify webview is for framelayout.
You have to replace main_content with webView in your java code.
Moreover your first framelayout never ends
Sent from my GT-S5570 using XDA Premium 4 mobile app

Android: Unfortunately the "app name" stopped! My first app

I've just started to build my first android app and this 1st time errors are bugging me now since 2 days. Finding no solution I had to come here. I have been following Androids official tutorial for my first app and can't open my app.
Error: "Unfortunately "app name" has stopped"
Here is my manisfest file,
Code:
<manifest xmlns:android=" [B]removed due to new member at the forum warning! 10 posts minimum need to post link:([/B]
package="app2.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Log Cat
03-10 08:59:54.310: D/dalvikvm(1671): Not late-enabling CheckJNI (already on)
03-10 08:59:54.400: D/AndroidRuntime(1671): Shutting down VM
03-10 08:59:54.400: W/dalvikvm(1671): threadid=1: thread exiting with uncaught exception (group=0xb2d88b20)
03-10 08:59:54.400: E/AndroidRuntime(1671): FATAL EXCEPTION: main
03-10 08:59:54.400: E/AndroidRuntime(1671): Process: app2.android, PID: 1671
03-10 08:59:54.400: E/AndroidRuntime(1671): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{app2.android/app2.android.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "app2.android.MainActivity" on path: DexPathList[[zip file "/data/app/app2.android-1.apk"],nativeLibraryDirectories=[/data/app-lib/app2.android-1, /vendor/lib, /system/lib]]
03-10 08:59:54.400: E/AndroidRuntime(1671): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
03-10 08:59:54.400: E/AndroidRuntime(1671): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-10 08:59:54.400: E/AndroidRuntime(1671): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-10 08:59:54.400: E/AndroidRuntime(1671): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-10 08:59:54.400: E/AndroidRuntime(1671): at android.os.Handler.dispatchMessage(Handler.java:102)
03-10 08:59:54.400: E/AndroidRuntime(1671): at android.os.Looper.loop(Looper.java:136)
03-10 08:59:54.400: E/AndroidRuntime(1671): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-10 08:59:54.400: E/AndroidRuntime(1671): at java.lang.reflect.Method.invokeNative(Native Method)
03-10 08:59:54.400: E/AndroidRuntime(1671): at java.lang.reflect.Method.invoke(Method.java:515)
03-10 08:59:54.400: E/AndroidRuntime(1671): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-10 08:59:54.400: E/AndroidRuntime(1671): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-10 08:59:54.400: E/AndroidRuntime(1671): at dalvik.system.NativeStart.main(Native Method)
03-10 08:59:54.400: E/AndroidRuntime(1671): Caused by: java.lang.ClassNotFoundException: Didn't find class "app2.android.MainActivity" on path: DexPathList[[zip file "/data/app/app2.android-1.apk"],nativeLibraryDirectories=[/data/app-lib/app2.android-1, /vendor/lib, /system/lib]]
03-10 08:59:54.400: E/AndroidRuntime(1671): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-10 08:59:54.400: E/AndroidRuntime(1671): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
03-10 08:59:54.400: E/AndroidRuntime(1671): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
03-10 08:59:54.400: E/AndroidRuntime(1671): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
03-10 08:59:54.400: E/AndroidRuntime(1671): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
03-10 08:59:54.400: E/AndroidRuntime(1671): ... 11 more
I have been rolling all over the internet for solutions, tried so many, doesn't work!!! PLEASE HELP!
Activity name change to
.MainActivity in manifest
Sent from my GT-S7392 using XDA Premium 4 mobile app
arpitkh96 said:
Activity name change to
.MainActivity in manifest
Sent from my GT-S7392 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
i did. Same error!:crying:
Try writing the full package name to instead of just "MainActivity"
<activity android:name="app2.android.MainActivity" >
In the manifest change your activity name to <activity android:name="app2.android.MainActivity" > and also make sure that your project src folder has correct package inside (named app2.android)

How to store geofence in disk

Hey guys,
I'm having a problem figuring out a way to store the geofences that my app creates, in order to load them when I run the app again. The purpose is to show a list of geofences created by the user.
I tried to serialize them using Java's Serialization and I also tried to use Gson to convert them into a Json string. The problem with Gson it's when I try to load them, it gives me an error message saying that Geofence is not a class. (which is true, it's an interface).
logcat:
Code:
09-09 21:37:16.148 18137-18137/? D/dalvikvm﹕ Late-enabling CheckJNI
09-09 21:37:17.515 18137-18137/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
09-09 21:37:17.515 18137-18137/? W/dalvikvm﹕ VFY: unable to resolve virtual method 614: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
09-09 21:37:17.515 18137-18137/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
09-09 21:37:17.515 18137-18137/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
09-09 21:37:17.515 18137-18137/? W/dalvikvm﹕ VFY: unable to resolve virtual method 636: Landroid/content/res/TypedArray;.getType (I)I
09-09 21:37:17.515 18137-18137/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
09-09 21:37:18.133 18137-18137/? D/GoogleAPIMsg﹕ Construcao do Client Google
09-09 21:37:18.164 18137-18137/? D/Manager﹕ Loading Geofences...
09-09 21:37:18.203 18137-18137/? D/AndroidRuntime﹕ Shutting down VM
09-09 21:37:18.203 18137-18137/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x419307c0)
09-09 21:37:18.234 18137-18137/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartlocation.wilcocsjrxxlxpto/com.smartlocation.wilcocsjrxxlxpto.HomeScreen}: java.lang.RuntimeException: Unable to invoke no-args constructor for interface com.google.android.gms.location.Geofence. Register an InstanceCreator with Gson for this type may fix this problem.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to invoke no-args constructor for interface com.google.android.gms.location.Geofence. Register an InstanceCreator with Gson for this type may fix this problem.
at com.google.gson.internal.ConstructorConstructor$12.construct(ConstructorConstructor.java:210)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:186)
at com.google.gson.Gson.fromJson(Gson.java:810)
at com.google.gson.Gson.fromJson(Gson.java:775)
at com.google.gson.Gson.fromJson(Gson.java:724)
at com.google.gson.Gson.fromJson(Gson.java:696)
at com.smartlocation.wilcocsjrxxlxpto.core.Manager.loadGeofences(Manager.java:203)
at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.load(HomeScreen.java:252)
at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.onCreate(HomeScreen.java:66)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
************at android.app.ActivityThread.access$600(ActivityThread.java:153)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
************at android.os.Handler.dispatchMessage(Handler.java:99)
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.java:5289)
************at java.lang.reflect.Method.invokeNative(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:525)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
************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:525)
at com.google.gson.internal.UnsafeAllocator$1.newInstance(UnsafeAllocator.java:48)
at com.google.gson.internal.ConstructorConstructor$12.construct(ConstructorConstructor.java:207)
************at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:186)
************at com.google.gson.Gson.fromJson(Gson.java:810)
************at com.google.gson.Gson.fromJson(Gson.java:775)
************at com.google.gson.Gson.fromJson(Gson.java:724)
************at com.google.gson.Gson.fromJson(Gson.java:696)
************at com.smartlocation.wilcocsjrxxlxpto.core.Manager.loadGeofences(Manager.java:203)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.load(HomeScreen.java:252)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.onCreate(HomeScreen.java:66)
************at android.app.Activity.performCreate(Activity.java:5133)
************at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
************at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
************at android.app.ActivityThread.access$600(ActivityThread.java:153)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
************at android.os.Handler.dispatchMessage(Handler.java:99)
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.java:5289)
************at java.lang.reflect.Method.invokeNative(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:525)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
************at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.InstantiationException: can't instantiate class com.google.android.gms.location.Geofence; abstract class or interface
at sun.misc.Unsafe.allocateInstance(Native Method)
************at java.lang.reflect.Method.invokeNative(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:525)
************at com.google.gson.internal.UnsafeAllocator$1.newInstance(UnsafeAllocator.java:48)
************at com.google.gson.internal.ConstructorConstructor$12.construct(ConstructorConstructor.java:207)
************at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:186)
************at com.google.gson.Gson.fromJson(Gson.java:810)
************at com.google.gson.Gson.fromJson(Gson.java:775)
************at com.google.gson.Gson.fromJson(Gson.java:724)
************at com.google.gson.Gson.fromJson(Gson.java:696)
************at com.smartlocation.wilcocsjrxxlxpto.core.Manager.loadGeofences(Manager.java:203)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.load(HomeScreen.java:252)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.onCreate(HomeScreen.java:66)
************at android.app.Activity.performCreate(Activity.java:5133)
************at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
************at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
************at android.app.ActivityThread.access$600(ActivityThread.java:153)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
************at android.os.Handler.dispatchMessage(Handler.java:99)
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.java:5289)
************at java.lang.reflect.Method.invokeNative(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:525)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
************at dalvik.system.NativeStart.main(Native Method)
09-09 21:37:18.648 18137-18137/? I/Process﹕ Sending signal. PID: 18137 SIG: 9
code:
Code:
public class Manager implements ResultCallback<Status>, LocationListener {
// Tag para fazer debug
protected static final String MAN = "Manager";
protected static final String SMS = "eventSMS";
protected static final String RING = "eventRing";
private Context mAppContext;
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
// Listas de Geofences
private TreeMap<String, Geofence> mGeofences;
private TreeMap<String, Event> mEvents;
private int mCounterActiveGeofences;
private PendingIntent mGeofencePendingIntent;
private Intent updateLocIntent;
/* Save */
private Gson gson;
private SharedPreferences prefs;
public Manager(Context context, GoogleApiClient googleApiClient){
mGeofences = new TreeMap<String, Geofence>();
mEvents = new TreeMap<String, Event>();
mGeofencePendingIntent = null;
mAppContext = context;
mGoogleApiClient = googleApiClient;
mCounterActiveGeofences = 0;
prefs = context.getSharedPreferences(Constants.Geofences, Context.MODE_PRIVATE);
gson = new Gson();
}
...
public void saveGeofences(){
String json;
Geofence geofence;
SharedPreferences.Editor editor = prefs.edit();
Log.d(MAN, "Saving Geofences...");
for (Map.Entry<String, Geofence> entry : mGeofences.entrySet()) {
geofence = mGeofences.get(entry.getKey());
json = gson.toJson(geofence);
editor.putString(geofence.getRequestId(), json);
Log.d(MAN, geofence.getRequestId() + " json: " + json);
}
editor.apply();
}
public void loadGeofences(){
Map<String, ?> keys = prefs.getAll();
Log.d(MAN, "Loading Geofences...");
for (Map.Entry<String, ?> entry : keys.entrySet()) {
String jsonString = prefs.getString(entry.getKey(), null);
Geofence geofence = gson.fromJson(jsonString, Geofence.class);
Log.d(MAN, geofence.getRequestId());
mGeofences.put(geofence.getRequestId(), geofence);
}
}
}
Thank you in advance.
wilcocsjr said:
Hey guys,
I'm having a problem figuring out a way to store the geofences that my app creates, in order to load them when I run the app again. The purpose is to show a list of geofences created by the user.
I tried to serialize them using Java's Serialization and I also tried to use Gson to convert them into a Json string. The problem with Gson it's when I try to load them, it gives me an error message saying that Geofence is not a class. (which is true, it's an interface).
Thank you in advance.
Click to expand...
Click to collapse
Could you show your code and show logcat read sticky thread how to post development questions
Sent from my SM-G530H using XDA Free mobile app
AndroidFire said:
Could you show your code and show logcat read sticky thread how to post development questions
Sent from my SM-G530H using XDA Free mobile app
Click to expand...
Click to collapse
Just edited the original post, sorry about that

Categories

Resources