我是Android的新手,听说过改装。但是当我试图实现这个时,我收到了这个错误:
11-07 10:57:59.969 8036-8291/com.example.first.servicefirst W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
11-07 10:57:59.969 8036-8291/com.example.first.servicefirst W/dalvikvm﹕ VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
11-07 10:57:59.969 8036-8291/com.example.first.servicefirst I/dalvikvm﹕ Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
11-07 10:57:59.969 8036-8291/com.example.first.servicefirst W/dalvikvm﹕ VFY: unable to resolve static method 18524: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;
我真的很困惑我哪里出错了。
这是我的主要活动:
package com.example.first.servicefirst;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import java.io.IOException;
import retrofit.Call;
import retrofit.Callback;
import retrofit.GsonConverterFactory;
import retrofit.Response;
import retrofit.Retrofit;
public class MainActivity extends Activity {
public EditText password,userName;
Button login,resister;
ProgressBar progressbar;
TextView tv;
String TAG="Fails";
String url="http://172.16.7.203/sfAppServices/SF_UserLogin.svc";
private ModelLogin Result;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
password=(EditText) findViewById(R.id.password);
userName=(EditText) findViewById(R.id.txtEmployeeCode);
login=(Button) findViewById(R.id.btnsignin);
userName.setBackgroundResource(R.drawable.colorfoucs);
//progess_msz.setVisibility(View.GONE);
ConnectivityManager cn=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nf=cn.getActiveNetworkInfo();
if(nf != null && nf.isConnected()==true )
{
Toast.makeText(this, "Network Available", Toast.LENGTH_LONG).show();
} else {
showAlertDialog(MainActivity.this,"No Network","Please Check Your Network Connectivity",true);
}
final ConnectionDetector cd = new ConnectionDetector(getApplicationContext());
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
progressbar = (ProgressBar) findViewById(R.id.progressBar);
progressbar.setVisibility(View.VISIBLE);
String s1 = userName.getText().toString();
String s2 = password.getText().toString();
if (s1.equals("")) {
userName.setError("Enter User Name");
}
if (s2.equals("")) {
password.setError("Enter Password");
}
try{
OkHttpClient client = new OkHttpClient();
client.interceptors().add(new Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
Request original = chain.request();
// Customize the request
Request request = original.newBuilder()
.header("Accept", "application/json")
.header("Authorization", "auth-token")
.method(original.method(), original.body())
.build();
com.squareup.okhttp.Response response = chain.proceed(request);
// Customize or return the response
return response;
}
});
Retrofit retro = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).build();
RetrofitRest retrofitRest = retro.create(RetrofitRest.class);
Call<ModelLogin>call=retrofitRest.getResult(s1, s2);
// Call<ModelLogin> callget=retrofitRest.verify(result);
call.enqueue(new Callback<ModelLogin>()
{
@Override
public void onResponse(Response<ModelLogin> response, Retrofit retrofit)
{
ModelLogin modelLogin=new ModelLogin();
modelLogin.getLoginResult();
if(modelLogin.equals(2))
{
Intent intent=new Intent(getApplicationContext(),Main2Activity.class);
startActivity(intent);
}
}
@Override
public void onFailure(Throwable t) {
Toast.makeText(getApplicationContext(),"Fails",Toast.LENGTH_LONG).show();
}
});
// call.enqueue(new Callback<ModelLogin>() {
// @Override
// public void onResponse(Response<ModelLogin> response, Retrofit retrofit) {
// }
// @Override
// public void onFailure(Throwable t) {
// Log.d(TAG,"Error");
// }
//});
}catch (Exception e){
throw e;
}
}
});
}
public void showAlertDialog(Context context, String title, String message, Boolean status) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(message);
// Setting alert dialog icon
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
// Showing Alert Message
alertDialog.show();
}
}
这是我的界面:
package com.example.first.servicefirst;
import retrofit.Call;
import retrofit.http.POST;
import retrofit.http.Path;
public interface RetrofitRest {
@POST("SF_UserLogin.svc/rest/login/{EMPLOYEECODE}/{PASSWORD}")
public Call<ModelLogin>getResult(@Path("EMPLOYEECODE")String empcode,@Path("PASSWORD")String passwrd);
}
我的json回复将是这样的:
{"loginResult":"{\"Result\":2,\"UserID\":0,\"ModuleID\":1,\"ModuleName\":\"CRM\"}"}
这是我的logcat:
11-09 11:17:34.670 18964-18964/com.example.first.servicefirst D/dalvikvm﹕ Late-enabling CheckJNI
11-09 11:17:34.770 18964-18964/com.example.first.servicefirst I/libthemeutils﹕ Theme: libthemeutil.so load success
11-09 11:17:34.830 18964-18964/com.example.first.servicefirst D/dalvikvm﹕ GetMethodID: not returning s tatic method Landroid/os/Process;.getTotalMemory ()J
11-09 11:17:34.830 18964-18964/com.example.first.servicefirst D/dalvikvm﹕ GetMethodID: not returning static method Landroid/os/Process;.getFreeMemory ()J
11-09 11:17:34.980 18964-18964/com.example.first.servicefirst W/Toast﹕ From com.example.first.servicefirst, go ahead.
11-09 11:17:35.070 18964-18964/com.example.first.servicefirst I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.5.2.2.2_RB1.04.04.04.154.004_msm8226_LNX.LA.3.5.2.2.2_RB1__release_AU ()
OpenGL ES Shader Compiler Version: E031.24.00.15
Build Date: 08/06/14 Wed
Local Branch: mybranch4057433
Remote Branch: quic/LNX.LA.3.5.2.2.2_rb1
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.2.2.2_RB1.04.04.04.154.004 + NOTHING
11-09 11:17:35.240 18964-18964/com.example.first.servicefirst D/OpenGLRenderer﹕ Enabling debug mode 0
11-09 11:17:35.410 18964-18964/com.example.first.servicefirst I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@424badd8 time:61392269
11-09 11:17:41.420 18964-19350/com.example.first.servicefirst W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
11-09 11:17:41.420 18964-19350/com.example.first.servicefirst W/dalvikvm﹕ VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
11-09 11:17:41.420 18964-19350/com.example.first.servicefirst I/dalvikvm﹕ Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
11-09 11:17:41.420 18964-19350/com.example.first.servicefirst W/dalvikvm﹕ VFY: unable to resolve static method 18520: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
11-09 11:17:41.420 18964-19350/com.example.first.servicefirst D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x000a
11-09 11:17:41.420 18964-19350/com.example.first.servicefirst W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
11-09 11:17:41.420 18964-19350/com.example.first.servicefirst W/dalvikvm﹕ VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
11-09 11:17:41.420 18964-19350/com.example.first.servicefirst I/dalvikvm﹕ Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
11-09 11:17:41.420 18964-19350/com.example.first.servicefirst W/dalvikvm﹕ VFY: unable to resolve static method 18519: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;
11-09 11:17:41.420 18964-19350/com.example.first.servicefirst D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x000a
答案 0 :(得分:0)
您的回复解析不正确。请查看此代码
call.enqueue(new Callback<ModelLogin>()
{
@Override
public void onResponse(Response<ModelLogin> response, Retrofit retrofit)
{
if(response.getLoginResult().getResult().equals("2")
{
Intent intent=new Intent(getApplicationContext(),Main2Activity.class);
startActivity(intent);
}
}