gpt4 book ai didi

java - Android Studio 应用程序可在模拟器中运行,但不能在真实设备上运行

转载 作者:太空狗 更新时间:2023-10-29 16:30:18 27 4
gpt4 key购买 nike

我是 android 编程的新手,在使用它时遇到了很多麻烦。我终于让我的应用程序在 API 23 和 16 的模拟器中运行,我的目标是 API 16。它在模拟器上运行没有问题,但是当我尝试在我的手机上使用它时(谷歌 Nexus 5 API 23)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:gravity="center"
android:orientation="vertical"
android:background="#F44336"
android:id="@+id/background"
tools:context="thereisstuffhere.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/factTextBox"
android:textSize="25dp"
android:textColor="#fff"/>
</LinearLayout>


package there is stuff here too;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

TextView factBox;
LinearLayout bg;
Facts factHolder = new Facts(this);
Backgrounds backs = new Backgrounds();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
factBox = (TextView) findViewById(R.id.factTextBox);
factBox.setText(factHolder.nextFact());
bg = (LinearLayout) findViewById(R.id.background);
bg.setBackgroundColor(getResources().getColor(backs.getBackground()));
bg.setOnTouchListener(new OnSwipeTouchListener(this)
{
public void onSwipeTop()
{
//Toast.makeText(MainActivity.this, "top", Toast.LENGTH_SHORT).show();
}
public void onSwipeRight()
{
//Toast.makeText(MainActivity.this, "right", Toast.LENGTH_SHORT).show();
prev();
}
public void onSwipeLeft()
{
//Toast.makeText(MainActivity.this, "left", Toast.LENGTH_SHORT).show();
next();
}
public void onSwipeBottom()
{
//Toast.makeText(MainActivity.this, "bottom", Toast.LENGTH_SHORT).show();
}
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
}

private void next() {
factBox.setText(factHolder.nextFact());
bg.setBackgroundColor(getResources().getColor(backs.getBackground()));
}

private void prev() {
factBox.setText(factHolder.prevFact());
bg.setBackgroundColor(getResources().getColor(backs.getBackground()));
}

public void genFact(View view)
{
factBox.setText(factHolder.nextFact());
}

Facts.java 只包含一个巨大的列表和两个返回列表中下一个或上一个字符串的函数

Backgrounds.java 本质上做同样的事情,只是它使用一个整数列表和 colors.xml 文件来存储标签等

这是我的 OnTouchListener 类:

package stuff be here;

import android.content.Context;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class OnSwipeTouchListener implements OnTouchListener {
final GestureDetector gestureDetector;

public OnSwipeTouchListener(Context ctx)
{
gestureDetector = new GestureDetector(ctx, new GestureListener());
}

@Override
public boolean onTouch(View view, MotionEvent motionEvent)
{
return false;
}

private final class GestureListener extends SimpleOnGestureListener{

private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;

@Override
public boolean onDown(MotionEvent e)
{
return true;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
boolean result = false;
try{
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
if(Math.abs(diffX) > Math.abs(diffY)){
if(Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD){
if(diffX > 0){
onSwipeRight();
}else{
onSwipeLeft();
}
}
result = true;
}
else if(Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD){
if(diffY > 0){
onSwipeBottom();
}else{
onSwipeTop();
}
}
result = true;
} catch (Exception exception){
exception.printStackTrace();
}
return result;
}
}
public void onSwipeRight(){}
public void onSwipeLeft(){}
public void onSwipeTop(){}
public void onSwipeBottom(){}
}

对于所有代码,我深表歉意,但我已经尝试修复此问题一段时间了,但无济于事。当我尝试像“使用引导类加载器找不到类;没有可用的堆栈跟踪”和“无法实例化 Activity ComponentInf...”这样的方式运行时,我遇到了很多错误,我还收到了一些警告,例如“ClassLoader 引用了未知路径:/data/app/packagenamehere-1/lib/x86_64 和/data/app/packagenamehere-1/lib/arm"即使在模拟器中运行也是如此

这是我的日志 cat 文件:

12-16 17:26:25.167 22237-22237/com.ubiquity.sciencefacts I/art: Late-enabling -Xcheck:jni
12-16 17:26:25.197 22237-22243/com.ubiquity.sciencefacts I/art: Ignoring second debugger -- accepting and dropping
12-16 17:26:25.203 22237-22243/com.ubiquity.sciencefacts I/art: Debugger is no longer active
12-16 17:26:25.211 22237-22243/com.ubiquity.sciencefacts W/art: Suspending all threads took: 7.324ms
12-16 17:26:25.235 22237-22237/com.ubiquity.sciencefacts W/System: ClassLoader referenced unknown path: /data/app/com.ubiquity.sciencefacts-2/lib/arm
12-16 17:26:25.248 22237-22237/com.ubiquity.sciencefacts D/AndroidRuntime: Shutting down VM
12-16 17:26:25.254 22237-22237/com.ubiquity.sciencefacts E/AndroidRuntime: FATAL EXCEPTION: main
12-16 17:26:27.065 22237-22237/com.ubiquity.sciencefacts I/Process: Sending signal. PID: 22237 SIG: 9
12-16 17:33:18.574 24986-24986/com.ubiquity.sciencefacts W/System: ClassLoader referenced unknown path: /data/app/com.ubiquity.sciencefacts-1/lib/arm
12-16 17:33:18.662 24986-24986/com.ubiquity.sciencefacts D/AndroidRuntime: Shutting down VM
12-16 17:33:18.673 24986-24986/com.ubiquity.sciencefacts E/AndroidRuntime: FATAL EXCEPTION: main
12-16 17:33:20.800 24986-24986/com.ubiquity.sciencefacts I/Process: Sending signal. PID: 24986 SIG: 9
12-16 17:34:15.668 25845-25845/com.ubiquity.sciencefacts W/System: ClassLoader referenced unknown path: /data/app/com.ubiquity.sciencefacts-1/lib/arm
12-16 17:34:15.687 25845-25845/com.ubiquity.sciencefacts D/AndroidRuntime: Shutting down VM
12-16 17:34:15.693 25845-25845/com.ubiquity.sciencefacts E/AndroidRuntime: FATAL EXCEPTION: main
12-16 18:00:52.080 2640-2640/com.ubiquity.sciencefacts I/art: Not late-enabling -Xcheck:jni (already on)
12-16 18:00:52.142 2640-2640/com.ubiquity.sciencefacts W/System: ClassLoader referenced unknown path: /data/app/com.ubiquity.sciencefacts-1/lib/x86_64
12-16 18:00:52.568 2640-2640/com.ubiquity.sciencefacts W/System: ClassLoader referenced unknown path: /data/app/com.ubiquity.sciencefacts-1/lib/x86_64
12-16 18:00:52.805 2640-2640/com.ubiquity.sciencefacts W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
12-16 18:00:53.993 2640-2646/com.ubiquity.sciencefacts W/art: Suspending all threads took: 633.582ms
12-16 18:00:54.020 2640-2716/com.ubiquity.sciencefacts D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
12-16 18:00:54.063 2640-2716/com.ubiquity.sciencefacts I/OpenGLRenderer: Initialized EGL, version 1.4
12-16 18:00:54.091 2640-2716/com.ubiquity.sciencefacts E/EGL_emulation: tid 2716: eglSurfaceAttrib(1165): error 0x3009 (EGL_BAD_MATCH)
12-16 18:00:54.091 2640-2716/com.ubiquity.sciencefacts W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f8b8ec90c40, error=EGL_BAD_MATCH
12-16 18:34:41.488 27869-27869/com.ubiquity.sciencefacts I/art: Late-enabling -Xcheck:jni
12-16 18:34:41.561 27869-27869/com.ubiquity.sciencefacts W/System: ClassLoader referenced unknown path: /data/app/com.ubiquity.sciencefacts-2/lib/arm
12-16 18:34:41.586 27869-27869/com.ubiquity.sciencefacts D/AndroidRuntime: Shutting down VM
12-16 18:34:41.589 27869-27869/com.ubiquity.sciencefacts E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ubiquity.sciencefacts, PID: 27869
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ubiquity.sciencefacts/com.ubiquity.sciencefacts.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.ubiquity.sciencefacts.MainActivity" on path: DexPathList[[zip file "/data/app/com.ubiquity.sciencefacts-2/base.apk"],nativeLibraryDirectories=[/data/app/com.ubiquity.sciencefacts-2/lib/arm, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.ubiquity.sciencefacts.MainActivity" on path: DexPathList[[zip file "/data/app/com.ubiquity.sciencefacts-2/base.apk"],nativeLibraryDirectories=[/data/app/com.ubiquity.sciencefacts-2/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Suppressed: java.lang.ClassNotFoundException: com.ubiquity.sciencefacts.MainActivity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
12-16 18:34:43.772 27869-27869/com.ubiquity.sciencefacts I/Process: Sending signal. PID: 27869 SIG: 9

重要更新:我将程序构建为 apk 并使用它安装在我的手机上,并且运行没有问题。这是否意味着下面评论中所说的目标错误?这会影响我的应用程序的分发吗(为了将来引用,我实际上并没有分发它)?

最佳答案

关于您的错误,似乎缺少一些 SDK。

检查您的 SDK 管理器是否安装了所有需要的 SDK 和 SDK 工具。

关于java - Android Studio 应用程序可在模拟器中运行,但不能在真实设备上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41179790/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com