Sorry!! the application XXXX has stopped unexpectedly..Please try again - android

I am a beginner in android developmnt.I followed a series of tutorials and made a piece of code.Whenever I run the app in the emulator it shows "Sorry! the application XXXX has stopped unexpectedly..Please try again." Please help me solve this error.
Here is the code I used...
package newapp.com;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
int counter;
Button add,sub;
TextView display;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter=0;
add= (Button) findViewById(R.id.badd);
sub= (Button) findViewById(R.id.bsub);
display= (TextView) findViewById(R.id.tdisplay);
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
}
});
}}
This is xml code i used....
<LinearLayout 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:orientation="vertical"
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.com.MainActivity$PlaceholderFragment" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="The sum is"
android:textSize="45dp"
android:gravity="center"
android:id="#+id/tdisplay"
/>
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="add"
android:id="#+id/badd"
/>
<Button
android:id="#+id/bsub"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="subtract" />
</LinearLayout>
And here is the manifest....
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="newapp.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="newapp.com.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 logcat...and how logcat is useful to resolve this issue.
05-07 13:22:31.058: I/dalvikvm(609): Could not find method
android.content.pm.PackageManager.getActivityLogo, referenced from method
android.support.v7.internal.widget.ActionBarView.<init>
05-07 13:22:31.058: W/dalvikvm(609): VFY: unable to resolve virtual method 318:
Landroid/content/pm/PackageManager;.getActivityLogo
(Landroid/content/ComponentName;)Landroid/graphics/drawable/Drawable;
05-07 13:22:31.058: D/dalvikvm(609): VFY: replacing opcode 0x6e at 0x008b
05-07 13:22:31.058: I/dalvikvm(609): Could not find method
android.content.pm.ApplicationInfo.loadLogo, referenced from method
android.support.v7.internal.widget.ActionBarView.<init>
05-07 13:22:31.068: W/dalvikvm(609): VFY: unable to resolve virtual method 314:
Landroid/content/pm/ApplicationInfo;.loadLogo
(Landroid/content/pm/PackageManager;)Landroid/graphics/drawable/Drawable;
05-07 13:22:31.088: D/dalvikvm(609): VFY: replacing opcode 0x6e at 0x0099
05-07 13:22:31.108: D/dalvikvm(609): VFY: dead code 0x008e-0092 in
Landroid/support/v7/internal/widget/ActionBarView;.<init>
(Landroid/content/Context;Landroid/util/AttributeSet;)V
05-07 13:22:31.108: D/dalvikvm(609): VFY: dead code 0x009c-00a0 in
Landroid/support/v7/internal/widget/ActionBarView;.<init>
(Landroid/content/Context;Landroid/util/AttributeSet;)V
05-07 13:22:31.458: D/AndroidRuntime(609): Shutting down VM
05-07 13:22:31.458: W/dalvikvm(609): threadid=1: thread exiting with uncaught exception
(group=0x4001d800)
05-07 13:22:31.478: E/AndroidRuntime(609): FATAL EXCEPTION: main
05-07 13:22:31.478: E/AndroidRuntime(609): java.lang.RuntimeException: Unable to start
activity ComponentInfo{newapp.com/newapp.com.MainActivity}:
java.lang.NullPointerException
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.os.Handler.dispatchMessage(Handler.java:99)
05-07 13:22:31.478: E/AndroidRuntime(609): at android.os.Looper.loop(Looper.java:123)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread.main(ActivityThread.java:4627)
05-07 13:22:31.478: E/AndroidRuntime(609): at
java.lang.reflect.Method.invokeNative(Native Method)
05-07 13:22:31.478: E/AndroidRuntime(609): at
java.lang.reflect.Method.invoke(Method.java:521)
05-07 13:22:31.478: E/AndroidRuntime(609): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-07 13:22:31.478: E/AndroidRuntime(609): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-07 13:22:31.478: E/AndroidRuntime(609): at dalvik.system.NativeStart.main(Native
Method)
05-07 13:22:31.478: E/AndroidRuntime(609): Caused by: java.lang.NullPointerException
05-07 13:22:31.478: E/AndroidRuntime(609): at
newapp.com.MainActivity.onCreate(MainActivity.java:32)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-07 13:22:31.478: E/AndroidRuntime(609): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-07 13:22:31.478: E/AndroidRuntime(609): ... 11 more
05-07 13:22:41.409: I/Process(609): Sending signal. PID: 609 SIG: 9

