Unfortunately, “App Name” has stopped. (Eclipse, Android) - android

I am somewhat new to Android app Programming.
I was able to create the app and be able to export it and install it to my android device, but when I try to run it it quits and displays the message "Unfortunately, My First App has stopped." This problem is also present when I try to run the app in an emulator
This is my AndroidManifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tada"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".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>
This is my mainactivity file:
package com.example.tada;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
item.getItemId();
return true;
}
}
This is my activity_main file
<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="com.example.tada.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/welcome_to_the_tada_app" />
</RelativeLayout>
Here is my LogCat
11-23 01:22:21.520: D/AndroidRuntime(1055): Shutting down VM
11-23 01:22:21.520: W/dalvikvm(1055): threadid=1: thread exiting with uncaught exception (group=0xb3afbba8)
11-23 01:22:21.560: E/AndroidRuntime(1055): FATAL EXCEPTION: main
11-23 01:22:21.560: E/AndroidRuntime(1055): Process: com.example.tada, PID: 1055
11-23 01:22:21.560: E/AndroidRuntime(1055): java.lang.Error: Unresolved compilation problem:
11-23 01:22:21.560: E/AndroidRuntime(1055): activity_main cannot be resolved or is not a field
11-23 01:22:21.560: E/AndroidRuntime(1055): at com.example.tada.MainActivity.onCreate(MainActivity.java:14)
11-23 01:22:21.560: E/AndroidRuntime(1055): at android.app.Activity.performCreate(Activity.java:5231)
11-23 01:22:21.560: E/AndroidRuntime(1055): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-23 01:22:21.560: E/AndroidRuntime(1055): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
11-23 01:22:21.560: E/AndroidRuntime(1055): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
11-23 01:22:21.560: E/AndroidRuntime(1055): at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-23 01:22:21.560: E/AndroidRuntime(1055): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-23 01:22:21.560: E/AndroidRuntime(1055): at android.os.Handler.dispatchMessage(Handler.java:102)
11-23 01:22:21.560: E/AndroidRuntime(1055): at android.os.Looper.loop(Looper.java:136)
11-23 01:22:21.560: E/AndroidRuntime(1055): at android.app.ActivityThread.main(ActivityThread.java:5017)
11-23 01:22:21.560: E/AndroidRuntime(1055): at java.lang.reflect.Method.invokeNative(Native Method)
11-23 01:22:21.560: E/AndroidRuntime(1055): at java.lang.reflect.Method.invoke(Method.java:515)
11-23 01:22:21.560: E/AndroidRuntime(1055): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-23 01:22:21.560: E/AndroidRuntime(1055): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-23 01:22:21.560: E/AndroidRuntime(1055): at dalvik.system.NativeStart.main(Native Method)
11-23 01:22:26.100: I/Process(1055): Sending signal. PID: 1055 SIG: 9

When developing for android, always have a logcat window open.
When you see the crash dialog, the logcat will reveal the root cause of the error, making it easy for you to find it and fix it.

Its the issue of corrupted R.java file.....Immediately create a new project and do the code or switch ur sdk.

Delete your R.java file and Clean your project. No need to create a new project.

Related

I can not execute my project in emulator

I am doing a simple project using google maps. My project is running fine in my mobile. But i can not run in emulator. When i try to execute the following error is showing..
11-23 12:50:44.187: E/AndroidRuntime(3128): FATAL EXCEPTION: main
11-23 12:50:44.187: E/AndroidRuntime(3128): Process: info.android.googlemapsv2, PID: 3128
11-23 12:50:44.187: E/AndroidRuntime(3128): java.lang.RuntimeException: Unable to resume activity {info.android.googlemapsv2/info.android.slidingmenu.SlideActivity}: java.lang.NullPointerException
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2788)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2817)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.os.Handler.dispatchMessage(Handler.java:102)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.os.Looper.loop(Looper.java:136)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.ActivityThread.main(ActivityThread.java:5017)
11-23 12:50:44.187: E/AndroidRuntime(3128): at java.lang.reflect.Method.invokeNative(Native Method)
11-23 12:50:44.187: E/AndroidRuntime(3128): at java.lang.reflect.Method.invoke(Method.java:515)
11-23 12:50:44.187: E/AndroidRuntime(3128): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-23 12:50:44.187: E/AndroidRuntime(3128): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-23 12:50:44.187: E/AndroidRuntime(3128): at dalvik.system.NativeStart.main(Native Method)
11-23 12:50:44.187: E/AndroidRuntime(3128): Caused by: java.lang.NullPointerException
11-23 12:50:44.187: E/AndroidRuntime(3128): at com.tracker.newmaps.MainActivityNew.GetLocaion(MainActivityNew.java:210)
11-23 12:50:44.187: E/AndroidRuntime(3128): at com.tracker.newmaps.MainActivityNew.onResume(MainActivityNew.java:300)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.Fragment.performResume(Fragment.java:1743)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:924)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1044)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:1863)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.Activity.performResume(Activity.java:5320)
11-23 12:50:44.187: E/AndroidRuntime(3128): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2778)
11-23 12:50:44.187: E/AndroidRuntime(3128): ... 12 more
I am using Google APIs x86(Google Inc.) Target api, and emulator also Google APIs x86(Google Inc.)
Please let me know how to run the project in my emulator.
Maybe in the emulator you don't have Google play services installed. This link could be helpful too.

