android null pointer exception [closed] - android

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I write a simple programm, but there is problem.
Here is the code:
package player.org;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
public class Player extends Activity {
/** Called when the activity is first created. */
private MediaPlayer media;
private ProgressBar progress;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
progress=(ProgressBar) findViewById(R.id.progress);
progress.setVisibility(ProgressBar.INVISIBLE);
And here is the tabs.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#FFFFFF">
<ProgressBar
android:id="#+id/progress"
android:layout_width="250dp"
android:layout_height="8dp"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_x="35dp"
android:layout_y="320dp"/>
</AbsoluteLayout>
But when I run program, it's force closed because of Null pointer exception. Can anyone help?
Here is the LogCat:
08-07 08:24:02.516: ERROR/AndroidRuntime(334): FATAL EXCEPTION: main
08-07 08:24:02.516: ERROR/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{player.org/player.org.Player}: java.lang.NullPointerException
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.os.Looper.loop(Looper.java:123)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at java.lang.reflect.Method.invoke(Method.java:507)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at dalvik.system.NativeStart.main(Native Method)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): Caused by: java.lang.NullPointerException
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at player.org.Player.onCreate(Player.java:26)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): ... 11 more
08-07 08:24:02.536: WARN/ActivityManager(67): Force finishing activity player.org/.Player
08-07 08:24:03.056: WARN/ActivityManager(67): Activity pause timeout for HistoryRecord{4054b008 player.org/.Player}
08-07 08:24:03.167: INFO/ActivityManager(67): Displayed com.android.launcher/com.android.launcher2.Launcher: +37s552ms
08-07 08:24:13.233: WARN/ActivityManager(67): Activity destroy timeout for HistoryRecord{4054b008 player.org/.Player}

Related

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

"onClick" in AutocompleteTextView causes an error

I have an autocompletetextview. I want a method to run "onClick". Here is my XML:
<AutoCompleteTextView
android:id="#+id/GivenByBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="setupMiranda"
android:gravity="left"
/>
When this is run, I get errors. It doesn't matter what onClick is set to, it will always cause an error. If I remove the android:onclick line everything works fine, but that is not what I want.
Here is an excerpt from logCat:
08-07 13:56:36.040: E/AndroidRuntime(32735): FATAL EXCEPTION: main
08-07 13:56:36.040: E/AndroidRuntime(32735): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.itsmr.dre_android_clean/com.itsmr.dre_android_clean.MainActivity}: android.view.InflateException: Binary XML file line #46: Error inflating class <unknown>
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.app.ActivityThread.access$700(ActivityThread.java:140)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.os.Looper.loop(Looper.java:137)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.app.ActivityThread.main(ActivityThread.java:4921)
08-07 13:56:36.040: E/AndroidRuntime(32735): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 13:56:36.040: E/AndroidRuntime(32735): at java.lang.reflect.Method.invoke(Method.java:511)
08-07 13:56:36.040: E/AndroidRuntime(32735): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
08-07 13:56:36.040: E/AndroidRuntime(32735): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
08-07 13:56:36.040: E/AndroidRuntime(32735): at dalvik.system.NativeStart.main(Native Method)
08-07 13:56:36.040: E/AndroidRuntime(32735): Caused by: android.view.InflateException: Binary XML file line #46: Error inflating class <unknown>
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
08-07 13:56:36.040: E/AndroidRuntime(32735): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-07 13:56:36.040: E/AndroidRuntime(32735): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.app.Activity.setContentView(Activity.java:1924)
08-07 13:56:36.040: E/AndroidRuntime(32735): at com.itsmr.dre_android_clean.MainActivity.onCreate(MainActivity.java:81)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.app.Activity.performCreate(Activity.java:5188)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
08-07 13:56:36.040: E/AndroidRuntime(32735): ... 11 more
08-07 13:56:36.040: E/AndroidRuntime(32735): Caused by: java.lang.reflect.InvocationTargetException
08-07 13:56:36.040: E/AndroidRuntime(32735): at java.lang.reflect.Constructor.constructNative(Native Method)
08-07 13:56:36.040: E/AndroidRuntime(32735): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
08-07 13:56:36.040: E/AndroidRuntime(32735): ... 26 more
08-07 13:56:36.040: E/AndroidRuntime(32735): Caused by: java.lang.NullPointerException
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.widget.AutoCompleteTextView$PassThroughClickListener.access$302(AutoCompleteTextView.java:1226)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.widget.AutoCompleteTextView.setOnClickListener(AutoCompleteTextView.java:200)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.view.View.<init>(View.java:3678)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.widget.TextView.<init>(TextView.java:574)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.widget.EditText.<init>(EditText.java:76)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.widget.AutoCompleteTextView.<init>(AutoCompleteTextView.java:137)
08-07 13:56:36.040: E/AndroidRuntime(32735): at android.widget.AutoCompleteTextView.<init>(AutoCompleteTextView.java:133)
08-07 13:56:36.040: E/AndroidRuntime(32735): ... 29 more
I get this error no matter what function is set onClick. Even a function with an empty body causes this error.
What is causing this error?

