问题①

我在另外一个项目里写了一个注册和登录功能的几个文件,当我想把这些代码和另一个文件合起来的时候就出现了问题。

首先不可以直接把另外一个项目的某个文件直接复制过来,

最好的办法是重新新建一个相同名字的文件,然后去另一个文件里复制代码(除了包名不要复制,其他都可以)。

然后所有的activity文件都要在AndroidManifest文件里面注册

 1 <application
2 android:allowBackup="true"
3 android:icon="@mipmap/ic_launcher"
4 android:label="@string/app_name"
5 android:roundIcon="@mipmap/ic_launcher_round"
6 android:supportsRtl="true"
7 android:theme="@style/Theme.HelloWorld">
8 <meta-data
9 android:name="com.baidu.lbsapi.API_KEY"
10 android:value="SmUC55wktbFHpYaLz7DLNeOdy4ScE5qH">
11 </meta-data>
12 <service
13 android:name="com.baidu.location.f"
14 android:enabled="true"
15 android:process=":remote">
16 </service>
17
18 <activity android:name=".MainActivity">
19 </activity>
20 <activity android:name=".SecondActivity"></activity>

21    <activity android:name=".loginActivity">
22 <intent-filter>
23 <action android:name="android.intent.action.MAIN" />
24
25 <category android:name="android.intent.category.LAUNCHER" />
26 </intent-filter>
27 </activity>
<!--
  这一部分代码 <intent-fillter> 标签里面的部分就是说当这个软件开始运行的时候,哪一个activity是最先被运行的,
  这一段在哪个activity里面被注册就是哪个最先运行。
-->

28 <activity android:name=".RegisterActivity"></activity>
29 </application>

问题② 数据库帮助类的使用

  1 package com.example.helloworld;
2
3 import android.content.Context;
4 import android.database.Cursor;
5 import android.database.sqlite.SQLiteDatabase;
6 import android.database.sqlite.SQLiteOpenHelper;
7 import android.util.Log;
8
9 import java.util.ArrayList;
10
11 public class DBOpenHelper extends SQLiteOpenHelper {
12 /**
13 * 声明一个AndroidSDK自带的数据库变量db
14 */
15 private SQLiteDatabase db;
16
17 /**
18 * 写一个这个类的构造函数,参数为上下文context,所谓上下文就是这个类所在包的路径
19 * 指明上下文,数据库名,工厂默认空值,版本号默认从1开始
20 * super(context,"db_test",null,1);
21 * 把数据库设置成可写入状态,除非内存已满,那时候会自动设置为只读模式
22 * 不过,以现如今的内存容量,估计一辈子也见不到几次内存占满的状态
23 * db = getReadableDatabase();
24 */
25 public DBOpenHelper(Context context){
26 super(context,"db_test",null,1);
27 db = getReadableDatabase();
28 }
29
30 /**
31 * 重写两个必须要重写的方法,因为class DBOpenHelper extends SQLiteOpenHelper
32 * 而这两个方法是 abstract 类 SQLiteOpenHelper 中声明的 abstract 方法
33 * 所以必须在子类 DBOpenHelper 中重写 abstract 方法
34 * 想想也是,为啥规定这么死必须重写?
35 * 因为,一个数据库表,首先是要被创建的,然后免不了是要进行增删改操作的
36 * 所以就有onCreate()、onUpgrade()两个方法
37 * @param db
38 */
39 @Override
40 public void onCreate(SQLiteDatabase db){
41 db.execSQL("CREATE TABLE IF NOT EXISTS user(" +
42 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
43 "username TEXT," +
44 "userid TEXT,"+
45 "userphone TEXT,"+
46 "useraddress TEXT)"
47 );
48 }
49 @Override
50 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
51 db.execSQL("DROP TABLE IF EXISTS user");
52 onCreate(db);
53 }
54 /**
55 * 接下来写自定义的增删改查方法
56 * 这些方法,写在这里归写在这里,以后不一定都用
57 * add()
58 * delete()
59 * update()
60 * getAllData()
61 */
62 public void add(String username,String userid,String userphone,String useraddress){
63 db.execSQL("INSERT INTO user (username,userid,userphone,useraddress) VALUES(?,?,?,?)",new Object[]{username,userid,userphone,useraddress});
64 }
65 public void delete(String userphone){
66 db.execSQL("DELETE FROM user WHERE userphone = "+userphone);
67 }
68 public void updata(String userphone){
69 db.execSQL("UPDATE user SET userphone = ?",new Object[]{userphone});
70 }
71
72 /**
73 * 前三个没啥说的,都是一套的看懂一个其他的都能懂了
74 * 下面重点说一下查询表user全部内容的方法
75 * 我们查询出来的内容,需要有个容器存放,以供使用,
76 * 所以定义了一个ArrayList类的list
77 * 有了容器,接下来就该从表中查询数据了,
78 * 这里使用游标Cursor,这就是数据库的功底了,
79 * 在Android中我就不细说了,因为我数据库功底也不是很厚,
80 * 但我知道,如果需要用Cursor的话,第一个参数:"表名",中间5个:null,
81 * 最后是查询出来内容的排序方式:"name DESC"
82 * 游标定义好了,接下来写一个while循环,让游标从表头游到表尾
83 * 在游的过程中把游出来的数据存放到list容器中
84 * @return
85 */
86 public ArrayList<User> getAllData(){
87
88 ArrayList<User> list = new ArrayList<User>();
89 Cursor cursor = db.query("user",null,null,null,null,null,"username DESC");
90 while(cursor.moveToNext()){
91 String username = cursor.getString(cursor.getColumnIndex("username"));
92 String userid = cursor.getString(cursor.getColumnIndex("userid"));
93 String userphone = cursor.getString(cursor.getColumnIndex("userphone"));
94 String useraddress = cursor.getString(cursor.getColumnIndex("useraddress"));
95 list.add(new User(username,userid,userphone,useraddress));
96 }
97 Log.v("输出数据库查询结果:",list.toString());
98 return list;
99 }
100 }