android studio my helloWorld project has stopped

I just instilled Android Studio and when I run the sample project hello world in the emulator it gives me my project has stopped and it doesn't work
myActivity.java
package b3du.im.myapplication;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
public class MyActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
}
}
activity_my.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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MyActivity">
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="b3du.im.myapplication" >
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MyActivity"
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>
logcat error
08-01 05:13:56.557 1884-1884/b3du.im.myapplication I/Process﹕ Sending signal. PID: 1884 SIG: 9
08-01 05:21:26.244 1944-1944/b3du.im.myapplication D/AndroidRuntime﹕ Shutting down VM
08-01 05:21:26.244 1944-1944/b3du.im.myapplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb2cc9b20)
08-01 05:21:26.284 1944-1944/b3du.im.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: b3du.im.myapplication, PID: 1944
java.lang.RuntimeException: Unable to start activity ComponentInfo{b3du.im.myapplication/b3du.im.myapplication.MyActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:108)
at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at b3du.im.myapplication.MyActivity.onCreate(MyActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
This is because you are using ActionBarActivity, which requires the AppCompat theme to be applied.
Either use that theme, Or use simple Activity. See a similar issue
as Stated by MysticMagic change ActionBarActivity to Activity or change your theme to AppCompat
explore package got to res-> values->style.xml and change style
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
Your issue is with AppTheme that you have set currently in you app.
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:108)
You are inheriting you from ActionBarActivity so you have to use Theme.AppCompat for your application. Change app base theme in styles.xml to
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
If you are facing issue in loading this theme than please follow the below link to resolve compilation issue.
Can't Find Theme.AppCompat.Light for New Android ActionBar Support

Is Renderscript incompatible with NDK libraries in the same project?

I have a problem creating an Android app that makes use of both Renderscript and native code generated with NDK.
Substantially, I use NDK tools to generate a library called sprstr_native.so. I managed to call their C++ functions through Java code without problems. Then I needed some Renderscript functionalities (in particular, ScriptIntrinsicYuvToRGB) so I've added to my Eclipse project a reference to the relative support library, renderscript-v8.jar, and this line in the project properties file:
renderscript.support.mode=true
Now the problem: Android can't recognize my sprstr_native anymore and the app crashes when calling the code:
System.loadLibrary("sprstr_native");
This is the stack:
11-23 17:46:54.450: E/AndroidRuntime(3901): FATAL EXCEPTION: main
11-23 17:46:54.450: E/AndroidRuntime(3901): java.lang.ExceptionInInitializerError
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.Class.newInstanceImpl(Native Method)
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.Class.newInstance(Class.java:1409)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.os.Looper.loop(Looper.java:130)
11-23 17:46:54.450: E/AndroidRuntime(3901): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.reflect.Method.invokeNative(Native Method)
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.reflect.Method.invoke(Method.java:507)
11-23 17:46:54.450: E/AndroidRuntime(3901): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-23 17:46:54.450: E/AndroidRuntime(3901): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-23 17:46:54.450: E/AndroidRuntime(3901): at dalvik.system.NativeStart.main(Native Method)
11-23 17:46:54.450: E/AndroidRuntime(3901): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load sprstr_native: findLibrary returned null
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.Runtime.loadLibrary(Runtime.java:429)
11-23 17:46:54.450: E/AndroidRuntime(3901): at java.lang.System.loadLibrary(System.java:554)
11-23 17:46:54.450: E/AndroidRuntime(3901): at com.lag.proj.MainActivity.<clinit>(MainActivity.java:18)
11-23 17:46:54.450: E/AndroidRuntime(3901): ... 15 more
Curiously, if I delete all the references to Renderscript the native lib turns to work again!
Please don't tell me that there are incompatibilities between Renderscript and NDK code!
I've probably solved it, but not without other errors that came after (see Getting different errors for different platforms using Renderscript Support Library). By the way, the library loading phase should be solved by adding this line on the Application.mk file:
APP_ABI := all
That lets the NDK to compile the objs for all the supported architectures.

android:exception in map

