I was getting this message, 'Field can be converted to a local variable'. Did some research on it and found this good post:here
The variables I was getting the message with are these, declared straight after:
reverseSelectionSort( A[0...n-1])
{
for(int i=n-1; i=>1; i--)
{
int min = i;
for(int j=i-1; j=>0; j--)
{
if(A[j] < A[min])
{
min = j;
}
}
swap(A[i], A[min])
}
}
So I took it's advice and made my code like this:
public class MainActivity extends Activity {
final ListView listview;
final String callType;
final String phoneNumber;
final String callDate;
final String callDuration;
final Date callDateTime;
And now callType, phoneNumber, callDate, callDuration, callDateTime are coming up in red and I get errors - illegal start of expression - when I try compile my project.
Can anyone tell me what's wrong and how to fix this problem?
答案 0 :(得分:1)
Just remove the $scope.newTask = function() {
$ionicPopup.prompt({
title: "New Task",
template: "Enter Task:",
inputPlaceholder: "What do you need to do?",
okText: 'Create Task'
}).then(function(res) { // promise
if (res) $scope.tasks.push({title: res, completed: false});
})
};
modifier.
When applied to an instance variable, the final modifier simply means that the instance variable can’t be changed.
In your example you declared final variables, but didn't set them any value. That's the reason of your issue.
Also you should declare your variables in that methods where you use them. So parts of your code should be like these:
final
答案 1 :(得分:1)
Because your variables are final. You cannot reassign any value to a final variable. Remove the keyword final and try it again. Let me know if it works or not. Good luck.
答案 2 :(得分:1)
您现在收到错误,因为您已使用错误的方法声明了变量。将声明从onCreate移动到正在使用它们的getCallDetails中。
答案 3 :(得分:0)
如果你想让它成为最终版,那就把它作为静态
答案 4 :(得分:-3)
我认为你不能在调用super.onCreate()之前声明变量,因为你没有Context。