2012-09-11 137 views
0

我的应用程序的加载阶段出现崩溃。 这里的源代码后:Android应用程序的负载崩溃

DiscoveryMain.java

package com.heeere.androiddnssd.discovery; 


import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 

public class DiscoveryMain extends Activity { 



    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     Button button = (Button)this.findViewById(R.id.button); 

     button.setOnClickListener(new OnClickListener() { 
       public void onClick(View v) { 
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); 
        startActivity(browserIntent); 
       } 
      }); 


    } /** Called when the activity is first created. */ 

} 

main.xml中

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scroller" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true"> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" 
       android:scrollbars="vertical" 
       android:fadeScrollbars="true" 
       android:isScrollContainer="true"> 
    <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Hello World, Android Discovery" /> 
    <TextView 
      android:id="@+id/text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Hello, I am a TextView" /> 
    <Button 
      android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Hello, I am a Button" /> 
    </LinearLayout> 
</ScrollView> 

的Manifest.xml

<?xml version="1.0" encoding="UTF-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.heeere.androiddnssd.discovery"> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/> 

    <application> 
     <activity android:name=".MainTest" android:label="DiscoveryActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN"/> 
       <category android:name="android.intent.category.LAUNCHER"/> 
      </intent-filter> 
     </activity> 
    </application> 
</manifest> 

logcat的

09-11 11:21:18.186: W/dalvikvm(3415): threadid=3: thread exiting with uncaught exception (group=0x4001e170) 
09-11 11:21:18.196: E/AndroidRuntime(3415): Uncaught handler: thread main exiting due to uncaught exception 
09-11 11:21:18.206: E/AndroidRuntime(3415): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.heeere.androiddnssd.discovery/com.heeere.androiddnssd.discovery.MainTest}: java.lang.ClassNotFoundException: com.heeere.androiddnssd.discovery.MainTest in loader [email protected] 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at android.app.ActivityThread.access$2200(ActivityThread.java:119) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at android.os.Handler.dispatchMessage(Handler.java:99) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at android.os.Looper.loop(Looper.java:123) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at android.app.ActivityThread.main(ActivityThread.java:4363) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at java.lang.reflect.Method.invokeNative(Native Method) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at java.lang.reflect.Method.invoke(Method.java:521) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at dalvik.system.NativeStart.main(Native Method) 
09-11 11:21:18.206: E/AndroidRuntime(3415): Caused by: java.lang.ClassNotFoundException: com.heeere.androiddnssd.discovery.MainTest in loader [email protected] 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409) 
09-11 11:21:18.206: E/AndroidRuntime(3415):  ... 11 more 

什么是我的代码proble?

+3

你会请加你的日志就死机 –

+2

如果你发布的logcat我们会更有帮助 –

+0

用LogCat – MOHAMED

回答

3

你有清单中的这个吗?

<activity 
      android:name=".DiscoveryMain" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

更新:

你是什么开始的活动? DiscoveryMain或MainTest?请加正确的

+1

+1,m迟了11秒.. – user370305

+0

也附上清单文件。并且它不包含意图过滤器 – MOHAMED

+0

添加它并测试 – breceivemail

2

请使用下面..

<application> 
    <activity android:name=".DiscoveryMain"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 
      <category android:name="android.intent.category.LAUNCHER"/> 
     </intent-filter> 
    </activity> 
</application> 

编码愉快。

0

我解决了这个问题。从breceivemail 该清单文件的启发只需使用

<activity android:name=".DiscoveryMain" android:label="DiscoveryActivity"> 

,而不是

<activity android:name=".MainTest" android:label="DiscoveryActivity">