我有这个网络模块.我想在ErrorUtils的静态方法中注入网络模块.
@Module
public class NetworkModule {
private final String END_POINT = "https://www.myurl.com/";
@Provides
@Singleton
public OkHttpClient getOkHttpClient() {
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
}
@Provides
@Singleton
public GsonConverterFactory getGsonConverterFactory() {
return GsonConverterFactory.create();
}
@Provides
@Singleton
public Retrofit getRetrofit(OkHttpClient okHttpClient, GsonConverterFactory gsonConverterFactory) {
return new Retrofit.Builder()
.baseUrl(END_POINT)
.client(okHttpClient)
.addConverterFactory(gsonConverterFactory)
.build();
}
@Provides
@Singleton
public RetrofitService getRetrofitService(Retrofit retrofit) {
return retrofit.create(RetrofitService.class);
}
Run Code Online (Sandbox Code Playgroud)
我想在静态方法中注入此模块:
public class ErrorUtils {
@Inject
static Retrofit retrofit;
public static RestError parseError(Response<?> response) {
**//showing error while writing …
Run Code Online (Sandbox Code Playgroud) Android Studio版本3.2 beta 2和3.3 canary 2在使用时每次都会冻结.我曾尝试过以前的版本,除了很少的功能之外,它们曾经正常工作.
Android studio 3.2 canary 14没有渲染导航标签.它只是显示等待构建完成.
navigation_graph
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<fragment
android:id="@+id/fragment_nav_host"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/navigation_graph" />
</navigation>
Run Code Online (Sandbox Code Playgroud)
android android-studio android-navigation android-architecture-components android-architecture-navigation
我已按照此链接刷新访问令牌.添加Authenticator到okHttp从okTttp3获取错误的unnexpected流结束从改造回调onFailure方法
public class TokenAuthenticator implements Authenticator {
AccessTokenRefreshModel accessTokenRefreshModel = null;
@Override
public Request authenticate(Route route, Response response) throws IOException {
Call<UserLogin> call = iService.refreshAccessToken(BuildConfig.CLIENT_ID, refreshToken);
UserLogin userLogin = call.execute().body();
// Add new header to rejected request and retry it
return response.request().newBuilder()
.header(AUTHORIZATION, userLogin.getAccessToken())
.build();
}
}
Call<User> call = iService.createuser(user);
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
}
@Override
public void onFailure(Call<User> call, Throwable t) {
//**Unexpected end of …
Run Code Online (Sandbox Code Playgroud) 我正在使用JAVA EE,JAX-RS,JPA,GLASSFISH进行应用.对于MediaType.APPLICATION_XML,响应正常.它不适用于MediaType.APPLICATION_JSON.
这是我的pojo课程
@Entity
@XmlRootElement
public class Book {
private int id;
private String name;
private String publication;
private String price;
@Id
@Column(name = "id")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Basic
@Column(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Basic
@Column(name = "publication")
public String getPublication() {
return publication;
}
public void setPublication(String publication) …
Run Code Online (Sandbox Code Playgroud) 我使用viewpager来显示每月的数据.我想更改折叠工具栏的标题,以便在viewpager的页面中更改.折叠工具栏标题仅在向上滚动工具栏时更改.
我的布局
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="@dimen/activity_history_view_pager_height" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:id="@+id/my_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/activity_history_collapsing_toolbar_height"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_flexible_space"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
<TextView
android:id="@+id/txt_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_history_margin_left"
android:layout_marginStart="@dimen/activity_history_margin_left"
android:text="@string/activity_history_year"
android:textColor="@color/white"
android:textSize="@dimen/activity_history_text_size" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_history_margin_bottom"
android:orientation="vertical"
app:layout_scrollFlags="scroll">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="@dimen/activity_history_margin_right"
android:layout_marginRight="@dimen/activity_history_margin_right"
android:orientation="horizontal">
<ImageView
android:id="@+id/img_leftBackArrow"
android:layout_width="@dimen/activity_history_arrow_size"
android:layout_height="@dimen/activity_history_arrow_size"
android:contentDescription="@string/content_description"
android:src="@drawable/previous_arrow" />
<ImageView
android:id="@+id/img_rightBackArrow"
android:layout_width="@dimen/activity_history_arrow_size" …
Run Code Online (Sandbox Code Playgroud) android material-design android-design-library androiddesignsupport android-collapsingtoolbarlayout
我的应用程序中有两种产品口味,即
flavorOne(src / flavorOne / java)和flavorTwo(src / flavorTwo / java)。Main(src / main / java)是目录形式,两种风格都使用这些类。我想开始活动的src / flavorTwo / JAVA / ActivityB的.java从活动中存在的src / main / JAVA / ActivityA。在运行flavourTwo时有效,但当我切换flavourOne时,它显示导入com.packagename.ActivityB错误。
+ App // module
|- src
|- main// shared srcDir
|- java
|- SharedActivity
+ flavorOne
|- java
|- FlavorOneActivity
+ flavorTwo
|- java
|- FlavorTwoActivity
Run Code Online (Sandbox Code Playgroud)
这是dir src / main / java / SharedActivity.java中的SharedActivity.java
package com.example.buildvariants;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import …
Run Code Online (Sandbox Code Playgroud) android build build.gradle android-gradle-plugin android-productflavors
在添加导航目录时显示错误无效的资源目录.
处理命令'〜/ Android/Sdk/builds-tools/27.0.3/aapt'以退出值1结束.
的build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.crushcoder.testapp"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'android.arch.lifecycle:extensions:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Run Code Online (Sandbox Code Playgroud)
我在目录res/navigation/nav_graph.xml下创建了导航文件
android android-navigation android-architecture-components android-architecture-navigation
错误
无法实例化片段 androidx.navigation.fragment.NavHostFragment:确保类名存在,是公共的,并且有一个公共的空构造函数。
活动布局
<fragment
android:id="@+id/my_nav_host_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="androidx.navigation.fragment.NavHostFragment"
app:defaultNavHost="true"
app:navGraph="@navigation/app_nav" />
Run Code Online (Sandbox Code Playgroud)
活动
class HomeActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
}
}
Run Code Online (Sandbox Code Playgroud)
分段
class MovieListFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_movie_list, container, false)
}
}
Run Code Online (Sandbox Code Playgroud)
使用的依赖:
implementation('android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha07') {
exclude group: "com.android.support"
}
implementation('android.arch.navigation:navigation-ui-ktx:1.0.0-alpha07') {
exclude group: "com.android.support"
}
Run Code Online (Sandbox Code Playgroud) android android-architecture-components android-jetpack android-architecture-navigation
android ×6
android-architecture-components ×3
android-architecture-navigation ×3
android-collapsingtoolbarlayout ×1
build ×1
build.gradle ×1
dagger-2 ×1
glassfish ×1
java-ee-7 ×1
jax-rs ×1
okhttp3 ×1
retrofit2 ×1