Apply theme in activity in manifest file
android:theme="#style/Theme.AppCompat.Light"
And in styles.xml
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

The layout you posted that contains the Buttons and TextView you use is not R.layout.activity_main.
Make sure R.layout.activity_main is the layout that contains R.id.badd, R.id.bsub and R.id.tdisplay

Related

targetSdkVersion setting

If someone could help me with this. I downloaded AndroidSDK and everything else needed for android programming, and I faced some problems with (funny to say) hello world.
I just do not get the thing with tarketSdkVersion setting in AppManifest. Whenever it is not set to "13" (just noticed 8 which is my minSdkVersion is working also) application has "Unfortunately application stopped working" screen with this in LogCat:
07-01 01:26:47.820: E/AndroidRuntime(902): FATAL EXCEPTION: main
07-01 01:26:47.820: E/AndroidRuntime(902): Process: pl.bbZoftware.eclipsestandalone, PID: 902
07-01 01:26:47.820: E/AndroidRuntime(902): java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.bbZoftware.eclipsestandalone/pl.bbZoftware.eclipsestandalone.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.os.Handler.dispatchMessage(Handler.java:102)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.os.Looper.loop(Looper.java:136)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread.main(ActivityThread.java:5026)
07-01 01:26:47.820: E/AndroidRuntime(902): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 01:26:47.820: E/AndroidRuntime(902): at java.lang.reflect.Method.invoke(Method.java:515)
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-01 01:26:47.820: E/AndroidRuntime(902): at dalvik.system.NativeStart.main(Native Method)
07-01 01:26:47.820: E/AndroidRuntime(902): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.Activity.setContentView(Activity.java:1930)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
07-01 01:26:47.820: E/AndroidRuntime(902): at pl.bbZoftware.eclipsestandalone.MainActivity.onCreate(MainActivity.java:14)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.Activity.performCreate(Activity.java:5242)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
07-01 01:26:47.820: E/AndroidRuntime(902): ... 11 more
07-01 01:26:55.340: I/Process(902): Sending signal. PID: 902 SIG: 9
I do not get if this is intentional, I got some SDK errors or something else.
I was googling for answers but coulnt find any. Tell me if I should add some more info from project, looking for your answers.
EDIT: Forgot to add, I got an android device with 4.4.2 KitKat so I wanted to make project target set to 20. That is how I noticed this errors.
EDIT2:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
activity_main.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="pl.bbZoftware.eclipsestandalone.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world" />
</RelativeLayout>
EDIT3:
manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pl.bbZoftware.eclipsestandalone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="13" />
<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>
I just found where the problem was.
Do not use API Level of 20 and Platform 4.4W, as Android Virtual Device.
With Level 19 and Platform 4.2.2 set on ADV everything runs as it should.
Just remove android:targetSdkVersion from AndroidManifest.xml
Make following changes:
From
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
To:
<uses-sdk android:minSdkVersion="8" />
Most probably you are making mistake on activity_main.xml
Also target for 4.4.2 Kitkat is 19. Have a check in this android api levels page.
ChangetargetSdkVersion in [project directory]\app\build.gradle to something less than or equal to 19. Change:
defaultConfig {
applicationId '....'
minSdkVersion 8
targetSdkVersion 21
}
To:
defaultConfig {
applicationId '....'
targetSdkVersion 19
}
Android API 20 gives compilation issues. Make sure to be using the API 19 and set it as a Targeted SDK during development.

Problems with iText trying to create a PDF file

