- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
import android.content.Context
import android.graphics.Color
import android.net.Uri
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.support.v4.view.ViewPager
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.widget.TextView
import android.widget.Toolbar
import java.util.ArrayList
import com.salesrep.auxxa.alliontechnologies.auxxasr.R.id.viewPager
import android.graphics.drawable.GradientDrawable
import android.support.v4.app.FragmentStatePagerAdapter
import android.support.v4.view.PagerAdapter
import android.util.Log
import com.salesrep.auxxa.alliontechnologies.auxxasr.utillities.Session
import org.json.JSONObject
class NewPaymentActivity : AppCompatActivity(),SummaryFragment.OnFragmentInteractionListener,ReceiptDetailsFragment.OnFragmentInteractionListener{
internal lateinit var viewpageradapter: ViewPagerAdapter //Declare PagerAdapter
private var tabLayout: TabLayout? = null
var viewPager: ViewPager? = null
var toolbar: Toolbar? = null
var myPreference : Session? =null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_new_payment)
myPreference= Session(this)
viewpageradapter= ViewPagerAdapter(supportFragmentManager)
viewPager = findViewById(R.id.viewPager) as ViewPager
setupViewPager(viewPager!!)
tabLayout = findViewById(R.id.tab_layout) as TabLayout
tabLayout!!.setupWithViewPager(viewPager)
// tabLayout!!.setSelectedTabIndicatorColor(getResources().getColor(R.color.t));
tabLayout!!.setSelectedTabIndicatorHeight(0)
val headerView = (getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater)
.inflate(R.layout.custom_tabs_for_payments, null, false)
val receiptDetails = headerView.findViewById(R.id.tb_receipt_details) as TextView
val paymentDetails = headerView.findViewById(R.id.tb_payment_details) as TextView
val invoiceDetails = headerView.findViewById(R.id.tb_invoice_details) as TextView
val summary = headerView.findViewById(R.id.tb_summary) as TextView
receiptDetails.setTextColor(resources.getColor(R.color.white))
val drawable = receiptDetails.getBackground() as GradientDrawable
drawable.setColor(resources.getColor(R.color.received_payments))
paymentDetails.setTextColor(resources.getColor(R.color.main))
val drawablepaymentDetails = paymentDetails.getBackground() as GradientDrawable
drawablepaymentDetails.setColor(resources.getColor(R.color.white))
invoiceDetails.setTextColor(resources.getColor(R.color.main))
val drawableinvoiceDetails = invoiceDetails.getBackground() as GradientDrawable
drawableinvoiceDetails.setColor(resources.getColor(R.color.white))
summary.setTextColor(resources.getColor(R.color.main))
val summarydrawable = summary.getBackground() as GradientDrawable
summarydrawable.setColor(resources.getColor(R.color.white))
tabLayout!!.getTabAt(0)!!.setCustomView(receiptDetails)
tabLayout!!.getTabAt(1)!!.setCustomView(paymentDetails)
tabLayout!!.getTabAt(2)!!.setCustomView(invoiceDetails)
tabLayout!!.getTabAt(3)!!.setCustomView(summary)
tabLayout!!.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
if(tab!!.position==0)
{
Log.e("tab","0")
receiptDetails.setTextColor(resources.getColor(R.color.white))
val drawable = receiptDetails.getBackground() as GradientDrawable
drawable.setColor(resources.getColor(R.color.received_payments))
paymentDetails.setTextColor(resources.getColor(R.color.main))
val drawablepaymentDetails = paymentDetails.getBackground() as GradientDrawable
drawablepaymentDetails.setColor(resources.getColor(R.color.white))
invoiceDetails.setTextColor(resources.getColor(R.color.main))
val drawableinvoiceDetails = invoiceDetails.getBackground() as GradientDrawable
drawableinvoiceDetails.setColor(resources.getColor(R.color.white))
summary.setTextColor(resources.getColor(R.color.main))
val summarydrawable = summary.getBackground() as GradientDrawable
summarydrawable.setColor(resources.getColor(R.color.white))
}
else if(tab!!.position==1 && myPreference!!.getReceiptStatus())
{
Log.e("tab","1")
Log.e("stataus",myPreference!!.getReceiptStatus().toString())
paymentDetails.setTextColor(resources.getColor(R.color.white))
val drawable = paymentDetails.getBackground() as GradientDrawable
drawable.setColor(resources.getColor(R.color.received_payments))
receiptDetails.setTextColor(resources.getColor(R.color.main))
val drawablereceiptDetails= receiptDetails.getBackground() as GradientDrawable
drawablereceiptDetails.setColor(resources.getColor(R.color.white))
invoiceDetails.setTextColor(resources.getColor(R.color.main))
val drawableinvoiceDetails = invoiceDetails.getBackground() as GradientDrawable
drawableinvoiceDetails.setColor(resources.getColor(R.color.white))
summary.setTextColor(resources.getColor(R.color.main))
val summarydrawable = summary.getBackground() as GradientDrawable
summarydrawable.setColor(resources.getColor(R.color.white))
}
else if(tab!!.position==2)
{
Log.e("tab","2")
invoiceDetails.setTextColor(resources.getColor(R.color.white))
val drawable = invoiceDetails.getBackground() as GradientDrawable
drawable.setColor(resources.getColor(R.color.received_payments))
receiptDetails.setTextColor(resources.getColor(R.color.main))
val drawablereceiptDetails= receiptDetails.getBackground() as GradientDrawable
drawablereceiptDetails.setColor(resources.getColor(R.color.white))
paymentDetails.setTextColor(resources.getColor(R.color.main))
val drawablepaymentDetails = paymentDetails.getBackground() as GradientDrawable
drawablepaymentDetails.setColor(resources.getColor(R.color.white))
summary.setTextColor(resources.getColor(R.color.main))
val summarydrawable = summary.getBackground() as GradientDrawable
summarydrawable.setColor(resources.getColor(R.color.white))
}
else if(tab!!.position==3)
{
Log.e("tab","3")
summary.setTextColor(resources.getColor(R.color.white))
val drawable = summary.getBackground() as GradientDrawable
drawable.setColor(resources.getColor(R.color.received_payments))
receiptDetails.setTextColor(resources.getColor(R.color.main))
val drawablereceiptDetails = receiptDetails.getBackground() as GradientDrawable
drawablereceiptDetails.setColor(resources.getColor(R.color.white))
paymentDetails.setTextColor(resources.getColor(R.color.main))
val drawablepaymentDetails = paymentDetails.getBackground() as GradientDrawable
drawablepaymentDetails.setColor(resources.getColor(R.color.white))
invoiceDetails.setTextColor(resources.getColor(R.color.main))
val drawableinvoiceDetails = invoiceDetails.getBackground() as GradientDrawable
drawableinvoiceDetails.setColor(resources.getColor(R.color.white))
}
else {
}
}
override fun onTabUnselected(tab:TabLayout.Tab?){
}
override fun onTabReselected(tab:TabLayout.Tab?) {
}
})
}
private fun setupViewPager(viewPager: ViewPager) {
viewPager.setOffscreenPageLimit(-1);
val adapter = ViewPagerAdapter(supportFragmentManager)
viewPager.adapter = adapter
}
inner class ViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager) {
override fun getItem(position: Int): Fragment? {
var fragment: Fragment? = null
if (position == 0 ) {
Log.e("frag",position.toString())
fragment = ReceiptDetailsFragment()
} else if (position == 1 && myPreference!!.getReceiptStatus() ) {
Log.e("frag",position.toString())
fragment = PaymentDetailsFragment()
} else if (position == 2) {
Log.e("frag",position.toString())
fragment = InvoiceDetailsFragment()
} else if (position == 3) {
Log.e("frag",position.toString())
fragment = InvoiceDetailsFragment()
}
return fragment
}
override fun getPageTitle(position: Int): CharSequence {
return when (position) {
0 -> "Receipt Details"
1 -> "Payment Details"
2 -> "Invocie Details"
3 -> "Summary"
else -> throw IllegalArgumentException()
}
}
override fun getCount(): Int {
return 4
}
}
override fun onFragmentInteraction(jsonObject: JSONObject) {
//session intialization
val myPreference = Session(this)
myPreference.setJsonObject(jsonObject.toString())
viewPager!!.setCurrentItem(1,true)
}
override fun onFragmentInteraction(uri: Uri) {
}
}
private operator fun Int.invoke(i: Int) {
}
Above I have attched my NewPaymentActivity class.But issue is that I got one null pointer exception once I run this code.I need to use session values inside my inner class.But It seems session initialization pass null value. Inside inner class I used myPreference!!.getReceiptStatus() but myPreference value is null.Below I'll attch my log record also.
Process: com.salesrep.auxxa.alliontechnologies.auxxasr, PID: 6082
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
最佳答案
myPreference!!.getReceiptStatus()
避免使用“!!”,始终检查是否可为空,
myPreference?.let { it.getReceiptStatus() }
这样使用,异常就解决了
override fun onFragmentInteraction(jsonObject: JSONObject) {
//session intialization
val myPreference = Session(this)
myPreference.setJsonObject(jsonObject.toString())
viewPager!!.setCurrentItem(1,true)
}
这里你正在分配 myPreference 的局部变量,我认为你可能需要更改或将其分配给全局变量只需从 - val myPreference = Session(this)
中删除 val关于android - Kotlin 内部类无法发起 Session 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53590324/
我通过 spring ioc 编写了一些 Rest 应用程序。但我无法解决这个问题。这是我的异常(exception): org.springframework.beans.factory.BeanC
我对 TestNG、Spring 框架等完全陌生,我正在尝试使用注释 @Value通过 @Configuration 访问配置文件注释。 我在这里想要实现的目标是让控制台从配置文件中写出“hi”,通过
为此工作了几个小时。我完全被难住了。 这是 CS113 的实验室。 如果用户在程序(二进制计算器)结束时选择继续,我们需要使用 goto 语句来到达程序的顶部。 但是,我们还需要释放所有分配的内存。
我正在尝试使用 ffmpeg 库构建一个小的 C 程序。但是我什至无法使用 avformat_open_input() 打开音频文件设置检查错误代码的函数后,我得到以下输出: Error code:
使用 Spring Initializer 创建一个简单的 Spring boot。我只在可用选项下选择 DevTools。 创建项目后,无需对其进行任何更改,即可正常运行程序。 现在,当我尝试在项目
所以我只是在 Mac OS X 中通过 brew 安装了 qt。但是它无法链接它。当我尝试运行 brew link qt 或 brew link --overwrite qt 我得到以下信息: ton
我在提交和 pull 时遇到了问题:在提交的 IDE 中,我看到: warning not all local changes may be shown due to an error: unable
我跑 man gcc | grep "-L" 我明白了 Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more inf
我有一段代码,旨在接收任何 URL 并将其从网络上撕下来。到目前为止,它运行良好,直到有人给了它这个 URL: http://www.aspensurgical.com/static/images/a
在过去的 5 个小时里,我一直在尝试在我的服务器上设置 WireGuard,但在完成所有设置后,我无法 ping IP 或解析域。 下面是服务器配置 [Interface] Address = 10.
我正在尝试在 GitLab 中 fork 我的一个私有(private)项目,但是当我按下 fork 按钮时,我会收到以下信息: No available namespaces to fork the
我这里遇到了一些问题。我是 node.js 和 Rest API 的新手,但我正在尝试自学。我制作了 REST API,使用 MongoDB 与我的数据库进行通信,我使用 Postman 来测试我的路
下面的代码在控制台中给出以下消息: Uncaught DOMException: Failed to execute 'appendChild' on 'Node': The new child el
我正在尝试调用一个新端点来显示数据,我意识到在上一组有效的数据中,它在数据周围用一对额外的“[]”括号进行控制台,我认为这就是问题是,而新端点不会以我使用数据的方式产生它! 这是 NgFor 失败的原
我正在尝试将我的 Symfony2 应用程序部署到我的 Azure Web 应用程序,但遇到了一些麻烦。 推送到远程时,我在终端中收到以下消息 remote: Updating branch 'mas
Minikube已启动并正在运行,没有任何错误,但是我无法 curl IP。我在这里遵循:https://docs.traefik.io/user-guide/kubernetes/,似乎没有提到关闭
每当我尝试docker组成任何项目时,都会出现以下错误。 我尝试过有和没有sudo 我在这台机器上只有这个问题。我可以在Mac和Amazon WorkSpace上运行相同的容器。 (myslabs)
我正在尝试 pip install stanza 并收到此消息: ERROR: No matching distribution found for torch>=1.3.0 (from stanza
DNS 解析看起来不错,但我无法 ping 我的服务。可能是什么原因? 来自集群中的另一个 Pod: $ ping backend PING backend.default.svc.cluster.l
我正在使用Hibernate 4 + Spring MVC 4当我开始 Apache Tomcat Server 8我收到此错误: Error creating bean with name 'wel
我是一名优秀的程序员,十分优秀!