I am implementing an app in which i have to use google map and code is as follows:
<com.google.android.maps.MapView
android:id="#+id/mapview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:apiKey="0ACHOtlugQlOpv7OWSc2GYfNmJfYY1ltGNlzgEQ"
android:clickable="true"
android:enabled="true" >
</com.google.android.maps.MapView>
and i got this exception:
11-23 12:50:52.796: I/System.out(24625): android.view.InflateException: Binary XML file line #68: Error inflating class com.google.android.maps.Mapview
11-23 12:28:44.445: E/AndroidRuntime(24124): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
11-23 12:28:44.445: E/AndroidRuntime(24124): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
11-23 12:28:44.445: E/AndroidRuntime(24124): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-23 12:28:44.445: E/AndroidRuntime(24124): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
11-23 12:28:44.445: E/AndroidRuntime(24124): at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 12:28:44.445: E/AndroidRuntime(24124): at android.os.Looper.loop(Looper.java:123)
11-23 12:28:44.445: E/AndroidRuntime(24124): at android.app.ActivityThread.main(ActivityThread.java:3687)
11-23 12:28:44.445: E/AndroidRuntime(24124): at java.lang.reflect.Method.invokeNative(Native Method)
11-23 12:28:44.445: E/AndroidRuntime(24124): at java.lang.reflect.Method.invoke(Method.java:507)
11-23 12:28:44.445: E/AndroidRuntime(24124): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
11-23 12:28:44.445: E/AndroidRuntime(24124): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
11-23 12:28:44.445: E/AndroidRuntime(24124): at dalvik.system.NativeStart.main(Native Method)
11-23 12:28:44.445: E/AndroidRuntime(24124): Caused by: java.lang.NullPointerException
11-23 12:28:44.445: E/AndroidRuntime(24124): at com.trigma.mcs.Outsubmap.onCreate(Outsubmap.java:23)
11-23 12:28:44.445: E/AndroidRuntime(24124): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-23 12:28:44.445: E/AndroidRuntime(24124): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
Did you specify the shared library in manifest file?
<uses-library android:name="com.google.android.maps" />
More info
This was due to mapActivity. Actully i forgot to extend mapactivity and by extending that my code worked.

RuntimeException: Error inflating class fragment

I am getting a runtimeException with the following code, does anyone know why?
public class FragsApplicationActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
SuggestionFrags class
public class SuggestionFrags extends Fragment{
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
return super.onCreateView(inflater, container, savedInstanceState);
}
}
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" >
<fragment
android:id="#+id/fragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="com.samplefragsapplication.SuggestionFrags" />
</LinearLayout>
I am getting this exception:
11-23 18:09:23.899: E/AndroidRuntime(2436): FATAL EXCEPTION: main
11-23 18:09:23.899: E/AndroidRuntime(2436): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.samplefragsapplication/com.samplefragsapplication.FragsApplicationActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.os.Looper.loop(Looper.java:123)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-23 18:09:23.899: E/AndroidRuntime(2436): at java.lang.reflect.Method.invokeNative(Native Method)
11-23 18:09:23.899: E/AndroidRuntime(2436): at java.lang.reflect.Method.invoke(Method.java:521)
11-23 18:09:23.899: E/AndroidRuntime(2436): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-23 18:09:23.899: E/AndroidRuntime(2436): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-23 18:09:23.899: E/AndroidRuntime(2436): at dalvik.system.NativeStart.main(Native Method)
11-23 18:09:23.899: E/AndroidRuntime(2436): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-23 18:09:23.899: E/AndroidRuntime(2436): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.app.Activity.setContentView(Activity.java:1647)
11-23 18:09:23.899: E/AndroidRuntime(2436): at com.samplefragsapplication.FragsApplicationActivity.onCreate(FragsApplicationActivity.java:12)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-23 18:09:23.899: E/AndroidRuntime(2436): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.samplefragsapplication-2.apk]
11-23 18:09:23.899: E/AndroidRuntime(2436): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
11-23 18:09:23.899: E/AndroidRuntime(2436): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
11-23 18:09:23.899: E/AndroidRuntime(2436): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
11-23 18:09:23.899: E/AndroidRuntime(2436): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
11-23 18:09:23.899: E/AndroidRuntime(2436): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
If you are going to use Fragments you need to extend FragmentActivity not Activity.
To fix this issue you have to extends from FragmentActivity instead of Activity in the FragsApplicationActivity.
The proper form will be
<fragment
android:id="#+id/fragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.samplefragsapplication.SuggestionFrags" />
UPD: judging by the logcat output, you don't have fragments available. If you're running a pre-Honeycomb android (but >= 1.6), you can use the compatibility library. Fragments were introduced in 3.0.
The exception android.view.InflateException: Binary XML file line: #... Error inflating class fragment might happen if you manipulate with getActivity() inside your fragment before onActivityCreated() get called. In such case you receive a wrong activity reference and can't rely on that.
For instance the next pattern is wrong:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
final View view = inflater.inflate(R.layout..., container, false);
Button button = getActivity().findViewById(R.id...);
button.setOnClickListener(...); - another problem: button is null
return view;
}
I just had the same issue, and what I found was that in my main.xml I was incorrectly referencing the fragment class.
Instead of:
<fragment android:id="#+id/frag_capt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.company.test.applicationname.fragmentname" />
try:
<fragment android:id="#+id/frag_capt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.company.test.DetailFrag" />
This fixed the issue for me.
Good luck.
Try this
<fragment
android:id="#+id/fragment1"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true" />
Make sure android:name="className" is the first parameter in the list
ex
<fragment
android:name="com.name.first"
android:id="#+id/"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
I had the same issue, to summarise:
Extend from FragmentActivity
Follow this structure in your layout
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.maps.MapFragment"
/>

Categories

Resources