添加public void add(String username,String userid,String userphone,String useraddress){

    db.execSQL("INSERT INTO user (username,userid,userphone,useraddress) VALUES(?,?,?,?)"
  ,new Object[]{username,userid,userphone,useraddress});
}
查询方法
public ArrayList<User> getAllData() ArrayList<User> list = new ArrayList<User>(); Cursor cursor = db.query("user",null,null,null,null,null,"username DESC" while(cursor.moveToNext()){ String username = cursor.getString(cursor.getColumnIndex("username"));
        String userid = cursor.getString(cursor.getColumnIndex("userid"));
String userphone = cursor.getString(cursor.getColumnIndex("userphone"));
String useraddress = cursor.getString(cursor.getColumnIndex("useraddress"));
list.add(new User(username,userid,userphone,useraddress));
}
Log.v("输出数据库查询结果:",list.toString());
return list;
}
1、close()  关闭游标,释放资源
2、getColumnCount()返回所有列的总数
3、getColumnIndexOrThrow(String columnName)
  从零开始返回指定列名称,如果不存在将抛出IllegalArgumentException 异常。
4、moveToNext()    
  移动光标到下一行
5、moveToFirst()
  移动光标到第一行
6、moveToPosition(int position)
移动光标到一个绝对的位置
7、moveToPrevious() 移动光标到上一行

数据库构造函数
public DBOpenHelper(Context context){
super(context,"db_test",null,1);
db = getReadableDatabase();
}

onCreate()方法

public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE IF NOT EXISTS user(" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
"username TEXT," +
"userid TEXT,"+
"userphone TEXT,"+
"useraddress TEXT)"
);
}
注意不要丢掉_id 主键
每一段定义后面都有一个英文的逗号、

③实现页面跳转

Intent intent2 = new Intent(this, MainActivity.class);
startActivity(intent2);
自动获取时间

public void autoTimeAndDate(View view)
{
text2=(EditText)findViewById(R.id.tv_text2);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// HH:mm:ss
//获取当前时间
Date date = new Date(System.currentTimeMillis());
text2.setText(simpleDateFormat.format(date));
}

