0
votes

I am currently using online resources. I've done some research but hardly found anything similar.

The problem is that during the first example, I ran the application right after creating it in Eclipse (no changes on my end). The only changes made were to the target SDK which had to be set to the latest Android version.

So when I run the application, the layout looks a bit raw, the text is not centered and the icon is not shown in the header label. I am also unable to see the application in the Main_Activity Graphical Layout.

The created app is called Silent Mode Toggle, I will update whatever necessary code when needed. I could not include the application output...

The label should have been preceded by the application logo or an image, and the "Hello World!" text should have appeared on the center of the screen.

  • Layout XML 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.dummies.android.silentmodetoggle.MainActivity" >
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
    
    </RelativeLayout>
    

P.S. I cannot include the screenshot due to my new profile here on SO.

  • Below is the text generated in LogCat (application launches in AVD), hope this helps:
    1. 09-17 18:33:04.941: E/Trace(676): error opening trace file: No such file or directory (2)
    2. 09-17 18:33:05.541: W/dalvikvm(676): VFY: unable to find class
      referenced in signature (Landroid/view/SearchEvent;)
    3. 09-17 18:33:05.541: I/dalvikvm(676): Could not find method
      android.view.Window$Callback.onSearchRequested, referenced from
      method
      android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
    4. 09-17 18:33:05.541: W/dalvikvm(676): VFY: unable to resolve interface method 14052: Landroid/view/Window$Callback;.onSearchRequested
      (Landroid/view/SearchEvent;)Z
    5. 09-17 18:33:05.541: D/dalvikvm(676): VFY: replacing opcode 0x72 at
      0x0002
    6. 09-17 18:33:05.541: I/dalvikvm(676): Could not find method
      android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
    7. 09-17 18:33:05.551: W/dalvikvm(676): VFY: unable to resolve interface method 14056:
      Landroid/view/Window$Callback;.onWindowStartingActionMode
      (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
    8. 09-17 18:33:05.551: D/dalvikvm(676): VFY: replacing opcode 0x72 at
      0x0002
    9. 09-17 18:33:05.761: I/dalvikvm(676): Could not find method
      android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
    10. 09-17 18:33:05.771: W/dalvikvm(676): VFY: unable to resolve virtual method 13953: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
    11. 09-17 18:33:05.771: D/dalvikvm(676): VFY: replacing opcode 0x6f at 0x0007
    12. 09-17 18:33:05.801: I/dalvikvm(676): Could not find method
      android.content.res.TypedArray.getChangingConfigurations, referenced from method
      android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
    13. 09-17 18:33:05.801: W/dalvikvm(676): VFY: unable to resolve virtual method 401:
      Landroid/content/res/TypedArray;.getChangingConfigurations ()I
    14. 09-17 18:33:05.801: D/dalvikvm(676): VFY: replacing opcode 0x6e at 0x0002
    15. 09-17 18:33:05.801: I/dalvikvm(676): Could not find method
      android.content.res.TypedArray.getType, referenced from method
      android.support.v7.internal.widget.TintTypedArray.getType
    16. 09-17 18:33:05.801: W/dalvikvm(676): VFY: unable to resolve virtual method 423: Landroid/content/res/TypedArray;.getType (I)I
    17. 09-17 18:33:05.801: D/dalvikvm(676): VFY: replacing opcode 0x6e at 0x0002
    18. 09-17 18:33:06.181: D/gralloc_goldfish(676): Emulator without GPU
      emulation detected.
    19. 09-17 18:33:06.241: D/dalvikvm(676): GC_CONCURRENT freed 200K, 4%
      free 8211K/8519K, paused 18ms+8ms, total 163ms
2
You need to include the layout and possibly the desired and current output - codeMagic
To start with, if you are beginning Android development today, why starting with Eclipse (it is deprecated officially for Android). Do with Android studio instead. - Arnav Gupta
Add your layout xml here to the question, that would help everyone see the problem better and provide solutions. - Droidman
Please post relevant code/screenshot/logcat. Users tend to downvote and flag for closure quickly. Awaiting edit. - Sufian
Well I don't know about Android Studio but the book I have is using Eclipse... - Mohammed

2 Answers

3
votes

After doing some trial and error as well as searching around, I found a work around for this issue. My main problem is that I cannot use a theme for my app that is not a child of AppCompat, which means that the only theme that displays the icon in the action bar is the Theme.Holo.Light.DarkActionBar; the one in AppCompat does not have the same layout it seems and I was not allowed to use another. So below is what I've done to work around this:

  1. Create a theme.xml file in res ==> values, values-v11 and values-v14 as below:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="MyAppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <!-- Any customizations for your app running on pre-3.0 devices here -->
        </style>
    </resources>
    
  2. Change the theme set in the styles.xml file in res ==> values, values-v11 and values-v14 as shown below:

Previous:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">

New:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
  1. In your MainActiviy.java file add the code below:

        setTheme(R.style.MyAppTheme);
    

The above code should be positioned before the super.onCreate(savedInstanceState); the entire code is shown below:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.MyAppTheme);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

This basically means that the activity is started without an action bar but then later on the theme changes to the Holo.Light.DarkActionBar. Not doing step (2) would result in having two action bars in the emulator.

Note: Solution above is what has worked for me based on my limited knowledge of Android development.

2
votes

I had the same problem which I solved by changing this import statement as follows

import android.support.v7.app.AlertDialog;

to

import android.app.AlertDialog;

OR VISA VERSA!!!

You can alternatively delete your import statements and add them again by using "alt+Enter" You may find that there are in some cases more than one option in terms of the class to import. Your code should thus be in line with the class you choose!!!

I'm not a guru, but this seems logical to me, and I could not find any other reasonable explanation online...