How to add AdView from AdMob to a ListView - android

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.

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

Resolution specific subfolders of res directory crash the app

I have created a Phone & Tablet app for android and have the generic layout folder populated with the layouts, I then created two additional folders in the res directory with the suffix -sw600dp & -sw720dp and it is not working and the app is crashing every time no matter what I try. Can someone please give me some other options.
Log Cat Error:
04-01 02:34:23.567: E/AndroidRuntime(898): FATAL EXCEPTION: main
04-01 02:34:23.567: E/AndroidRuntime(898): java.lang.NullPointerException
04-01 02:34:23.567: E/AndroidRuntime(898): at za.co.astroweb.watsonline.wats_online_fragment$getBlogPosts.onPostExecute(wats_online_fragment.java:173)
04-01 02:34:23.567: E/AndroidRuntime(898): at za.co.astroweb.watsonline.wats_online_fragment$getBlogPosts.onPostExecute(wats_online_fragment.java:1)
04-01 02:34:23.567: E/AndroidRuntime(898): at android.os.AsyncTask.finish(AsyncTask.java:631)
04-01 02:34:23.567: E/AndroidRuntime(898): at android.os.AsyncTask.access$600(AsyncTask.java:177)
04-01 02:34:23.567: E/AndroidRuntime(898): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
04-01 02:34:23.567: E/AndroidRuntime(898): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 02:34:23.567: E/AndroidRuntime(898): at android.os.Looper.loop(Looper.java:137)
04-01 02:34:23.567: E/AndroidRuntime(898): at android.app.ActivityThread.main(ActivityThread.java:5103)
04-01 02:34:23.567: E/AndroidRuntime(898): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 02:34:23.567: E/AndroidRuntime(898): at java.lang.reflect.Method.invoke(Method.java:525)
04-01 02:34:23.567: E/AndroidRuntime(898): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
04-01 02:34:23.567: E/AndroidRuntime(898): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-01 02:34:23.567: E/AndroidRuntime(898): at dalvik.system.NativeStart.main(Native Method)

Error when taking a screenshot in 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().

Null Pointer Exception in First Android App