//获取当前地址

 1    public LocationClient mLocationClient = null;
2 private MyLocationListener myListener = new MyLocationListener();
3 //获取地址
4 public class MyLocationListener extends BDAbstractLocationListener {
5 @Override
6 public void onReceiveLocation(BDLocation location){
7 //此处的BDLocation为定位结果信息类,通过它的各种get方法可获取定位相关的全部结果
8 //以下只列举部分获取地址相关的结果信息
9 //更多结果信息获取说明,请参照类参考中BDLocation类中的说明
10 String addr = location.getAddrStr(); //获取详细地址信息
11 String country = location.getCountry(); //获取国家
12 String province = location.getProvince(); //获取省份
13 String city = location.getCity(); //获取城市
14 String district = location.getDistrict(); //获取区县
15 String street = location.getStreet(); //获取街道信息
16 String town = location.getTown();
17 //获取乡镇信息
18 text4=(EditText)findViewById(R.id.tv_text4);
19 text4.setText(country+" " +province+" "+city+" "+district+" "+town+" "+street+" ");
20 }
21 }
22 //自动获取地址
23 public void autoAddress(View view)
24 {
25 mLocationClient = new LocationClient(getApplicationContext());
26 //声明LocationClient类
27 mLocationClient.registerLocationListener(myListener);
28 LocationClientOption option = new LocationClientOption();
29 option.setIsNeedAddress(true);
30 option.setNeedNewVersionRgc(true);
31 mLocationClient.setLocOption(option);
32 //注册监听函数
33 mLocationClient.start();
34 }
所以大概是这样的
LocationClient这个类定义的是用户使用的类
MyLocationLisenter 这个类定义一个监听的工具,BDLocation这个类用来获取具体的地址字符串
mLocationClient.registerLocationListener(myListener);  这句话就是把用户的类和监听类绑定在一起

28-30行的内容是用户对这个地图的选项设置

LocationClientOption lcOption = new LocationClientOption();

//设置定位模式:高精度,低功耗,仅设备
lcOption.setLocationMode(LocationMode.Hight_Accuracy);
//设置坐标系
lcOption.setCoorType("bd09ll");
//设置GPS打开
lcOption.setOpenGps(true);
//设置需要地址信息
lcOption.setIsNeedAddress(true);
//设置每秒更新一次位置信息
lcOption.setScanSpan(1000);
//设置需要位置描述信息
lcOption.setIsNeedLocationDescribe(true);

mBdLocationManager.setLocOption(lcOption);
————————————————
版权声明:本文为CSDN博主「秋天该很好」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_36444585/article/details/78152765

【已解决】Android学习---注册和登录功能模块合并报错以及解决办法的更多相关文章

  1. Android学习笔记_65_登录功能本身没有任何特别

    对于登录功能本身没有任何特别,使用httpclient向服务器post用户名密码即可.但是为了保持登录的状态(在各个Activity之间切换时要让网站知道用户一直是处于登录的状态)就需要进行cooki ...

  2. 在android移动设备上登录gmail的时候报password错误解决方法!!!!

    今天刚发现的解决的方法:就是登录web端的gmail,查看收件箱应该有no-reply这一帐户给你发过邮件(假设没有,你在移动设备上登录一下gmail).照着邮件里的说明去做,就是生成一个专门应用的p ...

  3. 【已解决】HeidiSQL连接(登录)MySQL数据库报错10061问题

    解决方法: 打开cmd->输入命令services.msc 然后打开即可解决.

  4. android studio 使用的一些注意,一些报错的解决方法(原创)

    NDK 编译无法通过 注意看 build.gradle 里面的 有些是 ndk-build windows 上用 ndk-build.cmd Summary: gradle calls ndk-bui ...

  5. SSH登录之后运行命令报错的解决办法-- Failed to connect to Mir: Failed to connect to server socket: No such file or directory

    问题描述: Failed to connect to Mir: Failed to connect to server socket: No such file or directory 解决方案: ...

  6. 快速体验 Laravel 自带的注册、登录功能

    快速体验 Laravel 自带的注册.登录功能 注册.登录经常是一件很伤脑筋的是,Laravel 提供了解决方案,可以直接使用它.试过之后,感觉真爽! 前提:本地已安装好了 PHP 运行环境.mysq ...

  7. ssm整合实现注册与登录功能

    最简洁易懂的SSM整合源码都在这里了 激情提示: 1.本项目是用IDEA编写的,不管你是习惯何种ide工具,那也只是工具而已,源代码才是本质 2.本项目只拥有注册和登录功能,简易的功能和详细的注释,是 ...

  8. 使用JFinal框架连接数据库,实现注册、登录功能

    使用JFinal框架连接数据库,实现注册.登录功能 1.在Eclipse中新建Dynamic Web project项目 2.导入jfinal-2.2-bin-with-src.jar.c3p0-0. ...

  9. Android(java)学习笔记125:Clock app编写报错02

    1.首先之间看错误: 07-13 10:07:55.354: E/AndroidRuntime(8008): FATAL EXCEPTION: main 07-13 10:07:55.354: E/A ...

  10. Android(java)学习笔记65:Clock App 编写报错02

    1. 首先之间看错误: 07-13 10:07:55.354: E/AndroidRuntime(8008): FATAL EXCEPTION: main 07-13 10:07:55.354: E/ ...

