App crash when button is clicked. Unable to start activity ComponentInfo - android

I know that there are problems like this before. I have tried some of the solution given from the thread but it did not seem to solve the error for my application
This is my android.manifest file for the second activity
<application
android:allowBackup="true"
android:icon="#mipmap/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>
<activity
android:name=".RevGPAActivity"
android:label="#string/title_activity_rev_gpa">
<intent-filter>
<action android:name="com.example.user.testapp.RevGPAActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
And here is my MainActivity
private GoogleApiClient client;
Button start_rev_gpa;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
//Start Rev GPA
startRevGPA();
}
public void startRevGPA(){
start_rev_gpa = (Button)findViewById(R.id.startRevGPA);
start_rev_gpa.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.user.testapp.RevGPAActivity");
startActivity(intent);
}
}
);
}
I did not do anything on the xml file like android:onClick or anything. The app hangs for about 3 seconds then it stopped working
Logcat
FATAL EXCEPTION: main
Process: com.example.user.testapp, PID: 29051
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.testapp/com.example.user.testapp.RevGPAActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
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: 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:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at com.example.user.testapp.RevGPAActivity.onCreate(RevGPAActivity.java:10)
at android.app.Activity.performCreate(Activity.java:5937)
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) 

Solved my own problem. If someone stumbled on the same error, the target activity should be extending Activity not ActionBarActivity
You need to use a Theme.AppCompat theme (or descendant) with this activity

