中大奖啦啦噜 發表於 2022-8-22 16:50:00

Android开发

<h1 id="1知识点解析">1.知识点解析</h1>
<h2 id="11-dimen">1.1 dimen</h2>
<pre><code class="language-c++"> 1.尺寸资源;
2.在工程的res\layout\目录下创建一个test_dimen.xml布局文件。
3.在该布局文件中添加一个TextView和一个Button。
4.TextView的宽和高引用尺寸资源来设置,android:width="@dimen/text_width"
5.dimen定义:
        &lt;resources&gt;
    &lt;dimen name="drawer_profile_height"&gt;180dp&lt;/dimen&gt;
    &lt;dimen name="avatar_width"&gt;80dp&lt;/dimen&gt;
    &lt;dimen name="avatar_height"&gt;80dp&lt;/dimen&gt;
    &lt;/resource&gt;
</code></pre>
<h2 id="12-viewpager">1.2 ViewPager</h2>
<pre><code class="language-c++">参考连接:https://blog.csdn.net/harvic880925/article/details/38453725

1.ViewPager。它是google SDk中自带的一个附加包的一个类,可以用来实现屏幕间的切换。
2.代码:主布局文件中
        &lt;android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" /&gt;
3.新建三个layout,用于滑动切换的视图。
4.在java代码中将三个view添加add()到viewPager中。
        viewList = new ArrayList&lt;View&gt;();// 将要分页显示的View装入数组中
        viewList.add(view1);
        viewList.add(view2);
        viewList.add(view3);
</code></pre>
<h2 id="13-butterknife的使用">1.3 butterknife的使用</h2>
<pre><code class="language-shell">1.ButterKnife是一个专注于Android系统的View注入框架;
2.以前总是要写很多findViewById来找到View对象,有了ButterKnife可以很轻松的省去这些步骤。
3.使用ButterKnife对性能基本没有损失,因为ButterKnife用到的注解并不是在运行时反射的,而是在编译的时候生成新的class。
4.下载插件:butterknife Zelezny
5.导入依赖:
compile 'com.jakewharton:butterknife:7.0.1'
implementation ...
</code></pre>
<h2 id="14-fragment">1.4 Fragment</h2>
<pre><code class="language-shell">1.将一个Activity的界面进行碎片化,好让开发者根据不同的屏幕来进行不同的Fragment组合以来达到动态布局的效果。
2.如果采用Activity+Fragment的实现方式,则可大大降低内存的消耗
</code></pre>
<p><img src="https://img-blog.csdn.net/20161011175255612" alt="img" loading="lazy"></p>
<h2 id="15-recyclerviewadapterviewholder">1.5 RecyclerView、Adapter、ViewHolder</h2>
<pre><code class="language-shell">1.RecyclerView:用户滑动屏幕切换视图时,上一个视图会回收利用。主要任务是视图回收再利用,循环往复。
        好处:ListView只能在垂直方向上滚动,但是RecyclerView相较于ListView,在滚动上面的功能扩展了许多。它可以支持多种类型列表的展示要求。
        LinearLayoutManager,可以支持水平和竖直方向上滚动的列表。
        StaggeredGridLayoutManager,可以支持交叉网格风格的列表,类似于瀑布流或者Pinterest。
        GridLayoutManager,支持网格展示,可以水平或者竖直滚动,如展示图片的画廊。


4.LayoutManager:RecyclerView不会亲自摆放屏幕上的列表项,摆放列表项的任务被委托给了LayoutManager。主要任务是指定RecyclerView的布局方式
</code></pre>
<pre><code class="language-java">1.Adapter:主要任务是创建ViewHolder和将模型层的数据绑定到ViewHolder上。从模型层获取数据,然后提供给RecyclerView显示。
2. 方法:
   /**
   * 创建ViewHolder,将模型层的数据绑定到ViewHolder上
   */
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      return null;
    }

    /**
   * 从模型层获取数据,然后提供给RecyclerView显示
   * @param holder
   * @param position
   */
    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

    }

    /**
   * 总共有多少个Item
   * @return
   */
    @Override
    public int getItemCount() {
      return 1;
    }