I'm trying to create a PDF file when I press a button. I'm using iText library.
My activity:
package com.pdf;
import java.io.FileOutputStream;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class PDFActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void GenerarPDF(View view)throws Exception{
Document document=new Document();
PdfWriter.getInstance(document,new FileOutputStream("generando.pdf"));
document.open();
document.add(new Paragraph("Testing testing and testing"));
document.close();
}
}
My xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="#555">
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:onClick="GenerarPDF"
android:text="Button" />
</RelativeLayout>
My manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pdf"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.READ_FRAME_BUFFER"/>
<uses-permission android:name="android.permission.BIND_INPUT_METHOD"/>
<uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".PDFActivity"
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>
And the log cat:
05-31 12:08:58.778: E/AndroidRuntime(662): FATAL EXCEPTION: main
05-31 12:08:58.778: E/AndroidRuntime(662): java.lang.IllegalStateException: Could not execute method of the activity
05-31 12:08:58.778: E/AndroidRuntime(662): at android.view.View$1.onClick(View.java:3044)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.view.View.performClick(View.java:3511)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.view.View$PerformClick.run(View.java:14105)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.os.Handler.handleCallback(Handler.java:605)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.os.Handler.dispatchMessage(Handler.java:92)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.os.Looper.loop(Looper.java:137)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-31 12:08:58.778: E/AndroidRuntime(662): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 12:08:58.778: E/AndroidRuntime(662): at java.lang.reflect.Method.invoke(Method.java:511)
05-31 12:08:58.778: E/AndroidRuntime(662): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-31 12:08:58.778: E/AndroidRuntime(662): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-31 12:08:58.778: E/AndroidRuntime(662): at dalvik.system.NativeStart.main(Native Method)
05-31 12:08:58.778: E/AndroidRuntime(662): Caused by: java.lang.reflect.InvocationTargetException
05-31 12:08:58.778: E/AndroidRuntime(662): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 12:08:58.778: E/AndroidRuntime(662): at java.lang.reflect.Method.invoke(Method.java:511)
05-31 12:08:58.778: E/AndroidRuntime(662): at android.view.View$1.onClick(View.java:3039)
05-31 12:08:58.778: E/AndroidRuntime(662): ... 11 more
05-31 12:08:58.778: E/AndroidRuntime(662): Caused by: java.lang.NoClassDefFoundError: com.itextpdf.text.Document
05-31 12:08:58.778: E/AndroidRuntime(662): at com.pdf.PDFActivity.GenerarPDF(PDFActivity.java:22)
05-31 12:08:58.778: E/AndroidRuntime(662): ... 14 more
Added logcat error:
05-31 15:26:00.411: E/dalvikvm(792): Could not find class 'com.itextpdf.text.Document', referenced from method com.pdf.PDFActivity.GenerarPDF
I think thats the real problem, but don't know the solution.
Where exactly are you trying to create the pdf file? I used the itextpdf-5.2.1.jar and was able to successfully create the pdf in the sd card. I added the following lines of codes to your program:
public void GenerarPDF(View view)throws Exception{
Document document=new Document();
File root = new File(Environment.getExternalStorageDirectory(), "Notes");
if (!root.exists()) {
root.mkdirs();
}
File gpxfile = new File(root, "generando.pdf");
PdfWriter.getInstance(document,new FileOutputStream(gpxfile));
document.open();
document.add(new Paragraph("Testing testing and testing"));
document.close();
}
Hope this answer helps.
EDIT:
The error you mentioned in your comment (06-01 23:32:37.178: E/AndroidRuntime(535): Caused by: java.io.FileNotFoundException: /generando.pdf: open failed: EROFS (Read-only file system)
) is exactly what I get when I run the code you provided. The reason being that you are not specifying the location where the new file can be created/stored. Use the GenerarPDF(View view) in have pasted over here and the program will create the new pdf.
Another cause for this error might be that you don't have an sd card in your device.
change file root to this line
File root = new File(android.os.Environment.getExternalStorageDirectory(), "Notes");
looks like you forgot to call generatePDF() from onCreate()...
hope it helps!

Error java.lang.ClassNotFoundException in my Activity using Google API in Android

