《报错与问题解决方案》总结v1.0版本
Posted 王睿丶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了《报错与问题解决方案》总结v1.0版本相关的知识,希望对你有一定的参考价值。
文章目录
- 1、(Android)Activity.getWindowManager().getDefaultDisplay().getWidth()已被废弃
- 2、(Android)Description Resource Path Location Type AndroidManifest.xml file missing!
- 3、(Android)xxx cannot be resolved to a type
- 4、(Android)java.lang.RuntimeException: Unable to start activity Activity无法打开
- 5、(Android)Failed to resolve: com.android.support:appcompat-v7:28.0.0-alpha
- 6、(Android)java.lang.NullPointerException
- 7、(ADT)找不到android.support.v4.view.ViewPager
- 8、(Android)This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView)
- 9、(Android)Description Resource Path Location Type Call requires API level 9 (current min is 8):
- 10、(Android)java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Bu
- 11、(Android)android.app ClassCastException。SharedPreferencesImpl不能被强制转换为android.content.Shared
- 12、(Android)android.content.ActivityNotFoundException:activity in yourAndroidManifest.?
- 13、(Android)Description Resource Path Location Type Unparsed aapt error(s)! Cheheck the console for o
- 14、(Android)完美解决EditText和ScrollView的滚动冲突
- 15、(JavaWeb)bug记录
- 16、(Android)java.lang.ClassCastException: .MainActivity cannot be cast to java.lang.Runnable
- 17、(Android)unknow host service.gradle.org, proxy settings in gradle
- 18、(Flutter)No pubspec.yaml file found. This command should be run from the root of your Flutter project. Do not
- 19、(Flutter)Navigator operation requested with a context that does not include a Navigator.
- Navigator operation requested with a context that does not include a Navigator.
- 20、(Flutter)ListView和GridView嵌套报错?
- 21、(Android)table burner has no column named USER (code 1): , while compiling: INSERT INTO burner(USER,YELL
- 22、(Android)android.database.sqlite.SQLiteException: no such column: id (code 1): , while compiling: select
- 23、(Android)Error inserting GREEM=30 YELLOW=4 RED=5 android.database.sqlite.SQLiteException: no such tab
- 24、(Flutter)ListView不能直接嵌套ListView
- 25、(Flutter)Expanded组件不能直接嵌套LitView
- 26、(Android)setOnPageChangeListener 过时了怎么办?
- 27、(Android)java.lang.ClassCastException: com.github.mikephil.charting.charts.PieChart cannot be cast
- 28、(Android) Caused by: java.lang.ClassCastException: com.github.mikephil.charting.charts.PieChart can
- 29、(Android)IllegalStateException: The specified child already has a parent问题解决办法
- 30、(Android)setBackgroundResource无反应?
- 31、(Java)利用SimpleDateFormat格式化时间不准确
- 32、(Git)git push报错error: failed to push some refs to
- 33、(gitee)在码云上如何创建仓库
- 34、(Android)ImageView报错:不是可绘制对象(颜色或路径)
- 35、(MySQL)MySQL Server 安装失败
- 36、(SSL)无法建立SSL连接
- 37、(Ubuntu)python3.6升级到python3.7
- 38、(Ubuntu)su root无法切换到root用户
- 39、(Ubuntu)source ~/.bashrc 无法执行
- 40、(Ubuntu)安装Python版本出现No module named ‘apt_pkg‘
- 41、(Ubuntu)Running pip as root will break packages and permissions. You should install packages reliably by usi
- 42、(Ubuntu)安装并配置好 hb后,hb -h检测不对
- 43、(OpenHarmony)[OHOS ERROR] clang not found, install it please
- 44、(OpenHarmony)FAILED: libcjson_shared.so unstripped/usr/lib/libcjson_shared.so
- 45、(Ubuntu)Could not start AVD
- 46、(Git)fatal: Not a git repository (or any parent up to mount point /home)
- 47、(DevEco Studio) Could not install Gradle distribution
- 48、(HarmonyOS)Gradle在哪里下载
- 59、(Android)metalava was unable to determine the package name
- 50、(Android)Toast不显示的解决方案
- 51、(Ubuntu)terminal同一窗口多开
- 52、(Android)开发里跳过的坑-电源锁WakeLock不起作用
- 53、(ADB)如何退出adb logcat
1、(android)Activity.getWindowManager().getDefaultDisplay().getWidth()已被废弃
解决办法:
方法一:
// 通过WindowManager获取
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
System.out.println(“width-display :” + dm.widthPixels);
System.out.println(“heigth-display :” + dm.heightPixels);
方法二:
// 通过Resources获取
DisplayMetrics dm2 = getResources().getDisplayMetrics();
System.out.println(“width-display :” + dm2.widthPixels);
System.out.println(“heigth-display :” + dm2.heightPixels);
2、(Android)Description Resource Path Location Type AndroidManifest.xml file missing!
点击工具栏上面的Project:
顺序为:
Project>clean then Project>Build All
3、(Android)xxx cannot be resolved to a type
右键自己的Project → Properties → Resource → Other → UTF-8
4、(Android)java.lang.RuntimeException: Unable to start activity Activity无法打开
亲测可行~!
解决java.lang.RuntimeException: Unable to start activity Activity无法打开的问题
原文链接:https://blog.csdn.net/ldld1717/article/details/52251762
5、(Android)Failed to resolve: com.android.support:appcompat-v7:28.0.0-alpha
出现这个错误是因为我们的依赖库中,报的错误
打个比方,我之前有一个依赖不小心改成了:
改正后
即可解决问题
6、(Android)java.lang.NullPointerException
原文:java.lang.NullPointerException - 如何处理空指针异常
7、(ADT)找不到android.support.v4.view.ViewPager
我的思路是:
首先先导入.v4包:具体步骤
导入v4包步骤
然后再在界面中直接这么写即可:无需关心快捷键中是否有
android.support.v4.view.ViewPager
<android.support.v4.view.ViewPager
android:id="@+id/vp_advertising"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginTop="40dp" >
</android.support.v4.view.ViewPager>
8、(Android)This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView)
菜单栏window ——>Preferences——>Android——>Lint error Checking——>在issues搜索:Instantiatable
9、(Android)Description Resource Path Location Type Call requires API level 9 (current min is 8):
翻译错误:描述资源路径位置类型
调用需要API级别9(当前最小值为8):android.content.SharedPreferences。应用shezhifragment.java /JiaoTong_Textc/com/example/jiaotong_text行127 android Lint问题
10、(Android)java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Bu
java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Button.
翻译:. lang。android.widget ClassCastException。无法将TextView转换为android.widget.Button
意思就是说:代码中有按钮成员变量,却绑定的文本框组件,所以发生了异常
11、(Android)android.app ClassCastException。SharedPreferencesImpl不能被强制转换为android.content.Shared
. lang。android.app ClassCastException。SharedPreferencesImpl不能被强制转换为android.content.SharedPreferences$Editor
极有可能是因为:
错误代码
SharedPreferences.Editor sp = (Editor) getActivity().getSharedPreferences("data", 0x0000).edit();
正确代码:
SharedPreferences sp = (Editor) getActivity().getSharedPreferences("data", 0x0000).edit();
sp.putString("name", username);
sp.apply();
所以类型不匹配无法强制转换
12、(Android)android.content.ActivityNotFoundException:activity in yourAndroidManifest.?
这种错误很奇葩,有时候是因为工程自身出了问题,新建项目即可解决该问题
还有种情况,是我们把AndroidManifest.XML,删掉保存,再返回,保存,重新运行下项目,又可以对了
13、(Android)Description Resource Path Location Type Unparsed aapt error(s)! Cheheck the console for o
Description Resource Path Location Type
Unparsed aapt error(s)! Check the console for output. JiaoTong_Text line 1 Android ADT Problem
翻译:描述资源路径位置类型
未解析aapt错误(s) !检查控制台的输出。android ADT问题
14、(Android)完美解决EditText和ScrollView的滚动冲突
在网上搜了一下EditText和ScrollView的滚动冲突,发现几乎所有的解决方案都是触摸EditText的时候就将事件交由EditText处理,否则才将事件交由ScrollView处理。这样确实初步解决了两者之间的滚动冲突,但并不是最好的解决方案。比如,EditText本来可以显示6行文本,但是目前只显示了5行文本,此时我们在EditText区域进行滑动并期望整个页面能够滚动,但由于我们将事件交给了EditText进行处理,所以页面并不能滚动,这样的体验是极差的。其实我们更希望当EditText出现滚动条的时才将滚动事件交由它本身处理,其他情况下应当让ScrollView来处理。那么该如何进行实现呢?接下来咱们就做一个小Demo来实现这种方案。
1.布局文件
首先编写布局文件,可以看出这是非常简单的一个布局:一个ScrollView包裹着一个垂直方向的LinearLayout,LinearLayout中有两个TextView和一个EditText,其中为了区分EditText的范围,给其设置了一个背景rectangle_shape。
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="300dp"
android:text="Hello World Begin!"/>
<EditText
android:id="@+id/edit_text"
android:hint="EditText"
android:layout_width="match_parent"
android:layout_height="200dp"
android:gravity="top"
android:background="@drawable/rectangle_shape"/>
<TextView
android:layout_width="match_parent"
android:layout_height="300dp"
android:text="Hello World End!"/>
</LinearLayout>
</ScrollView>
2.rectangle_shape
背景rectangle_shape的代码,更没有什么技术含量。。。。。。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff"/>
<stroke android:color="#cccccc"
android:width="1dp"/>
</shape>
3.MainActivity中的代码
这里就是主要的代码逻辑了。先给EditText设置OnTouchListener,然后先在OnTouch方法中判断当前点击的区域是否为EditText,如果为EditText区域则再判断是否可以在垂直方向上进行滚动,如果可以滚动则将事件交由EditText处理,否则将事件交由ScrollView处理。
此处最重要的就是如何判断EditText区域在垂直方向上可以滚动,此处的代码已经封装成了一个方法,大家可以直接使用。那么为什么要这样判断呢?如果大家仍有兴趣,请继续阅读完美解决EditText和ScrollView的滚动冲突(下)。
public class MainActivity extends Activity implements View.OnTouchListener {
private EditText mEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEditText = (EditText) findViewById(R.id.edit_text);
mEditText.setOnTouchListener(this);
}
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
//触摸的是EditText并且当前EditText可以滚动则将事件交给EditText处理;否则将事件交由其父类处理
if ((view.getId() == R.id.edit_text && canVerticalScroll(mEditText))) {
view.getParent().requestDisallowInterceptTouchEvent(true);
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
view.getParent().requestDisallowInterceptTouchEvent(false);
}
}
return false;
}
/**
* EditText竖直方向是否可以滚动
* @param editText 需要判断的EditText
* @return true:可以滚动 false:不可以滚动
*/
private boolean canVerticalScroll(EditText editText) {
//滚动的距离
int scrollY = editText.getScrollY();
//控件内容的总高度
int scrollRange = editText.getLayout().getHeight();
//控件实际显示的高度
int scrollExtent = editText.getHeight() - editText.getCompoundPaddingTop() -editText.getCompoundPaddingBottom();
//控件内容总高度与实际显示高度的差值
int scrollDifference = scrollRange - scrollExtent;
if(scrollDifference == 0) {
return false;
}
return (scrollY > 0) || (scrollY < scrollDifference - 1);
}
}
————————————————
版权声明:本文为CSDN博主「曾博文」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z191726501/article/details/50701165
15、(JavaWeb)bug记录
今天来跟大家谈一下一个,我在做一个新闻项目的时候,遇到的一个很有意思的小Bug
报错的信息如下:
原因分析:
解决方法:
16、(Android)java.lang.ClassCastException: .MainActivity cannot be cast to java.lang.Runnable
像这种情况肯定是:
//在子线程中进行耗时操作
handler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
☆这里的this写成了MainActivity.this,所以报错了,他实际上需要的是Runnable这个内部类
handler.postDelayed(this, 2000); //延时2s
handler.sendEmptyMessage(0); //发送
}
});
}
}
17、(Android)unknow host service.gradle.org, proxy settings in gradle
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sinat_26710701/article/details/78082558
我们将其他项目导入到android studio 中的时候,如果gradle版本不对,经常会出现:
解决办法很简单,只需要在工程的build.gradle 文件中 将 classpath 修改为当前的gradle版本即可。
什么?你不知道当前gradle 版本号是多少?
最简单无脑的方法:新建一个项目,然后看看里面的工程build.gradle中的 classpath是多少,ctrl c —ctrl v。
结束 ,就是这么简单!
————————————————
版权声明:本文为CSDN博主「暴躁的码字猴」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sinat_26710701/article/details/78082558
18、(Flutter)No pubspec.yaml file found. This command should be run from the root of your Flutter project. Do not
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Do not run this command from the root of your git clone of Flutter.
翻译:
错误:找不到pubspec.yaml文件。
此命令应从Flutter项目的根目录运行。
不要从Flutter的git克隆的根目录运行此命令
解决:
只需要将根目录切换到当前工程文件即可:如下
cd flutter_app02,切换到当前工程
然后在flutter run运行项目即可!
19、(Flutter)Navigator operation requested with a context that does not include a Navigator.
flutter 最容易报的一个错误就是does not include,因为其思想是组合
这种情况即使是外面包裹了materialapp也是无效的,因为flutter会根据这个context一直上溯,一直到根节点的widget,注意,上溯是根据context的,会上溯到这个context相关的widget的最根节点
14down vote
This error is unrelated to the destination. It happens because you used a context that doesn’t contain a Navigator instance as parent.
How do I create a Navigator instance then ?
This is usually done by inserting in your widget tree a MaterialApp or WidgetApp. Although you can do it manually by using Navigator directly but less recommended. Then, all children of such widget can access NavigatorState using Navigator.of(context).
Wait, I already have a MaterialApp/WidgetApp !
That’s most likely the case. But this error can still happens when you use a context that is a parent of MaterialApp/WidgetApp.
This happens because when you do Navigator.of(context), it will start from the widget associated to the context used. And then go upward in the widget tree until it either find a Navigator or there’s no more widget.
In the first case, everything is fine. In the second, it throws a
Navigator operation requested with a context that does not include a Navigator.
So, how do I fix it ?
First, let’s reproduce this error :
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Center(
child: RaisedButton(
child: Text("Foo"),
onPressed: () => Navigator.pushNamed(context, "/"),
),
),
);
}
}
This example creates a button that attempts to go to ‘/’ on click but will instead throw an exception.
Notice here that in the
onPressed: () => Navigator.pushNamed(context, “/”),
we used context passed by to build of MyApp.
The problem is, MyApp is actually a parent of MaterialApp. As it’s the widget who instantiate MaterialApp! Therefore MyApp’s BuildContext doesn’t have a MaterialApp as parent!
To solve this problem, we need to use a different context.
In this situation, the easiest solution is to introduce a new widget as child of MaterialApp. And then use that widget’s context to do the Navigator call.
There are a few ways to achieve this. You can extract home into a custom class :
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHome()
);
}
}
class MyHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: RaisedButton(
child: Text("Foo"),
onPressed: () => Navigator.pushNamed(context, "/"),
),
);
}
}
Or you can use Builder :
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Builder(
builder: (context) => Center(
child: RaisedButton(
child: Text("Foo"),
onPressed: () => Navigator.pushNamed(context, "/"),
),
),
),
);
}
}
20、(Flutter)ListView和GridView嵌套报错?
直接在GridView布局里,加上这两句代码,即可解决问题!
physics: new NeverScrollableScrollPhysics(),//增加
shrinkWrap: true,//增加
例子如下:
GridView.count(
physics: new NeverScrollableScrollPhysics(),//增加
shrinkWrap: true, //增加
...
...
children: <Widget>[
...
...
],
);
21、(Android)table burner has no column named USER (code 1): , while compiling: INSERT INTO burner(USER,YELL
谷歌翻译:
表刻录机没有名为USER(代码1)的列:,正在编译:INSERT INTO Burner(USER,YELLOW,TIME)值(?,?,?)
在android.database.sqlite.SQLiteConnection.nativePrepareStatement(本机方法)
简单理解:
意思就是说,数据库中没有该列,但在插入时,多了这么一项
22、(Android)android.database.sqlite.SQLiteException: no such column: id (code 1): , while compiling: select
谷歌翻译:
android.database.sqlite.SQLiteException:无此类列:id(代码1):,而在编译时:通过id desc从刻录机顺序中选择*
简单理解:
id的名字写错了,导致操作数据库时,找不到id这一列
23、(Android)Error inserting GREEM=30 YELLOW=4 RED=5 android.database.sqlite.SQLiteException: no such tab
谷歌翻译
插入GREEM = 30 YELLOW = 4 RED = 5时出错
android.database.sqlite.SQLiteException:没有这样的表:Burner(代码1):,而在编译时:INSERT INTO Burner(GREEM,YELLOW,RED)值(?,?,?)
简单理解
表没有创建成功,不存在这张表导致插入数据时报错
24、(Flutter)ListView不能直接嵌套ListView
ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(
width: 180,
color: Colors.orange,
child: ListView(
children: <Widget>[
Image.network("https://www.itying.com/images/flutter/1.png"),
Text('我是一个文本')
],
),
),
],
),
直接套一个Container即可解决问题