所以我使用教程来创建我的第一个应用程序。我正在使用我的手机作为模拟器(HTC One X版本4.0.3 android) 我的编码没有错误,但出于某种原因,我得到了“不幸的应用程序停止了”。我已经尝试将它运行的版本从2.2到4.0.3之间更改,但它们都没有帮助。 这是我的错误日志和编码(简单的编码,所以希望很容易修复)
错误日志
06-09 12:37:20.630: D/AndroidRuntime(18583): Shutting down VM
06-09 12:37:20.650: W/dalvikvm(18583): threadid=1: thread exiting with uncaught exception (group=0x40a65228)
06-09 12:37:20.660: E/AndroidRuntime(18583): FATAL EXCEPTION: main
06-09 12:37:20.660: E/AndroidRuntime(18583): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.regoreminder/com.regoreminder.RegoReminderActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class imageview
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2237)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.app.ActivityThread.access$600(ActivityThread.java:139)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.os.Handler.dispatchMessage(Handler.java:99)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.os.Looper.loop(Looper.java:156)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.app.ActivityThread.main(ActivityThread.java:5005)
06-09 12:37:20.660: E/AndroidRuntime(18583): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 12:37:20.660: E/AndroidRuntime(18583): at java.lang.reflect.Method.invoke(Method.java:511)
06-09 12:37:20.660: E/AndroidRuntime(18583): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-09 12:37:20.660: E/AndroidRuntime(18583): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-09 12:37:20.660: E/AndroidRuntime(18583): at dalvik.system.NativeStart.main(Native Method)
06-09 12:37:20.660: E/AndroidRuntime(18583): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class imageview
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-09 12:37:20.660: E/AndroidRuntime(18583): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.app.Activity.setContentView(Activity.java:1897)
06-09 12:37:20.660: E/AndroidRuntime(18583): at com.regoreminder.RegoReminderActivity.onCreate(RegoReminderActivity.java:13)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.app.Activity.performCreate(Activity.java:4543)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2158)
06-09 12:37:20.660: E/AndroidRuntime(18583): ... 11 more
06-09 12:37:20.660: E/AndroidRuntime(18583): Caused by: java.lang.ClassNotFoundException: android.view.imageview
06-09 12:37:20.660: E/AndroidRuntime(18583): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-09 12:37:20.660: E/AndroidRuntime(18583): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-09 12:37:20.660: E/AndroidRuntime(18583): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:636)
06-09 12:37:20.660: E/AndroidRuntime(18583): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
06-09 12:37:20.660: E/AndroidRuntime(18583): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
06-09 12:37:20.660: E/AndroidRuntime(18583): ... 21 more
JAVA package com.regoreminder;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class RegoReminderActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread logoTimer = new Thread(){
public void run(){
try{
int logoTimer = 0;
while(logoTimer <5000) {
sleep (100);
logoTimer = logoTimer +100;
}
startActivity(new Intent("com.regoreminder.CLEARSCREEN"));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish();
}
}
};
logoTimer.start();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.regoreminder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<activity
android:name=".RegoReminderActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Title"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.regoreminder.CLEARSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
MAIN
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/background"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Continue"
android:gravity="center"/>
</LinearLayout>
飞溅
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<imageview
android:src="@drawable/titlebackground"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
如果有人能提供一些关于我做错了什么的帮助那就太棒了!我一直在关注一个教程,所以我不确定什么是错的。同时在网上寻找答案,但每个应用程序都不同。
答案 0 :(得分:5)
更改此
<imageview
android:src="@drawable/titlebackground"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
要
<ImageView
android:src="@drawable/titlebackground"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
答案 1 :(得分:2)
imageview
应为ImageView
(请注意案例)
答案 2 :(得分:2)
[...]我正在使用教程来创建我的第一个应用程序。
欢迎来到编程世界......
其他答案告诉你它有什么问题以及如何解决它。但您需要学习的是如何诊断自己解决这些问题。它主要涉及学习读取堆栈跟踪。
如果查看堆栈跟踪,您将看到许多部分:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.regoreminder/com.regoreminder.RegoReminderActivity}:
android.view.InflateException: Binary XML file line #7: Error
inflating class imageview
...
Caused by: android.view.InflateException: Binary XML file line #7:
Error inflating class imageview
...
Caused by: java.lang.ClassNotFoundException: android.view.imageview
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.view.LayoutInflater.createView(LayoutInflater.java:552)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:636)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
第一部分是主要异常堆栈跟踪,其他部分是一系列嵌套/链接异常...其中一个异常被捕获,另一个异常被创建并抛出第一个异常作为原因。 / p>
现在看一下实际的消息。每个人都在谈论一个名为“imageview”的课程。实际上,最后一个给出了类“android.view.imageview”的完全限定名称...并且说异常名称是“ClassNotFoundException”。这个例外基本上就意味着它所说的。 VM(或更具体地说是类加载器)找不到具有该名称的类。 (并且您将在跟踪中看到类加载器的类/方法名称。)
为什么?
因为它不存在。或者确切地说,没有任何类具有该大写字母。所有Java和Android类都是大写的,因此您永远不会在Java或Android中看到名为“imageview”的类。
那么你应该问自己“这个错误的类名来自哪里”?它不会在您的源代码中(除非您使用反射),因为如果您对库类使用了错误的类名,您将看到编译错误。所以一定是你的配置。快速搜索显示......确实......它就是名字的来源。再一次,在堆栈跟踪中,在堆栈跟踪的最后两行中有确认证据:
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
名称暗示它正在尝试在布局中创建视图,并且视图名称来自XML标记。
答案 3 :(得分:-1)
您的观点应始终为大写。在您的情况下“ImageView”