I made a test a program for my University which uses Google maps following a tutorial. I made everything like in tutorial, but my app crashes before even showing anything with message "Unfortunately SocialFoot has stopped". I tried to debug and it seems like it crashes even before entering to onCreate method. This is my code:
package it.univpm.dii.socialfoot;
import com.actionbarsherlock.app.SherlockMapActivity;
import android.os.Bundle;
public class SocialFootActivity extends SherlockMapActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Logcat:
05-18 19:29:59.343: E/AndroidRuntime(3405): FATAL EXCEPTION: main
05-18 19:29:59.343: E/AndroidRuntime(3405): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{it.univpm.dii.socialfoot/it.univpm.dii.socialfoot.activities.SocialFootActivity}: java.lang.ClassNotFoundException: it.univpm.dii.socialfoot.activities.SocialFootActivity
05-18 19:29:59.343: E/AndroidRuntime(3405): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
05-18 19:29:59.343: E/AndroidRuntime(3405): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-18 19:29:59.343: E/AndroidRuntime(3405): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-18 19:29:59.343: E/AndroidRuntime(3405): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-18 19:29:59.343: E/AndroidRuntime(3405): at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 19:29:59.343: E/AndroidRuntime(3405): at android.os.Looper.loop(Looper.java:137)
05-18 19:29:59.343: E/AndroidRuntime(3405): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-18 19:29:59.343: E/AndroidRuntime(3405): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 19:29:59.343: E/AndroidRuntime(3405): at java.lang.reflect.Method.invoke(Method.java:511)
05-18 19:29:59.343: E/AndroidRuntime(3405): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-18 19:29:59.343: E/AndroidRuntime(3405): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-18 19:29:59.343: E/AndroidRuntime(3405): at dalvik.system.NativeStart.main(Native Method)
05-18 19:29:59.343: E/AndroidRuntime(3405): Caused by: java.lang.ClassNotFoundException: it.univpm.dii.socialfoot.activities.SocialFootActivity
05-18 19:29:59.343: E/AndroidRuntime(3405): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-18 19:29:59.343: E/AndroidRuntime(3405): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-18 19:29:59.343: E/AndroidRuntime(3405): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-18 19:29:59.343: E/AndroidRuntime(3405): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-18 19:29:59.343: E/AndroidRuntime(3405): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
05-18 19:29:59.343: E/AndroidRuntime(3405): ... 11 more
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.univpm.dii.socialfoot"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".SocialFootActivity"
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>
Layout:
The logs indicate the app is trying to launch it.univpm.dii.socialfoot.activities.SocialFootActivity, but SocialFootActivity is in package it.univpm.dii.socialfoot. If this is happening at the start of your application (since that activity is set as the launch activity), I would try cleaning and rebuilding your project and trying again.

ComponentInfo{packgname.LoginActivity}: java.lang.ClassNotFoundException

Whenever I run my android application I get an exception:
05-07 12:03:55.356: E/AndroidRuntime(589): FATAL EXCEPTION: main
05-07 12:03:55.356: E/AndroidRuntime(589): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{packgname/de.fau.fsahoy.android.api15.Activities.LoginActivity}: java.lang.ClassNotFoundException: de.fau.fsahoy.android.api15.Activities.LoginActivity
05-07 12:03:55.356: E/AndroidRuntime(589): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
05-07 12:03:55.356: E/AndroidRuntime(589): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-07 12:03:55.356: E/AndroidRuntime(589): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-07 12:03:55.356: E/AndroidRuntime(589): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-07 12:03:55.356: E/AndroidRuntime(589): at android.os.Handler.dispatchMessage(Handler.java:99)
05-07 12:03:55.356: E/AndroidRuntime(589): at android.os.Looper.loop(Looper.java:137)
05-07 12:03:55.356: E/AndroidRuntime(589): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-07 12:03:55.356: E/AndroidRuntime(589): at java.lang.reflect.Method.invokeNative(Native Method)
05-07 12:03:55.356: E/AndroidRuntime(589): at java.lang.reflect.Method.invoke(Method.java:511)
05-07 12:03:55.356: E/AndroidRuntime(589): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-07 12:03:55.356: E/AndroidRuntime(589): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-07 12:03:55.356: E/AndroidRuntime(589): at dalvik.system.NativeStart.main(Native Method)
05-07 12:03:55.356: E/AndroidRuntime(589): Caused by: java.lang.ClassNotFoundException: packgname.Activities.LoginActivity
05-07 12:03:55.356: E/AndroidRuntime(589): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-07 12:03:55.356: E/AndroidRuntime(589): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-07 12:03:55.356: E/AndroidRuntime(589): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-07 12:03:55.356: E/AndroidRuntime(589): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-07 12:03:55.356: E/AndroidRuntime(589): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
05-07 12:03:55.356: E/AndroidRuntime(589): ... 11 more
However, in my AndroidManifest.xml there imho nothing wrong:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.fau.fsahoy.android.api15"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="15"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="#drawable/fsa_launcher"
android:label="#string/AppName">
<activity
android:name=".Activities.LoginActivity"
android:label="#string/AppName">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activities.MainMenuActivity"></activity>
<activity android:name=".Activities.ProfileActivity"></activity>
</application>
</manifest>
I'm going crazy about that issue and trying to resolve it for the last 3 hours or so :<
Currently I am rebuilding the app by copy and pasting the code over to another clean project. I hope that works. Anyway, I see that many people have that issue. What is it?
I solved the problem by creating a new Android Project and manually copy and pasted the code from the old project.
Magically then - it worked :)
Might not be the best solution - especially for large projects with a huge codebase. Yet, it worked for me :)
I had a similar "poltergeist" in my code. I don't understand the reason but it seems to be related with my activity extending FragmentActivity and having a method with the following signature: public boolean isResumed().
I renamed the method and it worked.