*******要想使⽤ ListView,就需要编写⼀个 Adapter 将数据适配到 ListView上,⽽为了节省资源提⾼运⾏效率,⼀般⾃定义类ViewHolder 来减少 findViewById() 的使⽤以及避免过多地 inflate view,从⽽实现⽬标。

</code></pre>
<pre><code class="language-java">1.ViewHolder:主要任务是容纳View视图,加载其他view。
2.好处:在滚动期间减少对FindViewById()的调用,提高性能。
3.构造方法:
//构造方法
      public BannerViewHolder(Context mContext,View itemView,ResultBeanData resultBeanData) {
            super(itemView);
            this.mContext = mContext;
            this.banner = (Banner) itemView.findViewById(R.id.banner);

      }
</code></pre>
<h2 id="16-inflate">1.6 inflate</h2>
<pre><code class="language-java">//1.作用:将一个layout.xml布局文件变为一个View对象。尤其在ListView、GridView、RecyclerView的Adapter还有组合自定义控件中,我们都会使用inflate()方法去加载一个布局,作为每个Item的布局。
//2.使用:加载一个View布局
inflater.inflate(R.layout.layout_inflate_test,null);
inflater.inflate(R.layout.layout_inflate_test, root,false);
inflater.inflate(R.layout.layout_inflate_test, root,true);
注意:
    不要将R.layout.view写成R.id.view,二者不同!!!
</code></pre>
<h2 id="17-postdelayedremovecallbacks">1.7 <strong>postDelayed</strong>、<strong>removeCallbacks</strong></h2>
<pre><code class="language-java">1. 方法postDelayed的作用是延迟多少毫秒后开始运行。
2. 而removeCallbacks方法是删除指定的Runnable对象,使线程对象停止运行.
</code></pre>
<h2 id="18-okhttputils">1.8 OkHttpUtils</h2>
<pre><code class="language-shell">1.是什么:OkHttpUtils一个专注于让网络请求更简单的网络请求框架,对于任何形式的网络请求只需要一行代码。
2.使用:一般的
        get,post,put,delete,head,options请求
        基于Post的大文本数据上传
        多文件和多参数统一的表单上传
        支持一个key上传一个文件,也可以一个Key上传多个文件
        大文件下载和下载进度回调
        大文件上传和上传进度回调
        支持cookie的内存存储和持久化存储,支持传递自定义cookie
        支持304缓存协议,扩展四种本地缓存模式,并且支持缓存时间控制
        支持301、302重定向
        支持链式调用
        支持可信证书和自签名证书的https的访问,支持双向认证
        支持根据Tag取消请求
        支持自定义泛型Callback,自动根据泛型返回对象
</code></pre>
<h2 id="19-lombok注解">1.9 @lombok注解</h2>
<pre><code class="language-shell">1.是啥:在项目中使用Lombok可以减少很多重复代码的书写。比如说getter/setter/toString等方法的编写。
2.使用:
@Getter/@Setter: 作用类上,生成所有成员变量的getter/setter方法。

@ToString : 作用于类,覆盖默认的toString()方法 ,可以通过of属性限定显示某些字段,通过。

exclude属性排除某些字段。

@AllArgsConstructor:生成全参构造器。

@NoArgsConstructor:生成无参构造器。

@Data: 该注解使用在类上,该注解会提供 getter 、 setter 、 equals 、 hashCode 、

toString 方法。

</code></pre>
<h2 id="110-indicator_height">1.10 indicator_height</h2>
<pre><code class="language-shell">常用在平行滑动模块时:
改变下划线高度:indicator_height
改变下划线宽度:indicator_width
</code></pre>
<h2 id="111-layoutmanager">1.11 LayoutManager</h2>
<pre><code class="language-c++">1.LayoutManager是一个抽象类,有3个子类:
    LinearLayoutManager: 线性布局管理器
      GridLayoutManager: 表格布局管理器
            StaggeredGridLayoutManager: 瀑布流布局管理器
