WhiteWolf
WhiteWolf

Reputation: 23

unresolved reference bundle android studio

I just started to learning kotlin for android studio and built my first project, i did not touched anything but android studio getting me this error: unresolved reference bundle, even trying to import android.os.Bundle did not worked. at first i was getting the error : unresolved reference R, but when i updated kotlin plugin, getting previous error that i already told you about. as i said i never touched anything and this files built by android studio itself. any ideas ?

this is app level gradle :

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.deathstroke.samplekotlinproject"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
         release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

and this is project level gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.31'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and this is main activity class :

package com.example.deathstroke.samplekotlinproject

import android.support.v7.app.AppCompatActivity
import android.os.bundle;

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: android.os.Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

android studio showing me Bunlde in red color and alt + Enter dose not have an option as import class...

Upvotes: 0

Views: 7311

Answers (2)

Sasi Kumar
Sasi Kumar

Reputation: 13278

Yours imports in java code but your methods in kotlin

Remove your imports

  import android.os.bundle;

then replace

override fun onCreate(savedInstanceState: Bundle?) 

press Alt+Enter imports will included automatically in android studio.

import android.os.Bundle 

Then clean and rebuild project

Upvotes: 1

Andrei Tanana
Andrei Tanana

Reputation: 8422

Class names in Kotlin are case sensitive. So you have to import Bundle instead of bundle

import android.os.Bundle

Upvotes: 3

Related Questions