Exception "inflating class fragment"

Getting run time exception as "inflating class fragment" when I tried to add Google map in my android application. I go through all the previous comments similar to which I have posted. But I couldn't solve it.
Log file is attached here
08-07 05:30:41.587: E/AndroidRuntime(2574): FATAL EXCEPTION: main
08-07 05:30:41.587: E/AndroidRuntime(2574): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newapp/com.example.newapp.NewApp}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.os.Looper.loop(Looper.java:137)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-07 05:30:41.587: E/AndroidRuntime(2574): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 05:30:41.587: E/AndroidRuntime(2574): at java.lang.reflect.Method.invoke(Method.java:525)
08-07 05:30:41.587: E/AndroidRuntime(2574): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-07 05:30:41.587: E/AndroidRuntime(2574): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-07 05:30:41.587: E/AndroidRuntime(2574): at dalvik.system.NativeStart.main(Native Method)
08-07 05:30:41.587: E/AndroidRuntime(2574): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-07 05:30:41.587: E/AndroidRuntime(2574): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.Activity.setContentView(Activity.java:1895)
08-07 05:30:41.587: E/AndroidRuntime(2574): at com.example.newapp.NewApp.onCreate(NewApp.java:12)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.Activity.performCreate(Activity.java:5133)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-07 05:30:41.587: E/AndroidRuntime(2574): ... 11 more
08-07 05:30:41.587: E/AndroidRuntime(2574): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-07 05:30:41.587: E/AndroidRuntime(2574): ... 21 more
08-07 05:30:41.587: E/AndroidRuntime(2574): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: DexPathList[[zip file "/data/app/com.example.newapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.newapp-1, /vendor/lib, /system/lib]]
08-07 05:30:41.587: E/AndroidRuntime(2574): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
08-07 05:30:41.587: E/AndroidRuntime(2574): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-07 05:30:41.587: E/AndroidRuntime(2574): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
08-07 05:30:41.587: E/AndroidRuntime(2574): ... 24 more
08-07 05:30:47.677: I/Process(2574): Sending signal. PID: 2574 SIG: 9
08-07 05:30:53.767: D/AndroidRuntime(2650): Shutting down VM
08-07 05:30:53.767: W/dalvikvm(2650): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-07 05:30:53.857: E/AndroidRuntime(2650): FATAL EXCEPTION: main
08-07 05:30:53.857: E/AndroidRuntime(2650): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newapp/com.example.newapp.NewApp}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.os.Looper.loop(Looper.java:137)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-07 05:30:53.857: E/AndroidRuntime(2650): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 05:30:53.857: E/AndroidRuntime(2650): at java.lang.reflect.Method.invoke(Method.java:525)
08-07 05:30:53.857: E/AndroidRuntime(2650): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-07 05:30:53.857: E/AndroidRuntime(2650): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-07 05:30:53.857: E/AndroidRuntime(2650): at dalvik.system.NativeStart.main(Native Method)
08-07 05:30:53.857: E/AndroidRuntime(2650): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-07 05:30:53.857: E/AndroidRuntime(2650): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.Activity.setContentView(Activity.java:1895)
08-07 05:30:53.857: E/AndroidRuntime(2650): at com.example.newapp.NewApp.onCreate(NewApp.java:12)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.Activity.performCreate(Activity.java:5133)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-07 05:30:53.857: E/AndroidRuntime(2650): ... 11 more
08-07 05:30:53.857: E/AndroidRuntime(2650): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-07 05:30:53.857: E/AndroidRuntime(2650): ... 21 more
08-07 05:30:53.857: E/AndroidRuntime(2650): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: DexPathList[[zip file "/data/app/com.example.newapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.newapp-1, /vendor/lib, /system/lib]]
08-07 05:30:53.857: E/AndroidRuntime(2650): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
08-07 05:30:53.857: E/AndroidRuntime(2650): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-07 05:30:53.857: E/AndroidRuntime(2650): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
08-07 05:30:53.857: E/AndroidRuntime(2650): ... 24 more
08-07 05:30:56.837: I/Process(2650): Sending signal. PID: 2650 SIG: 9
manifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="********************************" />
<permission
android:name="com.venky.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.newapp.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.newapp.NewApp"
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>
and the java file NewApp.java
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class NewApp extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_app);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.new_app, menu);
return true;
}
}
activity_new_app.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".NewApp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Please help me to solve this problem.
One visible mistake
https://developers.google.com/maps/documentation/android/start
Your meta tag must be a child of application tag in manifest
<meta-data // should be inside application tag.
android:name="com.google.android.maps.v2.API_KEY"
android:value="********************************" />
Change this
<permission
android:name="com.venky.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
to
<permission
android:name="com.example.newapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