2.构造方法:
LinearLayoutManager(Context context)

LinearLayoutManager(Context context,int orientation,boolean reverseLayout)

LinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr,int defStyleRes)
   
3.属性:
Context context :上下文,初始化时,构造方法内部加载资源用

int orientation :方向,垂直(RecyclerView.VERTICAL)和水平(RecyclerView.HORIZONTA ),默认为垂直.

boolean reverseLayout:是否倒序,设置为True,从最后一个item开始,倒序加载。此时,RecyclerView第一个item是添加进Adapter中的最后一个,最后一个item是第一个加进Adapter的数据,RecyclerView会自动滑到末尾,另外item整体是依靠下方的。
</code></pre>
<h2 id="112-gradlew-compiledebugjavawithjavac">1.12 gradlew compileDebugJavaWithJavac</h2>
<pre><code>打印错误的好命令!!!
</code></pre>
<h1 id="2-遇到的问题">2. 遇到的问题</h1>
<h2 id="21-could-not-find-method-compile非换行原因">2.1 Could not find method compile()...非换行原因</h2>
<p><img alt="image-20220613162945870" loading="lazy"></p>
<h2 id="22-could-not-find-method-androidtestcompile">2.2 Could not find method androidTestCompile()</h2>
<pre><code class="language-c++">换成“androidTestImplementation”
</code></pre>
<h2 id="23-inject注解报错">2.3 @Inject注解报错</h2>
<pre><code class="language-c++">1.@Inject标注作用是依赖注入,它根据作用的对象不同分为setter方法注入、构造方法注入、字段注入,可以根据实际情况来选择。
    @Inject标注通过optional参数来定义注入的接口是否需要注入的实现类,默认情况必须显示声明注入接口的实现。
2.在项目build.gradle中导入
implementation "com.google.dagger:dagger-compiler:2.23.2"
</code></pre>
<h2 id="24-could-not-initialize-class-comandroidrepositoryapirepomanager">2.4 Could not initialize class com.android.repository.api.RepoManager</h2>
<pre><code class="language-java">1. 新的android studio(4.2)已经不支持旧有的了,有些方法和类会找不到。
去build.gradle中把这个classpath换成最新的版本。最好也把gradle和gradle wrapper的版本也弄到最新。
2.代码:
        buildscript {
    repositories {
      jcenter()
      google()
    }
    dependencies {
      classpath 'com.android.tools.build:gradle:4.2.1'

      // NOTE: Do not place your application dependencies here; they belong
      // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
      jcenter()
      google()
    }
}
</code></pre>
<h2 id="25-android-apt-plugin-is-incompatible-with-the-android-gradle-plugin">2.5 android-apt plugin is incompatible with the Android Gradle plugin.</h2>
<pre><code class="language-java">defaultConfig{

....

...

javaCompileOptions {

annotationProcessorOptions {

includeCompileClasspath true

}

}

}
</code></pre>
<h2 id="26-could-not-resolve-all-files-for-configuration-appdebugruntimeclasspath">2.6 Could not resolve all files for configuration ':app:debugRuntimeClasspath'.</h2>
<pre><code class="language-java">1. 安卓版本升级之后导致的问题;
2. 在修改Project的build.gradle(注意:不是App的build.gradle),两处加上google()代码中添加google();
buildscript {
    repositories {
      jcenter()
      google()
    }
    dependencies {
      classpath 'com.android.tools.build:gradle:3.0.0'
    }
}

