- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 Android studio 中使用 Retrofit 库在 http 请求中与 Web 服务器进行通信。在我的一个请求中,我向服务器发送了一个发布请求。在这一行中:
Call<UploadRoomResponse> call = service.UploadRoom("Bearer " + token, new UploadRoomRequest(new Vector<String>() , angels, RoomName));
这被抛出:
throw new IllegalStateException("Could not execute method for android:onClick", e);
这是我的 IService 接口(interface):
public interface IService
{
@POST("api/users/login")
Call<LoginResponse> Login(@Body LoginRequest loginRequest);
@POST("api/users/signup")
Call<SignupResponse> Signup(@Body SignupRequest signupRequest);
@GET("api/users/rooms")
Call<GetRoomsResponse> GetRooms(@Header("Authorization") String token);
@POST("api/rooms")
Call<UploadRoomResponse> UploadRoom(@Header("Authorization") String token, UploadRoomRequest uploadRoomRequest);
}
这是我的响应和请求类:
public class UploadRoomResponse extends BaseResponse
{
private int roomId;
public UploadRoomResponse(String message, int roomId)
{
super(message);
this.roomId = roomId;
}
public int GetRoomId()
{
return roomId;
}
}
public class UploadRoomRequest
{
private List<String> files;
private List<Float> angles;
private String roomName;
public UploadRoomRequest(List<String> files, List<Float> angles, String roomName)
{
this.files = files;
this.angles = angles;
this.roomName = roomName;
}
public List<String> GetFiles()
{
return files;
}
public List<Float> GetAngles()
{
return angles;
}
public String GetRoomName()
{
return roomName;
}
}
演示者功能:
private void communicateUploadRoom(String token, String url)
{
Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).build();
IService service = retrofit.create(IService.class);
List<Float> angels = new Vector<Float>();
//adding all the angles of the images to the request
for(int i = 0; i < 2; i++)
{
angels.add(90 - Images.get(i).GetPitch());
}
angels.add(Math.abs(Images.get(2).GetPitch()));
Call<UploadRoomResponse> call = service.UploadRoom("Bearer " + token, new UploadRoomRequest(new Vector<String>() , angels, RoomName));
call.enqueue(new Callback<UploadRoomResponse>() {
@Override
public void onResponse(Call<UploadRoomResponse> call, Response<UploadRoomResponse> response)
{
UploadRoomResponse uploadRoomResponse = response.body();
if(uploadRoomResponse != null && uploadRoomResponse.GetMessage() == null)
{
ClearSteps();
View.ToastUpload("Room Uploaded");
}
else
{
View.ToastUpload(uploadRoomResponse.GetMessage());
}
}
@Override
public void onFailure(Call<UploadRoomResponse> call, Throwable t) {
}
});
}
堆栈跟踪:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: c.www.roomodel, PID: 1299
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6614)
at android.view.View.performClickInternal(View.java:6591)
at android.view.View.access$3100(View.java:786)
at android.view.View$PerformClick.run(View.java:25948)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6806)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6614)
at android.view.View.performClickInternal(View.java:6591)
at android.view.View.access$3100(View.java:786)
at android.view.View$PerformClick.run(View.java:25948)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6806)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #2)
for method IService.UploadRoom
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:720)
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:711)
at retrofit2.ServiceMethod$Builder.parameterError(ServiceMethod.java:729)
at retrofit2.ServiceMethod$Builder.parseParameter(ServiceMethod.java:348)
at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:202)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)
at retrofit2.Retrofit$1.invoke(Retrofit.java:145)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy0.UploadRoom(Unknown Source)
at c.www.roomodel.app.Activities.UploadRoom.UploadRoomPresenter.communicateUploadRoom(UploadRoomPresenter.java:170)
Activity 代码:
package c.www.roomodel.app.Activities.UploadRoom;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import c.www.roomodel.R;
import c.www.roomodel.app.Activities.Camera.CameraActivity;
import c.www.roomodel.app.Activities.Info.InfoActivity;
import c.www.roomodel.app.Activities.Options.OptionsActivity;
import c.www.roomodel.app.Models.GlobalUser;
import c.www.roomodel.app.Models.Image;
import c.www.roomodel.app.Models.UploadStep;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.LayoutDirection;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
import java.util.List;
import java.util.Vector;
import static java.security.AccessController.getContext;
public class UploadRoomActivity extends AppCompatActivity implements UploadRoomView{
public LinearLayout mainLayout;
public UploadRoomPresenter Presenter;
public Button uploadButton;
public Button clearButton;
public EditText RoomName;
//list of V icons of steps
public List<ImageView> Vs;
private static final int MY_CAMERA_REQUEST_CODE = 100;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload_room);
RoomName = (EditText)findViewById(R.id.RoomName);
addNameListener();
uploadButton = (Button)findViewById(R.id.upload_button);
clearButton = (Button)findViewById(R.id.clear_button);
Vs = new Vector<ImageView>();
if (checkSelfPermission(Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CAMERA},
MY_CAMERA_REQUEST_CODE);
}
mainLayout = (LinearLayout)findViewById(R.id.main_layout);
Presenter = new UploadRoomPresenter(this);
ChangeRoomName(Presenter.GetRoomName());
Bundle b = getIntent().getExtras();
if(b != null)
{
Presenter.SetImage(b.getInt("id"), new Image(b.getByteArray("data"), b.getFloat("pitch")));
}
Presenter.CheckAvailableImages();
}
//This function creates a button dynamically of a step
//it gets parameters:
//right - is the step positioned right
//background - background image of button
//(This function doesn't define a button click event)
private Button CreateStepButton(Boolean right, int background)
{
Button button = new Button(getApplicationContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.info_camera_height), getResources().getDimensionPixelSize(R.dimen.info_camera_height));
button.setBackgroundResource(background);
params.gravity = Gravity.CENTER_VERTICAL;
//if linear layout is positioned right
if(right)
{
params.leftMargin = getResources().getDimensionPixelSize(R.dimen.step_button_margin);
}
else
{
params.rightMargin = getResources().getDimensionPixelSize(R.dimen.step_button_margin);
}
button.setLayoutParams(params);
return button;
}
//This function creates a linear layout dynamically of a step
//it gets parameters:
//right - is the step positioned right
private LinearLayout CreateLinearLayout(Boolean right)
{
LinearLayout linearLayout = new LinearLayout(getApplicationContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.step_width), getResources().getDimensionPixelSize(R.dimen.step_height));
linearLayout.setBackgroundResource(R.drawable.step_layout);
if(right)
{
params.rightMargin = getResources().getDimensionPixelSize(R.dimen.step_margin);
params.gravity = Gravity.RIGHT;
linearLayout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
else
{
params.leftMargin = getResources().getDimensionPixelSize(R.dimen.step_margin);
params.gravity = Gravity.LEFT;
linearLayout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
params.topMargin = getResources().getDimensionPixelSize(R.dimen.step_top_margin);
linearLayout.setLayoutParams(params);
return linearLayout;
}
private TextView CreateText(Boolean right, String text)
{
TextView textView = new TextView(getApplicationContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
textView.setGravity(Gravity.CENTER);
textView.setTextColor(getResources().getColor(R.color.black));
textView.setTypeface(Typeface.create("sans-serif-black", Typeface.NORMAL));
textView.setText(text);
textView.setLayoutParams(params);
return textView;
}
private ImageView CreateVIcon(boolean right)
{
ImageView v = new ImageView(getApplicationContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.info_camera_height), getResources().getDimensionPixelSize(R.dimen.info_camera_height));
v.setImageResource(R.drawable.v);
params.gravity = Gravity.CENTER_VERTICAL;
//if linear layout is positioned right
if(right)
{
params.leftMargin = getResources().getDimensionPixelSize(R.dimen.step_button_margin);
}
else
{
params.rightMargin = getResources().getDimensionPixelSize(R.dimen.step_button_margin);
}
v.setLayoutParams(params);
return v;
}
public void CreateStep(Boolean right, UploadStep step, int id)
{
LinearLayout linearLayout = CreateLinearLayout(right);
linearLayout.setId(id);
ImageView v = CreateVIcon(right);
v.setAlpha(0);
Vs.add(v);
Button cameraButton = CreateStepButton(right, R.drawable.camera_button);
Button infoButton = CreateStepButton(right, R.drawable.info_button);
TextView textView = CreateText(right, step.GetTitle());
cameraButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent takePictureIntent = new Intent(UploadRoomActivity.this, CameraActivity.class);
Bundle b = new Bundle();
b.putInt("id", ((View)v.getParent()).getId());
takePictureIntent.putExtras(b);
startActivity(takePictureIntent);
finish();
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, ((View)v.getParent()).getId());
}
}
});
infoButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Presenter.ChangeRoomName(RoomName.getText().toString());
Intent intent = new Intent(UploadRoomActivity.this, InfoActivity.class);
Bundle b = new Bundle();
UploadStep step = Presenter.GetStep(((View)v.getParent()).getId());
b.putInt("image", step.GetImage());
b.putInt("info", step.GetInfo());
b.putString("title", step.GetTitle());
intent.putExtras(b);
startActivity(intent);
finish();
}
});
linearLayout.addView(v);
linearLayout.addView(cameraButton);
linearLayout.addView(infoButton);
linearLayout.addView(textView);
mainLayout.addView(linearLayout);
}
@Override
public void CheckStep(int id)
{
Vs.get(id).setAlpha(255);
}
public void changeToOptions(View view)
{
startActivity(new Intent(UploadRoomActivity.this, OptionsActivity.class));
finish();
}
@Override
public void enableButton(boolean enable)
{
uploadButton.setEnabled(enable);
if(enable)
{
uploadButton.setBackgroundColor(getResources().getColor(R.color.enabledButton));
}
else
{
uploadButton.setBackgroundColor(getResources().getColor(R.color.disabledButton));
}
}
@Override
public void InvisibleV()
{
for(int i = 0; i < Vs.size(); i++)
{
Vs.get(i).setAlpha(0);
}
}
//This function is an 'on click' function for the clear button
//clears all images and V's
//clears all images and V's
public void ClearClick(View v)
{
Presenter.ClearSteps();
}
//This function is an 'on click' function for the upload button
//Uploads the images
public void UploadClick(View v)
{
Presenter.TryUploadRoom(GlobalUser.User.GetToken(), getResources().getString(R.string.baseUrl));
}
@Override
public void ClearRoomName()
{
RoomName.setText("");
}
private void addNameListener()
{
RoomName.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s)
{
Presenter.ChangeRoomName(RoomName.getText().toString());
Presenter.canEnableUpload(RoomName.getText().toString());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
}
@Override
public void ChangeRoomName(String name)
{
RoomName.setText(name);
}
@Override
public void ToastUpload(String s)
{
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();
}
}
抛出异常的原因可能是什么?
谢谢。
最佳答案
这是根本错误:
Caused by: java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #2)
for method IService.UploadRoom
这是引用的方法:
@POST("api/rooms")
Call<UploadRoomResponse> UploadRoom(@Header("Authorization") String token, UploadRoomRequest uploadRoomRequest);
也许您忘记了 UploadRoomRequest
参数的 @Body
?
关于java - Android Studio - 使用 Retrofit 时出现 IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60581305/
我最近在/ drawable中添加了一些.gifs,以便可以将它们与按钮一起使用。这个工作正常(没有错误)。现在,当我重建/运行我的应用程序时,出现以下错误: Error: Gradle: Execu
Android 中有返回内部存储数据路径的方法吗? 我有 2 部 Android 智能手机(Samsung s2 和 s7 edge),我在其中安装了一个应用程序。我想使用位于这条路径中的 sqlit
这个问题在这里已经有了答案: What's the difference between "?android:" and "@android:" in an android layout xml f
我只想知道 android 开发手机、android 普通手机和 android root 手机之间的实际区别。 我们不能从实体店或除 android marketplace 以外的其他地方购买开发手
自Gradle更新以来,我正在努力使这个项目达到标准。这是一个团队项目,它使用的是android-apt插件。我已经进行了必要的语法更改(编译->实现和apt->注释处理器),但是编译器仍在告诉我存在
我是android和kotlin的新手,所以请原谅要解决的一个非常简单的问题! 我已经使用导航体系结构组件创建了一个基本应用程序,使用了底部的导航栏和三个导航选项。每个导航选项都指向一个专用片段,该片
我目前正在使用 Facebook official SDK for Android . 我现在正在使用高级示例应用程序,但我不知道如何让它获取应用程序墙/流/状态而不是登录的用户。 这可能吗?在那种情
我在下载文件时遇到问题, 我可以在模拟器中下载文件,但无法在手机上使用。我已经定义了上网和写入 SD 卡的权限。 我在服务器上有一个 doc 文件,如果用户单击下载。它下载文件。这在模拟器中工作正常但
这个问题在这里已经有了答案: What is the difference between gravity and layout_gravity in Android? (22 个答案) 关闭 9
任何人都可以告诉我什么是 android 缓存和应用程序缓存,因为当我们谈论缓存清理应用程序时,它的作用是,缓存清理概念是清理应用程序缓存还是像内存管理一样主存储、RAM、缓存是不同的并且据我所知,缓
假设应用程序 Foo 和 Eggs 在同一台 Android 设备上。任一应用程序都可以获取设备上所有应用程序的列表。一个应用程序是否有可能知道另一个应用程序是否已经运行以及运行了多长时间? 最佳答案
我有点困惑,我只看到了从 android 到 pc 或者从 android 到 pc 的例子。我需要制作一个从两部手机 (android) 连接的 android 应用程序进行视频聊天。我在想,我知道
用于使用 Android 以编程方式锁定屏幕。我从 Stackoverflow 之前关于此的问题中得到了一些好主意,并且我做得很好,但是当我运行该代码时,没有异常和错误。而且,屏幕没有锁定。请在这段代
文档说: android:layout_alignParentStart If true, makes the start edge of this view match the start edge
我不知道这两个属性和高度之间的区别。 以一个TextView为例,如果我将它的layout_width设置为wrap_content,并将它的width设置为50 dip,会发生什么情况? 最佳答案
这两个属性有什么关系?如果我有 android:noHistory="true",那么有 android:finishOnTaskLaunch="true" 有什么意义吗? 最佳答案 假设您的应用中有
我是新手,正在尝试理解以下 XML 代码: 查看 developer.android.com 上的文档,它说“starStyle”是 R.attr 中的常量, public static final
在下面的代码中,为什么当我设置时单选按钮的外观会发生变化 android:layout_width="fill_parent" 和 android:width="fill_parent" 我说的是
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
假设我有一个函数 fun myFunction(name:String, email:String){},当我调用这个函数时 myFunction('Ali', 'ali@test.com ') 如何
我是一名优秀的程序员,十分优秀!