如何将我的家庭布局连接到Ringdroid布局Android

时间:2015-01-04 20:12:58

标签: java android

我是android开发的初学者,我选择ringdroid来练习。在我的应用程序中,我创建了一个名为home.xml的xml布局,其中包含一个按钮,我创建了一个名为Home.class的类文件,这是代码:

public class Home extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    Button edit = (Button)findViewById(R.id.editor);


    edit.setOnClickListener (new OnClickListener() {
        public void onClick(View v){

            Intent e = new Intent (v.getContext(), RingdroidSelectActivity.class);
            startActivityForResult(e,0);
            }
        });
    }


}

我的问题当我点击或点击按钮转到RingdroidSelectActivity时我得到了一个错误"不幸的是Ringdroid已经停止"。这是我的Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.ringdroid"
      android:versionName="2.5"
      android:versionCode="20500">

<uses-sdk android:minSdkVersion="8"
          android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application android:label="@string/ringdroid_app_name"
             android:icon="@drawable/ringdroidlogo">


    <activity android:name ="com.ringdroid.home">

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

        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.OPENABLE" />
            <data android:mimeType="audio/*" />
        </intent-filter>
    </activity>


    <!-- Main activity that's launched when the user opens Ringdroid. -->

             <activity android:name="RingdroidSelectActivity"></activity>


<!-- Activity for actually editing a particular audio file.
         Controls viewing the waveform, setting the start and end
         positions, playback, and triggering saving of the output
         file. -->
    <activity android:name="RingdroidEditActivity"
              android:configChanges="orientation|keyboardHidden">
        <intent-filter android:label="@string/edit_intent">
            <action android:name="android.intent.action.EDIT" />
            <data android:mimeType="audio/*" />
        </intent-filter>
    </activity>

<!-- Activity for choosing a contact to assign a ringtone to. -->
    <activity android:name="ChooseContactActivity"
              android:configChanges="orientation|keyboardHidden">
    </activity>



</application>

最后是Logcat:

01-05 05:01:43.464: D/AndroidRuntime(278): Shutting down VM
01-05 05:01:43.464: W/dalvikvm(278): threadid=1: thread exiting with uncaught exception             (group=0x4001d800)
01-05 05:01:43.494: E/AndroidRuntime(278): FATAL EXCEPTION: main
01-05 05:01:43.494: E/AndroidRuntime(278): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ringdroid/com.ringdroid.RingdroidSelectActivity}: java.lang.NullPointerException
01-05 05:01:43.494: E/AndroidRuntime(278):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-05 05:01:43.494: E/AndroidRuntime(278):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-05 05:01:43.494: E/AndroidRuntime(278):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-05 05:01:43.494: E/AndroidRuntime(278):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-05 05:01:43.494: E/AndroidRuntime(278):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 05:01:43.494: E/AndroidRuntime(278):  at android.os.Looper.loop(Looper.java:123)
01-05 05:01:43.494: E/AndroidRuntime(278):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-05 05:01:43.494: E/AndroidRuntime(278):  at java.lang.reflect.Method.invokeNative(Native Method)
01-05 05:01:43.494: E/AndroidRuntime(278):  at java.lang.reflect.Method.invoke(Method.java:521)
01-05 05:01:43.494: E/AndroidRuntime(278):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-05 05:01:43.494: E/AndroidRuntime(278):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-05 05:01:43.494: E/AndroidRuntime(278):  at dalvik.system.NativeStart.main(Native Method)
01-05 05:01:43.494: E/AndroidRuntime(278): Caused by: java.lang.NullPointerException
01-05 05:01:43.494: E/AndroidRuntime(278):  at com.ringdroid.RingdroidSelectActivity.onCreate(RingdroidSelectActivity.java:109)
01-05 05:01:43.494: E/AndroidRuntime(278):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-05 05:01:43.494: E/AndroidRuntime(278):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-05 05:01:43.494: E/AndroidRuntime(278):  ... 11 more
01-05 05:01:45.614: I/Process(278): Sending signal. PID: 278 SIG: 9

1 个答案:

答案 0 :(得分:0)

您是否在AndroidManifest.xml中声明了新活动(RingdroidSelectActivity)? 如果你这样做,请在这里发布logCat。

编辑: 您在第109行的RingdroidSelectActivity的onCreate()中使用NullPointer时遇到问题

at com.ringdroid.RingdroidSelectActivity.onCreate(RingdroidSelectActivity.java:109)

如果您不知道问题,请发布此方法。