由于某些设备上发生的运行时错误,我需要一些可以使我的类可为空/可选的东西.
这可能吗?
class MyFragment extends Fragment {
@Inject
var presenter: MyPresenter? = null
// Other codes here...
}
Run Code Online (Sandbox Code Playgroud)
我想使用这个presenter选项,因为一些旧的Android设备特别抛出这个错误(这是在我删除lazyinit之前).
码:
class MyFragment extends Fragment {
@Inject
lazyinit var presenter: MyPresenter? = null
// Other codes here...
override fun onDestroy() {
super.onDestroy()
presenter.somecode()
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
Fatal Exception: java.lang.RuntimeException: Unable to destroy activity {com.sample.MyActivity}: c.r: lateinit property presenter has not been initialized
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3497)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3515)
at android.app.ActivityThread.access$1400(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1249)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at …Run Code Online (Sandbox Code Playgroud) 我目前正在研究Fragments它是在Activitieswith下创建的FragmentPagerAdapter。我使用 GreenRobot 的 EventBus 3.0 返回我从服务类创建的一些 AsyncTask。然而,由于这两个片段是一个接一个地创建的,事件总线的 poststicky 的返回使订阅的片段混淆了。我已经浏览过stackoverflow,做了其他人所做的事情(例如,将eventBus 寄存器设置为onStart 和OnStop 等),但我仍然看不到类似的问题。希望您能够帮助我。谢谢!
这是我的两个片段:(我省略了一些不必要的代码)
1.状态片段
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.e(TAG, "StatusFragment onCreateView");
eventBus = EventBus.getDefault();
eventBus.register(this);
StatusService statusService = StatusService.newInstance(getContext());
statusService.getStatusList(); //Async Task to call onReturnAdapter once finished
return mRecyclerView;
}
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onReturnList(List<Status> statuses) {
Log.e(TAG, "onReturnList");
mAdapter = new StatusRecyclerAdapter(statuses);
mRecyclerView.setAdapter(mAdapter);
eventBus.removeStickyEvent(statuses);
}
@Override
public void onStop() {
Log.e(TAG, "onStop");
eventBus.unregister(this); …Run Code Online (Sandbox Code Playgroud) android android-fragments greenrobot-eventbus greenrobot-eventbus-3.0
我只是使用最新的REALM版本制作基本领域文件,但编译器抛出此错误:
An exception has occurred in the compiler (1.8.0). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for rx.Observable not found
Run Code Online (Sandbox Code Playgroud)
我做的应用程序仍然相对较小,它适用于Realm ver 0.82.0我仍然不知道是什么导致了这个问题.我想使用最新版本,但此错误阻止了它.你有什么想法如何处理这个?
这是编译器错误堆栈跟踪:
Executing tasks: [:app:assembleDebug]
Configuration on demand is an incubating feature.
Observed package id 'add-ons;addon-google_apis-google-19' in inconsistent location 'C:\Users\Paul.Aragones\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-19-1' (Expected 'C:\Users\Paul.Aragones\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-19')
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE …Run Code Online (Sandbox Code Playgroud) 我目前正在测试 Dokka 文档,我所做的一些注释没有被渲染。以下是我的发现:
@sample, 和 html 标签<p></p>, <h1></h1>: 请参阅 SimpleCalculator类文档enum class OPERATOR代码文档@sample:@property请参阅所有方法代码文档@property和之间的定义混合@param。在类声明中, the@param是 a 内的那个<>(例如Group<T>)。但在方法中,它是参数内的那个。请看我的代码:
package example
/**
* <h1> A Simple Calculator for your daily needs! </h1>
*
* <p> This class can help you add, subract, multiply and divide Integers </p>
*
* @property firstNumber the first Number you want to …Run Code Online (Sandbox Code Playgroud) 我可以为两个jsps使用一个请求映射吗?
我目前正在从一个控制器调用一个请求映射,但其中一个jsps似乎没有被控制器捕获.
两个jsps都具有相同的表单操作和相同的表单方法:
first.jsp看起来像这样:
<form:form method="POST" action="/ShowroomNav/requestQuote" id="requestQuoteForm">
<input type="hidden" value=${product.productCode } name="productCodes" />
<input type="hidden" id="requestQuoteEmailAddress" name="requestQuoteEmailAddress" />
</form:form>
Run Code Online (Sandbox Code Playgroud)
second.jsp看起来像这样:
<form:form method="POST" action="/ShowroomNav/requestQuote" id="requestQuoteForm">
<input type="hidden" id="requestQuoteEmailAddress" name="requestEmailAddress" />
<c:forEach var="product" items="${products}">
<input type="hidden" value=${product.productCode } name="productCodes" />
<div class="box">
<img
src="public/productImages/${product.productCode}/${product.productCode}A.jpg"
style="max-width: 100%"
onclick="productProfile('${product.productCode}')" /><br /> <label
class="name">${product.productName}</label>
</div>
</c:forEach>
</form:form>
Run Code Online (Sandbox Code Playgroud)
他们都通过javascript调用提交函数:
$("#requestQuoteSubmitButton").one("click",function(){
$("#requestQuoteEmailAddress").val($("#requestQuoteEmailAddressModal").val());
alert($("#requestQuoteEmailAddress").val());
$("#requestQuoteForm").submit();
});
Run Code Online (Sandbox Code Playgroud)
这就是controller.java的样子:
@RequestMapping(value = "/requestQuote", method = RequestMethod.POST) // or GET
public String requestQuote(@RequestParam("requestQuoteEmailAddress") String requestQuoteEmailAddress, @RequestParam("productCodes") String[] productCodes) {
System.out.println(">>>> requesting …Run Code Online (Sandbox Code Playgroud) android ×2
java ×2
kotlin ×2
dagger-2 ×1
javascript ×1
jsp ×1
kdoc ×1
kotlin-dokka ×1
realm ×1
spring ×1
spring-mvc ×1