Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 启动应用程序时出现意外错误_Java_Android_Eclipse_Android Intent - Fatal编程技术网

Java 启动应用程序时出现意外错误

Java 启动应用程序时出现意外错误,java,android,eclipse,android-intent,Java,Android,Eclipse,Android Intent,我是java新手,我开始为Android编写应用程序,但我有一个错误,我认为问题在于意图过滤器,但我真的不确定。。我一点都不懂。我怎样才能达到我的水平?我的代码是一个好的起点吗 错误消息: $ adb shell am start -n "test.beta1/test.beta1.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Unexpect

我是java新手,我开始为Android编写应用程序,但我有一个错误,我认为问题在于意图过滤器,但我真的不确定。。我一点都不懂。我怎样才能达到我的水平?我的代码是一个好的起点吗

错误消息:

     $ adb shell am start -n "test.beta1/test.beta1.MainActivity" -a 
       android.intent.action.MAIN -c android.intent.category.LAUNCHER
       Unexpected error while executing: am start -n 
       "test.beta1/test.beta1.MainActivity" -a android.intent.action.MAIN -c 
       android.intent.category.LAUNCHER
       Error while Launching activity
主要活动代码(已更新):

Activity_main.xml代码:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="10dp"
android:layout_height="match_parent">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageToUpload"
        android:layout_gravity="center_horizontal"
        android:layout_width="150dp"
        android:layout_height="150dp" />

    <EditText
        android:id="@+id/etUploadName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/bUploadImage"
        android:text="Upload Image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>


请解释一下如何解决这个问题好吗?

您可以从这个错误中找到问题的根源:

/Users/abhinanda/Desktop/Beta1/app/src/main/java/test/Beta1/MainActivity.java:16:错误:变量bdownloadeImage已在类MainActivity按钮bUploadImage、bdownloadeImage中定义^

/Users/abhinanda/Desktop/Beta1/app/src/main/java/test/Beta1/MainActivity.java:28:错误:不兼容类型:按钮无法转换为ImageView bdownloadeImage=(按钮)findViewById(R.id.etDownloadName);^2个错误

首先,您可以定义多个b下载图像。
其次,您尝试将按钮强制转换为ImageView,这是一个错误


检查布局。

在onCreate中,您向bUploadImage投射了错误的id。您正在转换的id R.id.etUploadName是一个文本视图

在尝试运行它时,ADB日志中应该有一个堆栈跟踪。你能提供日志吗?事件日志:15/10/17 12:50 AM渐变同步完成1:19 AM执行任务:[:app:assembleDebug]1:19 AM渐变生成完成,5s 362ms 1:20 AM执行任务时出现4个错误:[:app:assembleDebug]1:20 AM渐变生成完成,2s 261ms 1:26 AM执行任务时出现3个错误:[:app:assembleDebug]1:26 AM渐变构建在1s285ms中完成1:27 AM执行任务:[:应用程序:汇编程序错误]1:27 AM渐变构建在4s424ms中完成1:28 AM执行任务:[:应用程序:汇编程序错误]1:28 AM渐变构建在1s879ms中完成1:29 AM会话“应用程序”:错误启动活动我在帖子中添加了渐变控制台(已编辑)我在运行时收到apk文件,但打开后,它会在2秒钟后关闭。因为现在我删除了下载的图像。我只希望上传图像正常工作。我不理解你解决的第二个问题。我在上面的帖子中添加了我的activity_main.xml代码和更新的main_activity.java(已编辑)。请帮助asapso我应该强制转换按钮?或图像视图?只要将oncreate中的这一行“bUploadImage=(button)findviewbyd(R.id.etUploadName);”更改为“bUploadImage=(button)findviewbyd(R.id.bUploadImage);”如果问题已得到解决,请向上投票
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="10dp"
android:layout_height="match_parent">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageToUpload"
        android:layout_gravity="center_horizontal"
        android:layout_width="150dp"
        android:layout_height="150dp" />

    <EditText
        android:id="@+id/etUploadName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/bUploadImage"
        android:text="Upload Image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>