我想将一个char指针转换为unsigned char var,我想我只能通过强制转换来实现,但它不起作用:
char * pch2;
//Code that puts something in pc2
part1 = (unsigned char) pch2;
Run Code Online (Sandbox Code Playgroud)
我有这个代码:
result.part1 = (unsigned char *) pch2;
printf("STRUCT %s\n",result.part1);
Run Code Online (Sandbox Code Playgroud)
result只是一个带有unsigned char数组的结构.
编辑:
pch2 = strtok( ip, "." );
while( pch2 != NULL ){
printf( "x %d x: %s\n", i, pch2 );
pch2[size-1] = '\0';
if(i == 1)
result.part1 = (unsigned char *) pch2;
if(i == 2)
result.part2 = (unsigned char *) pch2;
if(i == 3)
result.part3 = (unsigned char *) pch2;
if(i == …Run Code Online (Sandbox Code Playgroud) 我在我的Android项目中第一次使用框架Retrofit.它处理与后端的通信.现在最奇怪的部分是在Android 4.4上,一切都像魅力一样.在下面的每个版本.我得到一个RetrofitError类型java.io.EOFException.所以它第一次失败然后当我按下重试按钮时它工作.那为什么第一次失败呢?
我想解决这个问题,因为用户需要点击重试才很烦人...
有人为此得到了解决方案吗?
我正在使用一个日期选择器,并希望将最小日期设置为今天,并将最大日期设置为今天提前一年.
我这样做:
datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
cal.add(Calendar.YEAR, 1);
datePickerDialog.getDatePicker().setMaxDate(cal.getTimeInMillis());
Run Code Online (Sandbox Code Playgroud)
当我不做 - 1000然后我得到另一个例外:
java.lang.IllegalArgumentException: fromDate: Sat Apr 11 23:59:59 CEST 2015 does not precede toDate: Sat Apr 11 08:24:19 CEST 2015
Run Code Online (Sandbox Code Playgroud)
那是因为日期可能不等于今天.所以我提取1000毫秒.
我不知道如何解决新的异常.我试着在maxDate上计算+ 1000毫秒但是没有解决它.
编辑:
我像这样创建我的cal:
cal = Calendar.getInstance();
datePickerDialog = new DatePickerDialog(getActivity(), this, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
Run Code Online (Sandbox Code Playgroud) 我想在我的jsp中使用JSTL库.现在我按照教程告诉我将这行添加到jsp页面:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Run Code Online (Sandbox Code Playgroud)
它给我的错误无法用uri解析taglib,然后是URL.
我正在运行tomcat 8.我的web.xml是这样的:
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决这个问题吗?
我已经将我的Swift 2.3项目转换为swift 3.现在编译器不再抛出任何错误,但它会继续编译.CPU就像是100%,如果你不停止它,它会持续编译50分钟或更长时间.
Xcode一直在说建筑.. | 编译Swift源文件
在构建日志中,它始终停在相同的swift文件上.swift文件只是简单的模型类,所以我不知道问题是什么.
我在swift 2中遇到了同样的问题,但这是由??运营商引起的.我重构了代码以删除??运算符,因此它不再是这个.
我怎样才能找出减慢编译时间的原因?
我的模特看起来都一样:
class Test: InputContract {
var appointmentDate: Date!
var startTime: String!
var endTime: String!
var registerDescription: String!
var subjectKey: String!
var channelCode: String!
var relationManagerHrId: String = ""
var employeeUserCode: String = ""
var smsReminderMobileNumber: String = ""
var smsReminderMobileNumberSequence: String!
var contactPhoneNumber: String = ""
var contactPhoneNumberSequence: String!
var smsReminder: Bool = false
override func retrieveInputDictionary() -> NSDictionary {
return ["description" : self.registerDescription, "appointmentDate" : …Run Code Online (Sandbox Code Playgroud) 我有一个带有默认文本的EditText.
现在,当用户点击该EditText时,默认文本应更改为某些内容.
我得到的是:
我怎么能解决这个问题,从第一次开始呢?
这是我的xml:
<EditText
android:id="@+id/step"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="5dp"
android:hint="@string/hnt_message"
android:text="Default text"
android:maxLength="@integer/max_free_msg_length"
android:maxLines="2"
/>
Run Code Online (Sandbox Code Playgroud)
这是我的片段代码:
private EditText editMessage;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mContentView = inflater.inflate(R.layout.fragment_step, container, false);
ButterKnife.inject(this, mContentView);
editMessage = (EditText) mContentView.findViewById(step);
editMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
clearEditMessageText();
}
});
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用butterknife来制作这个按钮,但我做了,但没有用.
我第一次使用MagicalRecord.
我把它设置成这样:
[MagicalRecord setupCoreDataStackWithStoreNamed:@"test"];
Run Code Online (Sandbox Code Playgroud)
其中test是我的Core数据文件(test.xcdatamodeld)的文件名.
在我的视图控制器中,我想要使用我的核心数据,我写了这个:
- (void)viewDidLoad
{
[super viewDidLoad];
// If there is no POI, create a new POI
if (!_poi) {
_poi = [POI MR_createEntity];
}
// If there is no POI rank(=category) create one
if (!_poi.rank) {
_poi.rank = [Rank MR_createEntity];
}
}
Run Code Online (Sandbox Code Playgroud)
我在哪里
@Class POI;
Run Code Online (Sandbox Code Playgroud)
在头文件中.POI和Rank是我的xCode生成的coredata类.
当我跑这个:我总是得到:
2014-08-08 14:52:05.509 test[41248:60b] *** Assertion failure in +[NSManagedObjectContext MR_defaultContext], /Users/x/Documents/xCode/test/test/Pods/MagicalRecord/MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalRecord.m:60
2014-08-08 14:52:05.512 test[41248:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Default Context is nil! Did you …Run Code Online (Sandbox Code Playgroud) 我正在测试我的服务类,它可以在互联网上获取一些IP。我的测试是这样写的:
TestTryoutTestService webServices = new TestTryoutTestService(ENDPOINTESTURL);
TestService adapter = webServices.getWebservice();
adapter.getIpAsync(mCallback);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
assertEquals("IP is not equal", result, "1");
}
Callback<TestResponse> mCallback = new Callback<TestResponse>() {
@Override
public void success(TestResponse testResponse, Response response) {
result = testResponse.getIp();
}
@Override
public void failure(RetrofitError error) {
fail();
}
};
Run Code Online (Sandbox Code Playgroud)
问题是我的 Thread.sleep 太短,我认为它很难看。所以我的问题是如何在测试用例中等待回调结果?
编辑:
测试是通过 robolectric 进行的。即使线程睡眠 10000,它也永远不会出现在回调中。http 通过线框进行存根,如果不是异步完成,它就可以工作。
stubFor(get(urlMatching("/ip/.*"))
.atPriority(5)
.willReturn(aResponse()
.withStatus(200)
.withBodyFile("ip_response.json")
));
Run Code Online (Sandbox Code Playgroud) 我正在使用Espresso 2来测试按钮是否已启用。我的代码如下所示:
onView(withId(R.id.fragment_vote_pause_btn)).check(matches(isEnabled()));
Run Code Online (Sandbox Code Playgroud)
我的按钮定义为:
<Button
android:id="@+id/fragment_vote_pause_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent"
android:text="@string/audiowave_pause_or_play"
android:textColor="@drawable/play_pause_button_selector"
android:textAllCaps="false"
android:textSize="12sp" />
Run Code Online (Sandbox Code Playgroud)
有时测试有效,但有时却出现以下异常:
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is enabled' doesn't match the selected view.
Expected: is enabled
Got: "Button{id=2131296458, res-name=fragment_vote_pause_btn, visibility=INVISIBLE, width=329, height=144, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=false, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=375.0, y=649.0, text=Tap to play or pause, input-type=0, ime-target=false, has-links=false}"
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:580)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:82)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:53)
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:185)
at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:158)
at be.appfoundry.identify.ui.VoteActivityTest.test2PlayPauseButton(VoteActivityTest.java:39)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at …Run Code Online (Sandbox Code Playgroud) 我正在使用 Angular Material Table,我想更改表中的标题名称。
所以我为列创建了一个数组:
columnsToDisplay = [{"display": "name", "name": "Name"}, {"display": "something", "name": "Something here"}]
Run Code Online (Sandbox Code Playgroud)
然后我想我可以通过以下方式来解决这个问题:
<ng-container matColumnDef="{{column}}" *ngFor="let column of columnsToDisplay">
<th mat-header-cell *matHeaderCellDef mat-sort-header> {{column.name}} </th>
<td mat-cell *matCellDef="let element"> {{element[column]}} </td>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
但后来我得到这个错误:
Duplicate column definition name provided: "[object Object]".
Run Code Online (Sandbox Code Playgroud)