0

I already using Eclipse and I want to migrate to Android Studio. I installed Android Studio and I just created new project but its not running..

Log cat:

08-15 04:49:48.210 1357-1357/? E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{vakili.ramin.apps.myapplication/vakili.ramin.apps.myapplication.FullscreenActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
        at android.app.ActivityThread.access$600(ActivityThread.java:141)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5041)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        at dalvik.system.NativeStart.main(Native Method)
    Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
        at android.view.LayoutInflater.createView(LayoutInflater.java:613)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
        at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:299)
        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
        at vakili.ramin.apps.myapplication.FullscreenActivity.onCreate(FullscreenActivity.java:90)
        at android.app.Activity.performCreate(Activity.java:5104)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
        at android.app.ActivityThread.access$600(ActivityThread.java:141) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:137) 
        at android.app.ActivityThread.main(ActivityThread.java:5041) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:511) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
        at dalvik.system.NativeStart.main(Native Method)

this is my SDK:

enter image description here

enter image description here

I also tried to re syncing project - clean and rebuild - Invalidate caches / Restart-

The Build.Gradle file:

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "19.1.0"

defaultConfig {
    applicationId "vakili.ramin.apps.test3"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-   rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:appcompat-v7:22.2.1'
}

It seems every things is ok.but.... . Android studio is so weird!

Edit : main.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/background_03" >


    <ImageView
        android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/imageView"
       android:layout_gravity="center_horizontal"
       android:background="@drawable/abc_btn_check_to_on_mtrl_015" />
</LinearLayout>

I just added an imageView. and a drawable as it's background!

Edit 2 : xml for full screen activity

<FrameLayout 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:background="#0099cc"
tools:context="vakili.ramin.apps.myapplication.FullscreenActivity">

<!-- The primary full-screen view. This can be replaced with whatever view
     is needed to present your content, e.g. VideoView, SurfaceView,
     TextureView, etc. -->
<TextView
    android:id="@+id/fullscreen_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:keepScreenOn="true"
    android:text="@string/dummy_content"
    android:textColor="#33b5e5"
    android:textSize="50sp"
    android:textStyle="bold" />

<!-- This FrameLayout insets its children based on system windows using
     android:fitsSystemWindows. -->
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:id="@+id/fullscreen_content_controls"
        style="?metaButtonBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:background="@color/black_overlay"
        android:orientation="horizontal"
        tools:ignore="UselessParent">

        <Button
            android:id="@+id/dummy_button"
            style="?metaButtonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/dummy_button" />

    </LinearLayout>
</FrameLayout>

</FrameLayout>
soeldiablo
  • 169
  • 6

2 Answers2

0

replace your parent theme to @style/Theme.AppCompat.NoActionBar

<style name="AppTheme" parent="@style/Theme.AppCompat.NoActionBar">
   <item name="windowActionBar">false</item>
   <item name="android:windowNoTitle">true</item>
</style>

or replace

android:Theme.Material.Light.NoActionBar

With Using the support library theme

Theme.AppCompat.Light.NoActionBar

in style.xml (regardless of version) addresses the issue.

Masroor_Shah
  • 303
  • 1
  • 15
  • I just did tried this . and gives me the same!!! I think I must install some pacakges in SDK but donno what!!!? – soeldiablo Aug 15 '16 at 15:03
  • are you using mobile r emulator – Masroor_Shah Aug 15 '16 at 15:12
  • I 'm Using Genymotion. – soeldiablo Aug 15 '16 at 15:16
  • bro sometime it can be due to emulator try GENY MOTION may you git rid of it or paste error here – Masroor_Shah Aug 15 '16 at 15:17
  • I also tried a project with an empty activity. then just added an imageview.that was ok but when i added a drawable png icon to it . doesent run. and goes to force close.!! `android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.ImageView` – soeldiablo Aug 15 '16 at 15:20
  • bro also try this The cause of the error is that, in the toolbar xml, the ?attr prefix refers to attributes in support library themes. On the other hand, under v22 of style.xml above, the system theme android:Theme.Material.Light.NoActionBar instead of a support library theme is used. The inflater therefore cannot resolve attributes of the support library such as ?attr/actionBarSize. Using the support library theme Theme.AppCompat.Light.NoActionBar in style.xml (regardless of version) addresses the issue. – Masroor_Shah Aug 15 '16 at 15:30
0

Caused by: java.lang.NullPointerException
    at android.app.Activity.findViewById(Activity.java:1884)
    at net.dominik.genpush.settings.<init>(settings.java:23)

You're calling findViewById() too early when initializing an activity settings object, likely a member variable. The code you posted doesn't show that.

You can call activity functions really only in onCreate() or later.

Also put the findViewById() after setContentView() so it can actually return something other than null.

you may have forgot to intiliaze something check ur java code

Masroor_Shah
  • 303
  • 1
  • 15