我的同事使用classpath 'com.android.tools.build:gradle:1.1.0'
在Android Studio 1.4中使用API 21上的Android应用程序。此外,他使用Java jdk1.7.0_75。
现在我需要继续这个项目的工作。但是我有Android Studio 2.1.1,并希望使用API 22或23.我的gradle版本为classpath 'com.android.tools.build:gradle:2.1.0'
,我使用的是Java jdk1.8.0_91。
如果我试着跑步'与他在同一Android设备上的应用程序,我收到此错误:
Executing tasks: [:app:assembleDebug]
Configuration on demand is an incubating feature.
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72100Library
:app:prepareComAndroidSupportRecyclerviewV72100Library
:app:prepareComAndroidSupportSupportV42100Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
C:\Users\z565719\AndroidStudioProjects\DrescherBluetoothCanCom\app\src\main\java\z550583\com\navigationdrawer\ConnectFragment.java:133: error: incomparable types: Object and int
if (data.get(userDatabaseAdapter.ACCESS_NAME) == 1) {
^
[24 more errors like the one above...]
^
Note: C:\Users\z565719\AndroidStudioProjects\DrescherBluetoothCanCom\app\src\main\java\z550583\com\navigationdrawer\MainActivity.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
25 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
出了什么问题:
任务执行失败':app:compileDebugJavaWithJavac'。 编译失败;有关详细信息,请参阅编译器错误输出。
尝试: 使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获得更多日志输出。
建立失败
总时间:1分钟40.139秒
我不知道问题出在哪里,因为如果我尝试使用他的笔记本电脑运行应用程序(使用他的旧Android Studio ..)应用程序可以运行!
有人可以解释错误
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.)
更新
@AshishRanjan要求提供该文件。这是我的ConnectFragment.java:
public class ConnectFragment extends Fragment {
private View rootView;
private Toolbar mToolbar;
private BluetoothComService bluetoothComService;
private boolean isBound = false;
private TextView tvDiConDi;
private ProgressBar pb;
private int CurrentInitProgress = 0;
private int PastInitProgress = 0;
private boolean connectionDetailClicked;
private ImageView ivConnectionDetail;
private ToggleButton tglConnect;
private EditText eTBaudRate;
private EditText eTDbcName;
private LinearLayout LLShowDetail;
private LinearLayout LLConnectToggle;
private LinearLayout LLBaudRate;
private UserDatabaseAdapter userDatabaseAdapter;
private HashMap data;
private ConnectThread connectThread;
private boolean displayThreadLoop = true;
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
BluetoothComService.LocalBinder binder = (BluetoothComService.LocalBinder) service;
bluetoothComService = binder.getService();
isBound = true;
}
@Override
public void onServiceDisconnected(ComponentName name) {
isBound = false;
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onStart() {
super.onStart();
// Bindet an den BluetoothService
Intent intent = new Intent(getActivity(), BluetoothComService.class);
getActivity().bindService(intent, mConnection, getActivity().getApplicationContext().BIND_AUTO_CREATE);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_connect, container, false);
tvDiConDi = (TextView) rootView.findViewById(R.id.tv_display_connect_description);
ivConnectionDetail = (ImageView) rootView.findViewById(R.id.arrow_connection_details);
pb = (ProgressBar) rootView.findViewById(R.id.progress_bar_connect);
pb.setProgress(StateSingleton.getInstance().getProgressConnectState());
eTBaudRate = (EditText) rootView.findViewById(R.id.edit_baud_rate);
eTDbcName = (EditText) rootView.findViewById(R.id.edit_dbc_name);
LLBaudRate = (LinearLayout) rootView.findViewById(R.id.linear_layout_baud_rate);
LLShowDetail = (LinearLayout) rootView.findViewById(R.id.linear_layout_show_detail);
LLConnectToggle = (LinearLayout) rootView.findViewById(R.id.linear_layout_connect_toggle);
tglConnect = (ToggleButton) rootView.findViewById(R.id.connect_toggle);
tglConnect.setChecked(StateSingleton.getInstance().getTglConnectState());
tglConnect.playSoundEffect(SoundEffectConstants.CLICK);
userDatabaseAdapter = new UserDatabaseAdapter(getActivity());
data = userDatabaseAdapter.getFragmentData(InfoSingleton.getInstance().getUserName());
mToolbar = (Toolbar) getActivity().findViewById(R.id.toolbar_actionbar);
//if (data.get(userDatabaseAdapter.ACCESS_NAME) == 1) {
// LLBaudRate.setVisibility(View.VISIBLE);
//}
int ersterInteger = (int) data.get(UserDatabaseAdapter.ACCESS_NAME);
if (ersterInteger == 1){
LLBaudRate.setVisibility(View.VISIBLE);
}
最后一个if(现在已注释)是我收到错误的地方:
data.get(userDatabaseAdapter.ACCESS_NAME)== 1
Android Studio的提示是:
静态成员&#; z550583.com.sql.UserDatabaseAdapter.ACCESS_NAME'通过实例引用访问。通过类实例而不是类本身显示对静态方法和字段的引用。
但旧的Android Studio版本中也显示了相同的提示。所以我不确定这是否是唯一的问题。
答案 0 :(得分:1)
错误表明,data
为HashMap
,而get
的{{1}}方法会返回HashMap
,如果您不是Object
定义value
的类型,因此您需要将值解析为int
,然后再将其与1
进行比较。
你可以这样做:
int yourInteger= (int)data.get(userDatabaseAdapter.ACCESS_NAME);
if(yourInteger == 1){
//do something
}
或强>
您可以定义值的类型。如果您将类型定义为V
,则get
方法将返回V
类型的对象,如文档here所示。
因此,在您的情况下,您可以使用以下泛型定义key
中value
和HashMap
的对象类型:
HashMap<String,Integer> data;
而不是:
HashMap data;