allprojects {
    repositories {
      jcenter()
      google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
</code></pre>
<h2 id="27-could-not-find-method-minsdk-for-arguments-21-on-defaultconfig_">2.7 Could not find method minSdk() for arguments on DefaultConfig_</h2>
<pre><code class="language-java">将minSdk:改为自己的版本,或改为minSdkVersion:
android {
    compileSdkVersion 32
      
defaultConfig {
      applicationId "com.cheikh.lazywaimai"
      minSdkVersion 21
      targetSdkVersion 32
      versionCode 1
      versionName "1.0"
      javaCompileOptions {

            annotationProcessorOptions {

                includeCompileClasspath true

            }
      }
      testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    ...
}
</code></pre>
<h2 id="28-解决as编译报错failed-to-apply-plugin-id-comandroidapplication">2.8 解决AS编译报错:Failed to apply plugin </h2>
<pre><code class="language-shell">项目路径有中文
</code></pre>
<h2 id="29-使用butterknife之后代码没有颜色分区">2.9 使用ButterKnife之后,代码没有颜色分区</h2>
<pre><code class="language-shell">第一步:在Android Studio下载Android ButterKnife Injections (Support Kotlin)这个插件

第二步:更改插件路径

1. 插件下载后的路径是在:C:\Users\Administrator\AppData\Local\google\AndroidStudio2021.1\plugins\Android-ButterKnife-Injections.jar(APPData是隐藏文件夹,需要在“隐藏/查看”中勾选“隐藏的项目”才能够看到)

2. 路径下还有之前下载过的ButterKnife的jar文件,需要删除掉

3.将Android-ButterKnife-Injections.jar这个文件放到Android Studio的安装路径下(我是安装到D盘,所以路径是D:\Android Studio\plugins)

第三步:重启Android Studio(重启之后,之前的颜色分区就回来啦)

无用!!!!
</code></pre>
<pre><code>把下载的Butterknife插件卸载,用依赖导入
</code></pre>
<p><img alt="image-20220616163917035" loading="lazy"></p>
<h2 id="210-无法import-androidsupportv4appfragment的解决办法">2.10 无法import android.support.v4.app.Fragment的解决办法</h2>
<pre><code class="language-java">1.原因:项目使用了Androidx,support.v4.app不支持。
2.卸载butterknife插件。
3.as版本升级后,不支持support.v4...,需将依赖升级;
   如:implementation 'com.android.support:support-annotations:28.0.0'
   
因为依赖的module中也使用了继承自FragmentActivity的类,且由于依赖的module年代久远,其中依赖的 supportcompat、support 包版本较旧,怀疑可能是这个主项目与依赖module里面这些依赖包版本不一致引起的。
</code></pre>
<h2 id="211-orggradleapiinternalpluginspluginapplicationexception-failed-to-apply-plugin-id-comandroidapplication">2.11 <strong>org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin </strong></h2>
<pre><code class="language-java">1.原因:项目路径有中文。
2.解决:
    在gradle.properties文件中添加android.overridePathCheck=true就可以了。
</code></pre>
<h2 id="212-project-with-path--could-not-be-found-in-project-">2.12 Project with path ‘<em><strong>‘ could not be found in project ‘</strong></em>‘.</h2>
<pre><code class="language-shell">1.在项目中的settings.gradle中添加include语句,类似于:

include ':***'

2.这里面填的是你找不到的那个包,正常来说这个包都是会在项目中写好的,按照报错语句寻找即可;
如:
include ':app'
include ':okhttputils'
</code></pre>
<h2 id="213-android-a-failure-occurred-while-executing-comandroidbuildgradleinternaltasksworkersaction">2.13 Android A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$Action...</h2>
<pre><code class="language-shell">1、禁用构建缓存
在gradle.properties中添加了android.enableBuildCache=false 即可!
2、修改gradle版本号,我之前是3.6.1,刚开始运行的时候没问题,不知道为啥,改成3.4.0即可!
</code></pre>
<h2 id="214--could-not-find-method-android-for-arguments-on-root-project">2.14Could not find method android() for arguments on root project</h2>
<pre><code class="language-shell">1.(方法一)将根项目的build.gradle(app) 注释掉,重新Syn。

android {
//    compileOptions {
//      sourceCompatibility JavaVersion.VERSION_1_8
//      targetCompatibility JavaVersion.VERSION_1_8
//    }
//    defaultConfig {
//      targetSdk 32
//      minSdk 21
//    }
//    compileSdk 32
//}

2.(方法二)是因为app的gradle的顶部缺少这句话。
apply plugin: 'com.android.application'
</code></pre>
<h2 id="215-找不到androidsupportv4appfragmentactivity的类文件">2.15 找不到android.support.v4.app.FragmentActivity的类文件</h2>
<p><img alt="image-20220620165212753" loading="lazy"></p>
<pre><code class="language-shell">1.原因:使用的Glide 3.17.0版本太低,项目又选择了使用Androidx依赖,而此glide版本只能使用support.v4.app。。。不接受Androidx,两者冲突!
2.解决:使用glide 4.11以上版本,在build中添加依赖,
        implementation 'com.github.bumptech.glide:glide:4.13.2'
</code></pre>
<h2 id="216--android之recyclerview报错-no-adapter-attached-skipping-layout解决方法">2.16Android之recyclerview报错-No adapter attached; skipping layout解决方法</h2>
<pre><code class="language-java">没有设置LayoutManager

//设置布局管理就ok了
layoutManager=new StaggeredGridLayoutManager( 2,StaggeredGridLayoutManager.VERTICAL );
rec_xkjd.setLayoutManager( layoutManager );
rec_xkjd.setAdapter( myXKJDadapter );
</code></pre>
<h2 id="216-找不到符号-符号-方法-crossfade-位置-类-requestbuilder">2.16 找不到符号 符号: 方法 crossFade() 位置: 类 RequestBuilder<drawable></drawable></h2>
<pre><code class="language-shell">1.原因:Glide版本升级后,适应了Androidx,但是有一些方法改变了。
2.错误:
        Glide.with(context).load(url).crossFade().into(iv);//crossFade()方法会报错
        Glide.with(context).load(url).crossFade().placeholder(defaultImage).into(iv);
3.纠正:
        Glide.with(context).load(url).transition(withCrossFade()).into(iv);
                Glide.with(context).load(url).transition(withCrossFade()).placeholder(defaultImage).into(iv);
</code></pre>
<h2 id="217-每次运行meta_inf里面老是多出两个错的jar包">2.17 每次运行META_INF里面老是多出两个错的jar包</h2>
<pre><code class="language-shell">   在build里面的Android{}里面加:
   packagingOptions {
      exclude 'META-INF/DEPENDENCIES'
      exclude 'META-INF/NOTICE'
      exclude 'META-INF/LICENSE'
      exclude 'META-INF/LICENSE.txt'
      exclude 'META-INF/NOTICE.txt'
    }
</code></pre>
<h2 id="218-安卓-联网失败failed-to-connect-to-1921681331-port-9090-from-103020938">2.18 安卓 联网失败failed to connect to /192.168.133.1 (port 9090) from /10.30.209.38</h2>
<pre><code class="language-shell">该错误的产生原因:
1.服务端程序运行的电脑防火墙未关闭
2.客户端和服务器端程序运行在同一网络环境下
3.模拟器原因
4.客户端IP设置问题 (当时是再局域网下,但是客户端IP地址没有写局域网的IP地址)

解决方法:
1.确保客户端和服务器运行在同一WIFI下
2.查看IP是否填写错误,注意Android端的IP不能填写localhost或127.0.0.1,需要通过命令提示符—命令ipconfig查看主机使用的局域网ip地址!!!!!!
3.确认服务端防火墙处于关闭状态,如果没有可以通过控制面板关闭防火墙
4.更换模拟器,如果你使用的是Android studio的模拟器,那么你可以使用手机运行程序获取新建一个模拟器,我遇到的情况就是模拟器导致的问题。
</code></pre>
<h2 id="219--you-should-include-an-annotationprocessor-compile-dependency-on-comgithubbumptechglidecompiler-in-your-application-and-a-glidemodule-annot">2.19You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annot....</h2>
<pre><code>添加compiler:
</code></pre>
<p><img alt="image-20220621112025490" loading="lazy"></p>
<h3 id="220-type-androidxcoordinatorlayoutrattr-is-defined-multiple-times">2.20 Type androidx.coordinatorlayout.R$attr is defined multiple times</h3>
<pre><code>R$attr定义多次
clean一下项目即可
</code></pre>
<h1 id="3-标签使用">3. 标签使用</h1>
<h2 id="31-居中">3.1 居中</h2>
<h3 id="311-linearlayout">3.1.1 Linearlayout</h3>
<pre><code class="language-java">&lt;LinearLayout
// 下面gravity属性的参数:center为居中,center_horizontal为水平居中,center_vertical为垂直居中 删除其他的就能得到自己想要的
    android:gravity="center|center_horizontal|center_vertical" &gt;
</code></pre>
<h3 id="312-imageview">3.1.2 ImageView</h3>
<pre><code class="language-java">//前提是要放在Relativelayout或Linearlayout中
android:layout_centerVertical="true"
</code></pre>
<h2 id="32-layout_alignparent">3.2 layout_al@ignParent...</h2>
<pre><code class="language-java">align:对齐
parent:容器

layout_alignParentBottom="true"//容器中底部
layout_alignParentLeft="true"//容器中居左
layout_alignParentRight="true" //容器中居右
</code></pre>
<h2 id="33-gradient">3.3 gradient</h2>
<pre><code class="language-java">实现三色渐变
    &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;shape xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    &lt;corners android:radius="20dp"/&gt;
    &lt;gradient
      android:startColor="#FF5C13"
      android:endColor="#FC7D0B"
      android:angle="90" /&gt;
&lt;/shape&gt;
</code></pre>
<h1 id="4-经典代码">4. 经典代码</h1>
<h2 id="41-欢迎页面延迟2秒进入主页面">4.1 欢迎页面延迟2秒进入主页面</h2>
<pre><code class="language-java">//2秒钟进入主页面
      new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                //在主线程中执行,启动主页面
                startActivity(new Intent(Welcome.this,MainActivity.class));
                //关闭欢迎页面
                finish();
            }
      },2000);
</code></pre>
<h1 id="5-xml布局标签">5. xml布局标签</h1>
<h2 id="51-include">5.1 include</h2>
<pre><code class="language-java">1.把一个XML布局引入进来当做自己的布局,跟直接把引用的这段代码写在include处的效果是一样的。
2.使用:
        &lt;include
      android:id="@+id/titlebar"
      layout="@layout/titlebar" /&gt;
</code></pre>
<h1 id="6-as--svn">6. AS + SVN</h1>
<h2 id="61-安卓提交代码">6.1 安卓提交代码</h2>
<pre><code class="language-shell">Android Studio是用gradle来构建项目的,有很多环境方面的文件都不需要增加到SVN版本库。
以下为列出不需要增加到版本库的文件:

1. .idea 文件夹,此文件夹是用来保存开发工具的设置信息。

2..gradle 文件夹,此文件夹是用来保存gradle的依赖信息。

3.所有的 build 文件夹,build文件夹是用来保存编译后的文件目录。

4.所有的 .iml 文件,是用来保存开发工具信息。

5. local.properties 文件,是用来保存项目依赖信息。
</code></pre>
<h2 id="62-局域网内其他主机无法ping通对方主机">6.2 局域网内其他主机无法ping通对方主机</h2>
<pre><code class="language-shell">1.主机地址错误:查看主机地址是否错误,局域网的就写局域网地址!!!!!
2.防火墙没有打开!!
3.对固定端口没有开放!!:https://blog.csdn.net/t18438605018/article/details/108812631
</code></pre>
<p><img alt="image-20220618170005110" loading="lazy"></p>
<h2 id="63-局域网内对方无法checkout本地的svn仓库">6.3 局域网内对方无法checkout本地的SVN仓库</h2>
<pre><code>查看主机地址是否错误,局域网的就写局域网地址!!!!!不是以太网适配器
</code></pre>
<h1 id="7-java异常">7. JAVA异常</h1>
<h2 id="71--javalangillegalargumentexception-cannot-set-scalex-to-floatnan">7.1java.lang.IllegalArgumentException: Cannot set 'scaleX' to Float.NaN</h2>
<pre><code>不合法的参数异常:
因为传递了一个错误的参数。
</code></pre>
<h2 id="72-解决javalangnullpointerexception-attempt-to-read-from-field-int-androidviewviewmviewflags-on-a-null">7.2 解决java.lang.NullPointerException Attempt to read from field 'int android.view.View.mViewFlags' on a null...</h2>
<pre><code class="language-shell">1.异常:异常的解释是"程序 遇上了空指针",简单地说就是调用了未经初始化的对象或者是不存在的对象,这个错误经常出现在创建图片,调用数组这些操作中,比如图片 未经初始化,或者图片创建时的路径错误等等。
2.解决:Debug后发现position多个值时后返回null。
</code></pre>
<p><img alt="image-20220621115932683" loading="lazy"></p>
<h1 id="8-后台管理开发">8. 后台管理开发</h1>
<h2 id="81-遇到的问题">8.1 遇到的问题</h2>
<h3 id="811-managementforshoppingoutartifactsshopping-not-found-for-the-web-module">8.1.1 \ManagementForShopping\out\artifacts\shopping not found for the web module.</h3>
<p>war包没有正确</p>
<p><img alt="image-20220624211240568" loading="lazy"><img alt="image-20220624211253353" loading="lazy"></p>
<h3 id="812-springboot-连接数据库access-denied-for-user-rootlocalhost">8.1.2 Springboot 连接数据库Access denied for user 'root'@'localhost'</h3>
<pre><code class="language-shell">输入命令

在application.yml文件中:
spring:
datasource:
       url: jdbc:mysql://120.25.153.197:3306/pick
       username: root
       password: 6669
       driver-class-name: com.mysql.jdbc.Driver
       type: com.alibaba.druid.pool.DruidDataSource
      
cd mysql5.5/bin
D:\MySQL Server 5.5\bin&gt;mysqld --skip-grant-tables
D:\MySQL Server 5.5\bin&gt;mysql -u root -p 6669
执行“use mysql;”,使用mysql数据库。
执行“update user set password=PASSWORD("123456") where user='root';”(修改root的密码)
</code></pre>
<h3 id="813-idea创建mapperxml文件新建中没有mapper文件选项">8.1.3 IDEA创建Mapper.xml文件(新建中没有mapper文件选项)</h3>
<p><img alt="image-20220625160732120" loading="lazy"></p>
<h3 id="814--no-qualifying-bean-of-type-comxiaojianpickservicehomeservice-available-expected-at-least-1-bean-which-qualifies-as-autowire-candidate-dependency-annotations">8.1.4No qualifying bean of type 'com.xiaojian.pick.service.HomeService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:</h3>
<pre><code>原因:找不到合法的bean,在接口实现类中没有写@Service,在Controller中没有写@Controller,表名写错了。
</code></pre>
<h3 id="815-there-is-no-getter-for-property-named-type-in-class-javalangstring-with-root-cause">8.1.5 There is no getter for property named 'type' in 'class java.lang.String'] with root cause</h3>
<pre><code>#写成 $
</code></pre>
<p><img alt="image-20220627110207589" loading="lazy"></p>
<h2 id="82-安卓前端如何与后端联系">8.2 安卓前端如何与后端联系</h2>
<h2 id="83-springboot注解">8.3 SpringBoot注解</h2>
<h2 id="84-知识解析">8.4 知识解析</h2>
<h2 id="85-常用工具">8.5 常用工具</h2>
<h3 id="851-lombok插件">8.5.1 Lombok插件</h3>
<pre><code class="language-java">用途:
    使用注解@Data可直接使用实体对象的getter和setter方法等,不需要再实体中定义很多的代码,如下。