As you see in log file: You need to use a Theme.AppCompat theme (or descendant) with this activity could you check `#style/AppTheme" in style.xml of your project, this style need have parent="#style/Theme.AppCompat" or descendant ò

Related

Can't set login activity before mainactivity [duplicate]

This question already has answers here:
FirebaseApp.initializeApp(Context); Android error;
(3 answers)
Closed 5 years ago.
In my android app, i used firebase to sign in with google, but can't set the login activity before main.
Here's the stack trace:
02-12 23:57:02.524 8692-8692/bf_d.binary_femaledefense E/AndroidRuntime: FATAL EXCEPTION: main
Process: bf_d.binary_femaledefense, PID: 8692
java.lang.RuntimeException: Unable to start activity ComponentInfo{bf_d.binary_femaledefense/bf_d.binary_femaledefense.login}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process bf_d.binary_femaledefense. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process bf_d.binary_femaledefense. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source:54)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source:0)
at bf_d.binary_femaledefense.login.onCreate(login.java:53)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6541) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
l already called the FirebaseAuth.initializeApp(this) in the onCreate method. But still showing initializing error in FirebaseApp.
Here's the library i used:
implementation 'com.google.android.gms:play-services-auth:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
And here is my AndroidManifest:
<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/AppTheme">
<activity
android:name=".login"
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>
<activity android:name=".MainActivity"/>
<activity
android:name=".ContactSetup"
android:parentActivityName=".ContextSetup" />
<activity
android:name=".EditContacts"
android:parentActivityName=".EditContacts" />
<activity
android:name=".HowTo"
android:parentActivityName=".MainActivity" />
<activity
android:name=".AboutDevs"
android:parentActivityName=".MainActivity" />
<activity
android:name=".RecordHistory"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CustomText"
android:parentActivityName=".ContextSetup" />
<activity
android:name=".ContextSetup"
android:parentActivityName=".MainActivity" />
</application>
Any Suggestions would be appreciated :)
Extend Application class and call FirebaseApp.initializeApp(this) in onCreate() method of that class:
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
}
}
And add android:name attribute to your manifest
<application
android:name=". MyApplication"
...
>

App Crashes in landscape mode

App is crashing on restart of app after tablet/mobile orientation change,
I m going to develop an application in landscape mode only, and I have made a layout in layout-land with name acitivty_main and there is no any portrait layout in my application and no any layout folder as well, I have also added screenOrientation="landscape" in manifest activity.
Activity Code Following:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
Manifest.xml code following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yasir.sample">
<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/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Project Structure:
FATAL EXCEPTION: main
Process: com.example.yasir.sample, PID: 12611
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.yasir.sample/com.example.yasir.sample.MainActivity}:
android.content.res.Resources$NotFoundException: Resource ID #0x7f04001b
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3151)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5205)
at android.app.ActivityThread.access$1100(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1741)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f04001b
at android.content.res.Resources.getValue(Resources.java:2495)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:4236)
at android.content.res.Resources.getLayout(Resources.java:2311)
at android.view.LayoutInflater.inflate(LayoutInflater.java:413)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.yasir.sample.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3104)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261) 
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5205) 
at android.app.ActivityThread.access$1100(ActivityThread.java:219) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1741) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:6939) 
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:1404) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 
Resources$NotFoundException
This exception is thrown by the resource APIs when a requested
resource can not be found
FYI
Remove
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Add android:configChanges="orientation|screenLayout" in Manifest section .
Finally
<activity android:name=".MainActivity"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout">
Then Clean and Rebuild your project .
https://androidresearch.wordpress.com/2013/05/10/dealing-with-asynctask-and-screen-orientation/
This link will explain how to prevent crashes from AsyncTask and Screen Orentation

Beginner Android java.lang.RuntimeException: Unable to instantiate activity

i am beginner , so do not understand how i fix this problem. My XML code is ok. but when run emulator then click on app its say " unfortunately.... has stopped "
Error msg :
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.imran.justjava/com.example.imran.justjava.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.imran.justjava.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.imran.justjava-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
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: java.lang.ClassNotFoundException: Didn't find class "com.example.imran.justjava.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.imran.justjava-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
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)
Suppressed: java.lang.ClassNotFoundException: com.example.imran.justjava.MainActivity
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Here is my java code
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.example.imran.justjava.R;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
display(1);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(
R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}
Here is Xml Code
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="quantity"
android:textAllCaps="true"
android:padding="16dp"
android:textSize="16sp"
/>
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:padding="16dp"
android:textSize="16sp"
android:textColor="#android:color/black"
/>
<Button
android:id="#+id/order_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="order"
android:onClick="submitOrder"
/>
</LinearLayout>
AndroidManifast.xml code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.imran.justjava" >
<application
android:allowBackup="true"
android:icon="#mipmap/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 had the same issue in latest AndroidStudio. Everything was compiling and running fine in later versions of Android.
However, as soon as I ran the application on an emulator with Android 4.x, it would crash with the same ClassNotFoundException as mentioned in this post.
After trying a lot of solutions suggested online, it turns out the issue was related to multiDexEnabled being set to true. I could have sworn this was working fine before. Disabling the multidex solved the issue.
Following the guide at https://developer.android.com/studio/build/multidex.html#mdex-gradle should probably fix it as well, although I have not tried that out myself.
What is your logcat throws
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.example.imran.justjava.MainActivity"
ClassNotFoundException : ClassNotFoundException occurs when class loader could not find the required class in class path . So , basically you should check your class path and add the class in the classpath.
I guess your activity in manifest is not correct.
Post your manifest.xml .
Have a look here
https://developer.android.com/intl/es/samples/BasicContactables/AndroidManifest.html
Example
<activity
android:name=".MainActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Error:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.imran.justjava/com.example.imran.justjava.MainActivity}:
java.lang.ClassNotFoundException: Didn't find class
I have also faced this issue.
Your MainActivity.java is excluded from compile, so this class isn't included in .apk
Remove following line from excludeFromCompile section of the .idea/compiler.xml file
<file url="file://$PROJECT_DIR$/src/com/example/imran/justjava/MainActivity.java" />
I think error is in your Manifest file.
first ensure that you've declared the MainActivity correctly in AndroidManifest.xml
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Android App Compact theme Error

Hello I' making this project in Android when i start the dialog Activity from Main Activity.
These are the related files:
Main Activity:http://pastebin.com/xyDbBSj4
Dialogs Activity:http://pastebin.com/f6jGC1CH
I have this error on logcat:
FATAL EXCEPTION: main
Process: com.android4dev.navigationview, PID: 30736
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android4dev.navigationview/com.android4dev.navigationview.ui.activities.DialogsActivity}:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:122)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at com.android4dev.navigationview.ui.activities.BaseActivity.onCreate(BaseActivity.java:36)
at com.android4dev.navigationview.ui.activities.DialogsActivity.onCreate(DialogsActivity.java:43)
1- You should declare that your application will be stylized using Theme.AppCompat in your Android Manifest.
Something like this:
<activity
android:name=".my.packageactivity.MyOwnActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat"/>
2- Or maybe declare that the whole application will be stylized using AppCompat.
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat">
3- If you want to set your own style later, you'll have to create a style.xml.
3.1- Using the whole application:
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyOwnStyle">
3.2- Using the activity>
<activity
android:name=".my.packageactivity.MyOwnActivity"
android:label="#string/app_name"
android:theme="#style/MyOwnStyle"/>
And then set the parent to Theme.AppCompat inside your new style.xml file:
<resources>
<style name="MyOwnStyle" parent="Theme.AppCompat">
[...]
</style>
</resources>

android title bar null pointer exception

I know it is simple but I wasnt able to fix it.Tried many solution from SOF.com but none worked. I am trying to display a title for activity and throws NPE. Using API19 for testing.Below are the codes:
In the activity:
public class DisplayImageActivity extends RootActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().setTitle("Image Preview");
In the Manifest:
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".DisplayImageActivity"
android:label="< app name >"
android:screenOrientation="portrait" >
</activity>
In the style.xml:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
Finally, the logcat says:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kittu.<> /com.example.kittu.<>.DisplayImageActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2334)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.kittu.< >.DisplayImageActivity.onCreate(DisplayImageActivity.java:44)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            
If you are using the support library, your activity needs to extend it
import android.support.v7.app.AppCompatActivity
public class MainActivity extends AppCompatActivity{
and use getSupportActionBar() instead of getActionBar()
I think you are using AppCompat, then you should use getSupportActionBar() instead of getActionBar().
Change this:
getActionBar().setTitle("Image Preview");
to this:
getSupportActionBar().setTitle("Image Preview");
Hope this helps :)

Categories

Resources