随机推荐

  1. Go中响应式编程库github.com/ReactiveX/RxGo详细介绍

    最近的项目用到了 RxGo ,因为之前从没有接触过,特意去学了学,特此记录下.文章很多内容是复制了参考资料或者官方文档.如果涉及侵权,请联系删除,谢谢. 1.RxGo简介 1.1 基础介绍 RxGo是 ...

  2. RibbonRoutingFilter是如何工作的

    在讲RibbonRoutingFilter是如何工作之前,也有一些比较重要的类需要去提前了解. 重要的类 RequestContext 请求上下文,用于存储线程中对应的请求以及响应 public cl ...

  3. Java HashMap 详解

    HashMap HashMap 继承自 AbstractMap,实现了 Map 接口,基于哈希表实现,元素以键值对的方式存储,允许键和值为 null.因为 key 不允许重复,因此只能有一个键为 nu ...

  4. 【Azure Spring Cloud】使用azure-spring-boot-starter-storage来上传文件报错: java.net.UnknownHostException: xxxxxxxx.blob.core.windows.net: Name or service not known

    问题描述 使用 azure-spring-boot-starter-storage 来上传文件到 Storage Blob中,并把应用部署到Azure 中国区的Spring Cloud服务后,调用上传 ...

  5. 【Azure 应用服务】Azure Function (PowerShell) 执行时报错 "out of memory"

    问题描述 在Azure Function App服务中,创建一个PowerShell脚本的函数,遇见了OOM(Out Of Memory)的异常报错: 2022-01-10T07:44:37 Welc ...

  6. 为Oracle链接服务器使用分布式事务

    1 现象 在SQL Server中创建指向Oracle的链接服务器,SQL语句在事务中向链接服务器插入数据.返回链接服务器无法启动分布式事务的报错. 2 解决 在Windows平台下,SQL Serv ...

  7. Java 封装+构造器+this 小测试

    1 package com.bytezero.account; 2 3 4 public class Account 5 { 6 private int id; //账号 7 private doub ...

  8. 3DES算法的起源与演进:保障信息安全的重要里程碑

    一.3DES算法的起源与演进 3DES算法是DES算法的增强版,由IBM公司在上世纪90年代初提出.DES算法的密钥长度只有56位,随着计算机计算能力的提升,其安全性逐渐受到威胁.为了增强数据的安全性 ...

  9. C# DiagnosticSource and DiagnosticListener

    class Program { private static readonly DiagnosticSource testDiagnosticListener = new DiagnosticList ...

  10. linux 服务器 执行命令挂起 nohup 改用 pm2

    nohup http-server -p 80 & nohup完要 exit 退出,不能直接关! nohup完要 exit 退出,不能直接关! nohup完要 exit 退出,不能直接关! 重 ...