My Android App Keeps Crashing

I've started to learn Android Development and I got this snippit off of google android development site, it keeps on crashing.
My specs are:
Android 4.0.3
API 15
Code:
package lewes.android.hello;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
I get...
Unfortenualy, HelloAndroid is not responding.
Please help me!
MY MANIFEST:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lewes.android.hello"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".HelloWorld"
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:
03-17 11:35:19.835: D/AndroidRuntime(562): Shutting down VM
03-17 11:35:19.835: W/dalvikvm(562): threadid=1: thread exiting with uncaught
exception (group=0x409c01f8)
03-17 11:35:19.914: E/AndroidRuntime(562): FATAL EXCEPTION: main
03-17 11:35:19.914: E/AndroidRuntime(562): java.lang.RuntimeException: Unable to
instantiate activity
ComponentInfo{lewes.android.hello/lewes.android.hello.HelloWorld}:
java.lang.ClassNotFoundException: lewes.android.hello.HelloWorld
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread.access$600(ActivityThread.java:123)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.os.Handler.dispatchMessage(Handler.java:99)
03-17 11:35:19.914: E/AndroidRuntime(562): at android.os.Looper.loop(Looper.java:137)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread.main(ActivityThread.java:4424)
03-17 11:35:19.914: E/AndroidRuntime(562): at
java.lang.reflect.Method.invokeNative(Native Method)
03-17 11:35:19.914: E/AndroidRuntime(562): at
java.lang.reflect.Method.invoke(Method.java:511)
03-17 11:35:19.914: E/AndroidRuntime(562): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-17 11:35:19.914: E/AndroidRuntime(562): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-17 11:35:19.914: E/AndroidRuntime(562): at dalvik.system.NativeStart.main(Native
Method)
03-17 11:35:19.914: E/AndroidRuntime(562): Caused by:
java.lang.ClassNotFoundException: lewes.android.hello.HelloWorld
03-17 11:35:19.914: E/AndroidRuntime(562): at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-17 11:35:19.914: E/AndroidRuntime(562): at
java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-17 11:35:19.914: E/AndroidRuntime(562): at
java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.Instrumentation.newActivity(Instrumentation.java:1023)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
03-17 11:35:19.914: E/AndroidRuntime(562): ... 11 more
03-17 11:40:20.114: I/Process(562): Sending signal. PID: 562 SIG: 9
Delete one of the application sections from your manifest.
Keep the one where the activity corresponds to the name of your class.
make your manifest look exactly like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lewes.android.hello"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".HelloAndroid"
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>
Change
<activity
android:name=".HelloAndroidActivity"
to
<activity
android:name=".HelloAndroid"
SDK does not mention about this. But as my experience, activity (this) can not be used inside onCreate(Bundle) to initialize new objects. To be used as a parameter for constructors, this is nothing within onCreate().
You can follow this hello world. It uses static xml layout.
Hope this helps you :-)

Categories

Resources