1

I'm continuing to try and get a simple tablayout carousel to work with Android Kotlin, and now I'm running into another problem.

If you saw another thread of mine I'm trying to get this tutorial up and running: http://www.techotopia.com/index.php/Kotlin_-_Creating_a_Tabbed_Interface_using_the_TabLayout_Component

After fixing the fragment type mismatch (Fragment Type Mismatch in Android Kotlin), I now cannot run the project and I get this error:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.example.patientplatypus.kotlintabstrialagain, PID: 26869
                  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.patientplatypus.kotlintabstrialagain/com.example.patientplatypus.kotlintabstrialagain.TabLayoutDemoActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.patientplatypus.kotlintabstrialagain.TabLayoutDemoActivity" on path: DexPathList[[zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/base.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/lib/x86, /system/lib, /vendor/lib]]
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2718)
                      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)
E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.patientplatypus.kotlintabstrialagain.TabLayoutDemoActivity" on path: DexPathList[[zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/base.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.patientplatypus.kotlintabstrialagain-GDQWJ8v6l5XBSbfdWfWidA==/lib/x86, /system/lib, /vendor/lib]]
                      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                      at android.app.Instrumentation.newActivity(Instrumentation.java:1173)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2708)
                        ... 9 more

The problem is the following; Android SDK does not recognize my TabLayoutDemoActivity class as being on the dexpath. The tutorial I linked to unfortunately does not have an android manifest file, but here is mine. Note that TabLayoutDemoActivity very much is referenced, and is called as the class to boot on runtime:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.patientplatypus.kotlintabstrialagain">

    <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="TabLayoutDemoActivity"
            android:label="TabLayoutDemoActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

One of the solutions that I tried doing instead was to make a main activity page that simply linked to the TabLayoutDemoActivity activity through a button click, and put the main activity in the manifest instead. So this would be my very simple main file:

package com.example.patientplatypus.kotlintabstrialagain

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View



class MainActivity : AppCompatActivity() {

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

    fun tabMe(view: View){
        // Create an Intent to start the second activity
        val tabIntent = Intent(this, TabLayoutDemoActivity::class.java)

        // Start the new activity.
        startActivity(tabIntent)
    }
}

Here I get the error that on line val tabIntent = Intent(this, TabLayoutDemoActivity::class.java) the class TabLayoutDemoActivity is an unresolved reference. This very much does not make sense to me, as TabLayoutDemoActivity exists in the same folder and is a class.

I've searched SO and tried the solutions that I found here: Didn't find class on path: DexPathList?, but none of them seemed to work.

If anyone could let me know where I am going wrong that would be great. As a new user I find it very frustrating that something seemingly so basic presents this much of a hurdle.

Thanks.

EDIT

Here is my TabLayoutDemoActivity class. It is the same as the one that is linked to in the site above (they had a small syntax error at the bottom of the class and that's been fixed, but otherwise it is the same):

import android.os.Bundle
import android.support.design.widget.FloatingActionButton
import android.support.design.widget.Snackbar
import android.support.design.widget.TabLayout
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import com.example.patientplatypus.kotlintabstrialagain.R
import com.example.patientplatypus.kotlintabstrialagain.R.id.*
import com.example.patientplatypus.kotlintabstrialagain.TabPagerAdapter

import kotlinx.android.synthetic.main.activity_tab_layout_demo.*

class TabLayoutDemoActivity: AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tab_layout_demo)
        setSupportActionBar(toolbar)

        fab.setOnClickListener { view ->
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show()
        }
        configureTabLayout()
    }

    private fun configureTabLayout() {

        tab_layout.addTab(tab_layout.newTab().setText("Tab 1 Item"))
        tab_layout.addTab(tab_layout.newTab().setText("Tab 2 Item"))
        tab_layout.addTab(tab_layout.newTab().setText("Tab 3 Item"))
        tab_layout.addTab(tab_layout.newTab().setText("Tab 4 Item"))

        val adapter = TabPagerAdapter(supportFragmentManager,
                tab_layout.tabCount)
        pager.adapter = adapter

        pager.addOnPageChangeListener(
                TabLayout.TabLayoutOnPageChangeListener(tab_layout))
        tab_layout.addOnTabSelectedListener(object :
                TabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: TabLayout.Tab) {
                pager.currentItem = tab.position
            }

            override fun onTabUnselected(tab: TabLayout.Tab) {

            }

            override fun onTabReselected(tab: TabLayout.Tab) {

            }

        })
    }
}
Jayson Minard
  • 84,842
  • 38
  • 184
  • 227
Peter Weyand
  • 2,159
  • 9
  • 40
  • 72
  • Can you post your TabLayoutDemoActivity class? And I am assuming the MainActivity class worked fine when you tested the button click? – Eugene H Feb 19 '18 at 15:57
  • Sure - I posted the class above (same as on the website). The button is a bog standard button, as you can see above and the xml file for the main class has a button object with `android:onClick="tabMe"`. I think the issue is definitely somehow in my manifest, TabLayoutDemoActivity, or maybe (?) my gradle files. Something is broken somewhere but main is pretty standard. – Peter Weyand Feb 19 '18 at 16:03
  • Do you have the package above all of the imports? – Eugene H Feb 19 '18 at 16:10
  • Yeah, that was the problem. But now I'm getting `must implement OnFragmentInteractionListener` exceptions. I'll probably just go back to React Native, I can get that to compile at least. Thanks anyway. – Peter Weyand Feb 19 '18 at 16:29
  • This is pretty much a "why isn't my code working" and almost would require someone loading your entire project to see the problem. Also the outside link means that a lot of information would not be self-contained here and might vanish some day, lowering the utility of this question for others. – Jayson Minard Feb 19 '18 at 16:37

0 Answers0