Intent intent=new Intent(MainActivity.this, ContactListActivity.class);
startActivity(intent);
MainActivity.this是用java編寫的,ContactListActivity是用kotlin編寫的。我試圖調用ContactListActivty,但最終得到錯誤在kotlin中找不到類?
have you declared this activity in your AndroidManifest.xml?
我還在清單文件中添加了該活動。
<activity android:name="Chat_Activity$Connections$ContactListActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
編輯:
ContactListActivity.kt
class ContactListActivity : AppCompatActivity() {
private var mBroadcastReceiver: BroadcastReceiver? = null
private val TAG:String="ContactListActivity"
//static variable
object Obz{
@JvmStatic val GetContactListFromServer:String="Contact List"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(layout.activity_contact_list)
title = "Contact list"
contact_list.hasFixedSize()
contact_list.layoutManager= LinearLayoutManager(this)
getContactListAndNextActivity()
}
fun getContactListAndNextActivity(){
contact_list.adapter= ContactListAdaptor(applicationContext, dbHelper(applicationContext).getContactList())
}
}
如何以及在哪裏是'ContactListActivity'類中聲明? – miensol
它在清單中聲明。 @miensol –
你能告訴我們你有'class ContactListActivity'的源代碼嗎? – miensol