Open Web Browser from App - Always Crashes

I'm trying to open a web browser from my app using:
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse("http://developer.android.com/"));
startActivity(browser);
But the app just crashes:
08-07 17:18:29.912: E/AndroidRuntime(751): FATAL EXCEPTION: main
08-07 17:18:29.912: E/AndroidRuntime(751): java.lang.NullPointerException
08-07 17:18:29.912: E/AndroidRuntime(751): at android.app.Activity.startActivityForResult(Activity.java:3131)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.app.Activity.startActivity(Activity.java:3237)
08-07 17:18:29.912: E/AndroidRuntime(751): at com.Co.DrumKit$9.onClick(DrumKit.java:658)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.view.View.performClick(View.java:3110)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.view.View$PerformClick.run(View.java:11934)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.os.Handler.handleCallback(Handler.java:587)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.os.Handler.dispatchMessage(Handler.java:92)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.os.Looper.loop(Looper.java:132)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.app.ActivityThread.main(ActivityThread.java:4123)
08-07 17:18:29.912: E/AndroidRuntime(751): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 17:18:29.912: E/AndroidRuntime(751): at java.lang.reflect.Method.invoke(Method.java:491)
08-07 17:18:29.912: E/AndroidRuntime(751): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-07 17:18:29.912: E/AndroidRuntime(751): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-07 17:18:29.912: E/AndroidRuntime(751): at dalvik.system.NativeStart.main(Native Method)

imageview fadeineffect not working

I've been practicing some animation on Android but I could not get my code to work. the application fails at launch. Here is my main class + fade in class,
can you help me find out the problem?
package send.Shift;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
public class ShiftsActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView Arrow = (ImageView) findViewById(R.drawable.arrow);
Animation fadeInAnimation = AnimationUtils.loadAnimation(this,
R.anim.fade_in);
// Now Set your animation
Arrow.startAnimation(fadeInAnimation);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="500" />
logcat:
12-16 03:40:23.863: D/AndroidRuntime(707): Shutting down VM
12-16 03:40:23.863: W/dalvikvm(707): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-16 03:40:23.873: E/AndroidRuntime(707): FATAL EXCEPTION: main
12-16 03:40:23.873: E/AndroidRuntime(707): java.lang.RuntimeException: Unable to start activity ComponentInfo{send.Shift/send.Shift.ShiftsActivity}: java.lang.NullPointerException
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.os.Handler.dispatchMessage(Handler.java:99)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.os.Looper.loop(Looper.java:123)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-16 03:40:23.873: E/AndroidRuntime(707): at java.lang.reflect.Method.invokeNative(Native Method)
12-16 03:40:23.873: E/AndroidRuntime(707): at java.lang.reflect.Method.invoke(Method.java:507)
12-16 03:40:23.873: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-16 03:40:23.873: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-16 03:40:23.873: E/AndroidRuntime(707): at dalvik.system.NativeStart.main(Native Method)
12-16 03:40:23.873: E/AndroidRuntime(707): Caused by: java.lang.NullPointerException
12-16 03:40:23.873: E/AndroidRuntime(707): at send.Shift.ShiftsActivity.onCreate(ShiftsActivity.java:21)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-16 03:40:23.873: E/AndroidRuntime(707): ... 11 more
R.drawable.arrow cannot be an id of an imageview. That's a drawable, as in some picture you saved (png, or jpg) in your drawable folder. What you need is something like R.id.my_image_view
Try like this,
ImageView imageView= (ImageView)findViewById(R.id.imageView);
Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.your_fade_in_anim);
//Now Set your animation
imageView.startAnimation(fadeInAnimation );

Categories

Resources