Here's a problem that's really getting to me, whenever I try to launch my application's main activity, I get the error in LogCat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{me.kworden.atic/me.kworden.atic.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f0c00a9
The stack trace says that the problem is my super.onCreate(savedInstanceState) in my onCreate() method, which is frustrating me, because I can't control the superclass method.
The content layout I'm using is only a LinearLayout, so I don't think it is necessary for you all to see my xml file, although I will post on request.
I've seen the other similar problems on SO, but the only answers were "Clean/Rebuild the project" which hasn't done anything for me. I'm using Android Studio ver. 1.1.0 if this is a known problem, but I haven't seen any known bugs.
Here is my MainActivity, I've stripped out most of the code in order to pinpoint the problem, but now it seems that super.onCreate is the culprit; despite being extremely barebones, my app still fails to even start (i.e. I get "Unfortunately, app has stopped.").
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
// Create the activity and set the main content view //
super.onCreate(savedInstanceState); // This is line 17, per the stack trace //
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the main menu to the toolbar //
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if(id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here is my full stack trace:
03-16 23:16:33.572 1494-1494/me.kworden.atic E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: me.kworden.atic, PID: 1494
java.lang.RuntimeException: Unable to start activity ComponentInfo{me.kworden.atic/me.kworden.atic.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f0c00a9
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0c00a9
at android.content.res.Resources.getValue(Resources.java:1233)
at android.content.res.Resources.getDrawable(Resources.java:756)
at android.content.Context.getDrawable(Context.java:402)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3514)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3561)
at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1916)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:151)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at me.kworden.atic.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
If anyone stumbles on this in the future I want to make sure that you can get an answer...
The problem was that certain tags that are available only to Material and Android 5.0+ were being used in my styles. So I instead made a res/values-v21/styles.xml folder and put my appropriate settings in there. That fixed the issue.
Remove setContentView(R.layout.activity_main); method
after removing this method if it run successfully then your layout id cannot be gernerated.
and also make sure that your layout id is generated or not in R.java file
open manifest file check application package and activity. that is included or not included in file and also check style of application
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="yourapplicationpackage" >
<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>
If you using tag <view> on xml file just change tag <view> to <View>
Related
I've just built my first android app copying the code from this video: https://www.youtube.com/watch?v=gTy13ioTddg&t=594s
The app builds without problems but when I try to run it, it suddenly closes.
That's the message of the debugger:
12/02 12:19:56: Launching 'app' on Pixel_3a_API_30_x86.
Install successfully finished in 519 ms.
$ adb shell am start -n "com.example.pokedex/com.example.pokedex.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.example.pokedex | com.example.pokedex.test
Waiting for application to come online: com.example.pokedex | com.example.pokedex.test
Connecting to com.example.pokedex
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/ActivityThread: Application com.example.pokedex is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:52033', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/chatty: uid=10153(com.example.pokedex) identical 2 lines
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1475)
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/example.pokede: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/example.pokede: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pokedex, PID: 8349
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pokedex/com.example.pokedex.MainActivity}: android.view.InflateException: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Error inflating class android.support.constraint.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.view.InflateException: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: android.support.constraint.ConstraintLayout
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at android.view.LayoutInflater.createView(LayoutInflater.java:813)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.inflate(LayoutInflater.java:657)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.pokedex.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/~~ikbXqJo2xtaJUvZzC7gM8Q==/com.example.pokedex-kRHbfAkGOaaI21CGLAjxuQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~ikbXqJo2xtaJUvZzC7gM8Q==/com.example.pokedex-kRHbfAkGOaaI21CGLAjxuQ==/lib/x86, /system/lib, /system_ext/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 26 more
I/Process: Sending signal. PID: 8349 SIG: 9
Disconnected from the target VM, address: 'localhost:52033', transport: 'socket'
This is my Main Activity:
package com.example.pokedex;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
private RecyclerView.LayoutManager layoutManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView=findViewById(R.id.recycler_view);
adapter=new PokedexAdapter();
layoutManager=new LinearLayoutManager(this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(layoutManager);
}
}
Activity main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recycler_view"/>
</android.support.constraint.ConstraintLayout>
Pokedex_row:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pokedex_row">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pokedex_row_text_view"/>
</LinearLayout>
Android Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pokedex">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Pokedex">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I've been trying to solve this problem several days so I would be very thankful if someone can help me!
Have tried you changing your ConstraintLayout to use androidx instead of support
try changing the opening tag of activity_main.xml to be:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
and corresponding closing tag to be
</androidx.constraintlayout.widget.ConstraintLayout>
and then sync your project while connected to the internet.
I think it has problem with ConstraintLayout, can you share your xml files, that way I can help you batter.
I experience this error from time to time and use to solve by doing the following:
First, check if you have ConstraintLayout implementation in your app Gradle config
Then make sure there is no Error(maybe a semantic one) in your layout XML file
If the error persists, consider adding those two files to your question description so that one can easily help
Good Luck!
When I press button to open the camera, my app crashes.
LogCat:
05-18 19:33:41.644 386-2041/? E/CameraService: Permission Denial: can't use the camera pid=18519, uid=10159
05-18 19:33:41.648 18519-18519/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: involved.pose9, PID: 18519
java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.<init>(Camera.java:511)
at android.hardware.Camera.open(Camera.java:368)
at involved.pose9.CameraActivity$1.onClick(CameraActivity.java:48)
at android.view.View.performClick(View.java:5201)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Add this to your manifest:
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
Use this
To call the camera you can use:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivity(intent);
The image will be automatically saved in a default directory.
And you need to set the permission for the camera in your AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA"> </uses-permission>
Now using above approach Devices with no camera or devices only with front camera won't be able to find/install the app.
Add this to your manifest:
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
I want to read SMS using a content resolver. I've added permissions in the manifest file like this:
<uses-permission android:name="android.permission.READ_SMS"/>
Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null); //line that gives exception
cur.close();}
But it's giving an error:
02-22 02:55:36.429 18963-18963/inc.osi.imossis E/AndroidRuntime: FATAL EXCEPTION: main
Process: inc.osi.imossis, PID: 18963
java.lang.RuntimeException: Unable to start activity ComponentInfo{inc.osi.imossis/inc.osi.imossis.MainActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.SmsProvider uri content://sms/inbox from pid=18963, uid=10059 requires android.permission.READ_SMS, or grantUriPermission()
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.SmsProvider uri content://sms/inbox from pid=18963, uid=10059 requires android.permission.READ_SMS, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1599)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
at android.content.ContentResolver.query(ContentResolver.java:491)
at android.content.ContentResolver.query(ContentResolver.java:434)
at inc.osi.imossis.MainActivity.onCreate(MainActivity.java:30)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
The complete manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="inc.osi.imossis">
<uses-permission android:name="android.permission.READ_SMS"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
How do I solve it?
Have you tried cleaning and re-building the project?
edit: Can you try checking and requesting the permission at run-time?
final private int REQUEST_READ_SMS_ID = 1; // A constant needed for callback
int hasReadSMSPermission = checkSelfPermission(Manifest.permission.READ_SMS);
if (hasReadSMSPermission != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[] {Manifest.permission.hasReadSMSPermission }, REQUEST_CODE_ASK_PERMISSIONS);
return;
}`
Uninstall the app and install again and try.
As manifest changes does not reflect on re-installations sometimes.
If I am not wrong, may be you have modifies the manifest file after installation.
Just try your luck, it may work.
So I found the problem after 2 days of Headbanging search for solution there is a bug in Emulator of API 23 if Any one Else faces this problem just run it on a different device or on emulator of api level 18 or 19 it'll work. Thanks
I'm using the application class , so I had to create the manifest file, as follows:
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
I have to work normally without problems when testing , often the error occurred in the Google Play Store error report.
But the error report is posted on the Android version 4.4 , I even tested at 4.4 operate normally.
If the person experiencing this problem help me.
java.lang.RuntimeException: Unable to instantiate application com.moonae.android.common.ApplicationClass: java.lang.ClassNotFoundException: Didn't find class "com.culturelandnew.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4524)
at android.app.ActivityThread.access$1500(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.moonae.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:993)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
is this a typo? i have not seen this before i mean android.name to android:name..btw
quick suggestion, remove your application tag, and use the eclipse gui side to search the application class and reference it.. mostly it references the it without package name included.. like this.. =>
<application
android:name="ApplicationClass"
android:icon="#drawble/ic_launcher"
android:largeHeap="true"
....>
I have read several posts for the last couple of days and i can not seem to figure out what my issue is. I have checked the Activity names and they are the same. I have also checked my manifest and I have the . in front of the activities as well.
Here is my logcat file:
02-23 16:48:22.438 1508-1508/com.pctoolman.planme.app E/AndroidRuntime﹕ FATAL
EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.pctoolman.planme.app/com.pctoolman.planme.app.PlanMeMainActivity}:
java.lang.ClassCastException: com.pctoolman.planme.app.PlanMeMainActivity cannot be
cast
to android.app.Activity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.pctoolman.planme.app.PlanMeMainActivity
cannot
be cast to android.app.Activity
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pctoolman.planme.app" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.pctoolman.planme.app.PlanMeMainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.pctoolman.planme.app.NewEventSetupActivity"
android:label="#string/setup">
</activity>
</application>
PlanMeMainFragment.java
package com.pctoolman.planme.app;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class PlanMeMainFragment extends Fragment {
private Button mNewButton, mExistingButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.planme_main_fragment, parent, false);
mNewButton = (Button)v.findViewById(R.id.new_event_button);
mNewButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(getActivity(), NewEventSetupActivity.class);
getActivity().startActivity(myIntent);
}
});
return v;
}
}
PlanMeMainActivity.java
package com.pctoolman.planme.app;
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;
public class PlanMeMainActivity extends Fragment {
public Fragment createFragment() {
return new PlanMeMainFragment();
}
}
Change this line
public class PlanMeMainActivity extends Fragment {
to
public class PlanMeMainActivity extends FragmentActivity {
Here you can find all that you need to know about Activities and even more. Cheers
Where are you wrong?
<activity
android:name="com.pctoolman.planme.app.PlanMeMainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Why are you wrong?
The mistake is that you added the Fragment in the Manifest as
Activity. However Fragments are not activities
What you should do?
You should add the fragment in an activity and then define that activity in the
Manifest
Your PlanMeMainActivity isn't an Activity; it's a Fragment. Your activity needs to be an activity, and you can then add fragments to it.
Clean Project solved this error. The root cause of the error in my case was different, but I got the same "Activity is not assignable to Activity" error.
I faced this problem after copying existing (perfectly working) Android Project to create a new one.
After copying the project, the AppCompatActivity was not recognized causing all the activities in the Android Manifest file to show the error "activity-is-not-assignable-to-activity".
Which was solved by cleaning the project.
Your PlanMainActivity extends a Fragment. A fragment cannot be cast to an activity
Finally, I find out the solution is add following line in your dependencies:
compile 'com.android.support:support-v4:23.2.0'
just delete ".gradle" folder of your project
and press sync button .
its solved my problem
In my case the error was occurred by just installed plugin in Android Studio. So check your plugins and uninstall odd ones.
My problem was solved by Invalidating Caches and Restarting after having Cleaned the Project.