@Data
public class Mountain{
    private String name;
    private double longitude;
    private String country;
}

Maven添加依赖:
    &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
      &lt;artifactId&gt;lombok&lt;/artifactId&gt;
      &lt;version&gt;1.16.10&lt;/version&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;
</code></pre>
<h1 id="0-项目解析">0. 项目解析</h1>
<h2 id="01-框架">0.1 框架</h2>
<h3 id="011-前端安卓">0.1.1 前端(安卓)</h3>
<pre><code class="language-java">主体:FrameLayout帧布局,可以将将fragment添加到这个帧布局。

底部导航栏:RadioGroup,每个按钮对应一个Fragment,将每个fragmnet装入数组中,根据目前pos的值获取到数组中的fragment,然后将其添加到帧布局中。
</code></pre>
<h3 id="012-后台">0.1.2 后台</h3>
<pre><code class="language-java">(1)框架:SpringBoot、Mybatis、Redis
(2)数据库:mysql
(3)图片路径:阿里云Oss
</code></pre>
<h2 id="02-主页">0.2 主页:</h2>
<h3 id="021-布局">0.2.1 布局</h3>
<p>两个部分组成:顶部搜索栏、RecycleView、ViewHolder</p>
<p>1.为什么要使用recycleView?</p>
<pre><code class="language-java">(1)使用recycleView,可以继承适配器,然后适配器中有CreateView()方法,用来创建每一个ViewHolder。
(2)OnBindView方法绑定数据,给每个ViewHolder视图设置数据。
</code></pre>
<p>2.为什么要使用ViewHolder?</p>
<pre><code class="language-java">ViewHolder通常出现在适配器里,为的是listview滚动的时候快速设置值,而不必每次都重新创建很多对象,从而提升性能。
</code></pre>
<h3 id="022-功能">0.2.2 功能</h3>
<p>1.搜索</p>
<pre><code class="language-java">传参数到后台
</code></pre>
<p>2.轮播图</p>
<pre><code class="language-java">(1)使用Banner依赖包;
(2) 图片加载器Glide依赖包;
(3)点击事件,跳转到详情页面;
</code></pre>
<p>3.选择按钮</p>
<pre><code class="language-java">根据pos的值,传到intent,跳转到相应的列表
</code></pre>
<p>4.购物车</p>
<pre><code class="language-java">将详情页面的商品信息先添加到集合datas中,然后将datas添加到本地缓存(SharedPreferences)。
购物车显示:从本地缓存中直接获取,将Json数据转化为对象。
</code></pre>
<pre><code class="language-shell">1.在主页Fragment中初始化数据,使用第三方库OkHttpUtils通过自定义HOME_URL获取数据;
2.获取后执行OkHttpUtils的回调函数,再将获取的数据传到adapter;
3.利用adapter创建ViewHolder、将数据绑定到ViewHolder、并显示数据在ViewHolder上;
4.主页是一个RecycleView,其中有很多的ViewHolder,如BannerViewHolder继承RecycleView.ViewHolder
</code></pre>
<h2 id="03-发现">0.3 发现:</h2>
<h3 id="031-布局">0.3.1 布局</h3>
<p>Tablayout、ViewPager</p>
<h3 id="032-功能">0.3.2 功能</h3>
<h2 id="04-购物车">0.4 购物车</h2>
<h3 id="041-布局">0.4.1 布局</h3>
<p>RecycleView、</p>
<h3 id="042-功能">0.4.2 功能</h3>
<h2 id="05-个人中心">0.5 个人中心</h2>
<h3 id="051-布局">0.5.1 布局</h3>
<h3 id="052-功能">0.5.2 功能</h3>
<p>Android商城项目链接:<br>
Gitee:https://toscode.gitee.com/whude/shopping<br>
Github:https://github.com/summerCndidnufihd/shoppingForAndroid<br>
欢迎star!!!</p><br><br>
来源:https://www.cnblogs.com/lxpblogs/p/16613397.html
頁: [1]
查看完整版本: Android开发