I am trying to write my first Android app, and I'm having trouble. I wrote a simple Java program to find the factors of a number provided by the user, and I'd like to port it over to Java. I have an XML file for the interface, which seemed to run OK until I added the first Java class. Now it won't run, and log.cat says that there's a null pointer exception. So far, I only have stubs, but it seems like it should run OK with what I've done to this point. I'm including the log.cat text, but I'm too new it this to make much sense out of it.
There may be more than one problem. After adding the Java file I began to get run-time errors right away, but I don't think they were null pointer exceptions. I think that started when I made changes to fix what was already causing problems.
Any help is appreciated.
Here is the Java file:
import android.app.Activity; <br>
import android.os.Bundle; <br>
import android.widget.Button; <br>
import android.widget.EditText; <br>
import android.widget.TextView; <br>
public class AndroidFactoringActivity extends Activity {
// Instance Variables
EditText userNumber;
Button factorButton;
TextView resultsField;
int factorResults;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
factorButton = (Button) findViewById(R.id.factorButton);
userNumber = (EditText) findViewById(R.id.userNumber);
factorResults = 1;
resultsField.setText(String.valueOf(factorResults));
}
}
Here is main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/askField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/ask"
android:textSize="24dp" />
<EditText
android:id="#+id/userNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<Button
android:id="#+id/factorButton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/click" />
<TextView
android:id="#+id/resultsField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/tell"
android:textSize="24dp" />
</LinearLayout>
Here are the log.cat results:
03-31 23:58:53.579: D/AndroidRuntime(2804): Shutting down VM
03-31 23:58:53.589: W/dalvikvm(2804): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
03-31 23:58:53.589: E/AndroidRuntime(2804): Uncaught handler: thread main exiting due to uncaught exception
03-31 23:58:53.650: E/AndroidRuntime(2804): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.dave_b.factoring/net.dave_b.factoring.AndroidFactoringActivity}: java.lang.NullPointerException
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.os.Handler.dispatchMessage(Handler.java:99)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.os.Looper.loop(Looper.java:123)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.main(ActivityThread.java:4363)
03-31 23:58:53.650: E/AndroidRuntime(2804): at java.lang.reflect.Method.invokeNative(Native Method)
03-31 23:58:53.650: E/AndroidRuntime(2804): at java.lang.reflect.Method.invoke(Method.java:521)
03-31 23:58:53.650: E/AndroidRuntime(2804): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-31 23:58:53.650: E/AndroidRuntime(2804): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-31 23:58:53.650: E/AndroidRuntime(2804): at dalvik.system.NativeStart.main(Native Method)
03-31 23:58:53.650: E/AndroidRuntime(2804): Caused by: java.lang.NullPointerException
03-31 23:58:53.650: E/AndroidRuntime(2804): at net.dave_b.factoring.AndroidFactoringActivity.onCreate(AndroidFactoringActivity.java:26)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-31 23:58:53.650: E/AndroidRuntime(2804): ... 11 more
03-31 23:58:53.679: I/dalvikvm(2804): threadid=7: reacting to signal 3
03-31 23:58:53.679: E/dalvikvm(2804): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
03-31 23:59:57.629: I/Process(2804): Sending signal. PID: 2804 SIG: 9
04-01 00:07:36.129: D/AndroidRuntime(3040): Shutting down VM
04-01 00:07:36.129: W/dalvikvm(3040): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-01 00:07:36.139: E/AndroidRuntime(3040): Uncaught handler: thread main exiting due to uncaught exception
04-01 00:07:36.159: E/AndroidRuntime(3040): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.dave_b.factoring/net.dave_b.factoring.AndroidFactoringActivity}: java.lang.NullPointerException
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.os.Looper.loop(Looper.java:123)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-01 00:07:36.159: E/AndroidRuntime(3040): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 00:07:36.159: E/AndroidRuntime(3040): at java.lang.reflect.Method.invoke(Method.java:521)
04-01 00:07:36.159: E/AndroidRuntime(3040): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-01 00:07:36.159: E/AndroidRuntime(3040): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-01 00:07:36.159: E/AndroidRuntime(3040): at dalvik.system.NativeStart.main(Native Method)
04-01 00:07:36.159: E/AndroidRuntime(3040): Caused by: java.lang.NullPointerException
04-01 00:07:36.159: E/AndroidRuntime(3040): at net.dave_b.factoring.AndroidFactoringActivity.onCreate(AndroidFactoringActivity.java:26)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-01 00:07:36.159: E/AndroidRuntime(3040): ... 11 more
04-01 00:07:36.199: I/dalvikvm(3040): threadid=7: reacting to signal 3
04-01 00:07:36.199: E/dalvikvm(3040): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
04-01 00:07:40.329: I/Process(3040): Sending signal. PID: 3040 SIG: 9
resultsField.setText(String.valueOf(factorResults));
resultsField is null and you are trying to set value on null.
resultsField= (TextView ) findViewById(R.id.userNumber);
Get textview instance before setting value, otherwise resultsField will be null and all operations on null reference results in NullPointerException.
You got a null pointer because you didnt intialise the variable resultsField (you just declared it) .
As you used
userNumber = (EditText) findViewById(R.id.userNumber);
you must even initialise the reference resultsField.
This can be done using
resultsField= (TextView ) findViewById(R.id.resultsField);
in the onCreate() after the statement setContentView()
You need to initialize the userNumer and resultsFiled as follows
userNumber = (EditText) findViewById(R.id.userNumber);
resultsField= (TextView ) findViewById(R.id.resultsField);

OPEN FEINT error in Android App

15 reports
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.oas.fruitkungfufree/com.openfeint.internal.ui.IntroFlow}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
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:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.openfeint.internal.Util.setOrientation(Util.java:36)
at com.openfeint.internal.ui.NestedWindow.onCreate(NestedWindow.java:32)
at com.openfeint.internal.ui.WebNav.onCreate(WebNav.java:93)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
Does any one have a solution for this??
This is a problem with your code, you can't use an object that is null. This is a hint.

Categories

Resources