2013-11-19 4 views
0

Это ошибки, которые я получаю, когда пытаюсь запустить приложение. Может кто-нибудь увидеть, что я делаю неправильно?Невозможно начать работу - Ошибка ComponentInfo

LogCat

11-19 14:01:39.993: E/AndroidRuntime(4046): FATAL EXCEPTION: main 

11-19 14:01:39.993: E/AndroidRuntime(4046): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zimzux.soundapprhk/com.zimzux.soundapprhk.Start}: java.lang.NullPointerException 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at android.app.ActivityThread.access$600(ActivityThread.java:123) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at android.os.Handler.dispatchMessage(Handler.java:99) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at android.os.Looper.loop(Looper.java:137) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at android.app.ActivityThread.main(ActivityThread.java:4424) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at java.lang.reflect.Method.invokeNative(Native Method) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at java.lang.reflect.Method.invoke(Method.java:511) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at dalvik.system.NativeStart.main(Native Method) 

11-19 14:01:39.993: E/AndroidRuntime(4046): Caused by: java.lang.NullPointerException 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at com.zimzux.soundapprhk.Start.onCreate(Start.java:269) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at android.app.Activity.performCreate(Activity.java:4492) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 

11-19 14:01:39.993: E/AndroidRuntime(4046):  ... 11 more 

11-19 14:01:40.213: I/dalvikvm(4046): threadid=3: reacting to signal 3 

11-19 14:01:40.213: I/dalvikvm(4046): Wrote stack traces to '/data/anr/traces.txt' 

11-19 14:01:40.503: I/dalvikvm(4046): threadid=3: reacting to signal 3 

11-19 14:01:40.513: I/dalvikvm(4046): Wrote stack traces to '/data/anr/traces.txt' 

11-19 14:02:38.883: I/Process(4046): Sending signal. PID: 4046 SIG: 9 

Вот мой Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.zimzux.soundapprhk" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="11" 
     android:targetSdkVersion="18" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@android:style/Theme.NoTitleBar" > 

     <activity 
      android:name=".Opstart" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="com.zimzux.soundapprhk.OPSTART" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".Start" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="com.zimzux.soundapprhk.MAIN" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 


    </application> 
</manifest> 

Вот мой XML

Я использую в основном включают в себя, это легче для меня есть обзор.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#00A2E8" 
    android:gravity="center_vertical" 
    android:orientation="vertical" 
    android:scrollbars="vertical|horizontal" 
    tools:context=".MainActivity" 
    tools:ignore="SpUsage" > 

    <LinearLayout 
     android:id="@+id/top" 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="20" 
     android:layout_gravity="top" 
     android:background="#00A2E8" 
     android:gravity="center_horizontal" 
     android:layout_marginLeft="100dp" 
     android:orientation="vertical" > 

     <include 
      android:id="@+id/topbanner" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      layout="@layout/topbanner_xml" /> 
     <include 
      android:id="@+id/topbannerindstil" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      layout="@layout/topbanner_indstil_xml" /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/main" 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="100" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:layout_marginTop="5dp" 
     android:orientation="horizontal" > 

     <include 
      android:id="@+id/start" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      layout="@layout/mainstart_xml" /> 

     <include 
      android:id="@+id/afspilmain" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      layout="@layout/afspil_main_xml" />   

     <include 
      android:id="@+id/spilstopmain" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      layout="@layout/afspil_spilstop_xml" /> 
     <include 
      android:id="@+id/indstil" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      layout="@layout/indstil_xml" /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/bund" 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="25" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="10dp" 
     android:gravity="center" 
     android:orientation="horizontal" > 

     <include 
      android:id="@+id/bundbanner" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      layout="@layout/bundbanner_xml" /> 
     <include 
      android:id="@+id/bundbannerindstil" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      layout="@layout/bundbanner_indstil_xml" /> 

    </LinearLayout> 

</LinearLayout> 

Вот мой Java

Существует много findViewById для всех остальных XML.

package com.zimzux.soundapprhk; 

import android.app.Activity; 
import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.LinearLayout; 
import android.widget.TextView; 

public class Start extends Activity { 
    MediaPlayer mp1; 
    MediaPlayer mp2; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.start_xml); 


     final LinearLayout top = (LinearLayout) findViewById(R.id.top); 
     final LinearLayout bund = (LinearLayout) findViewById(R.id.bund); 
     final LinearLayout topbannerafspil = (LinearLayout) findViewById(R.id.topbanner); 
     final LinearLayout bundbannerafspil = (LinearLayout) findViewById(R.id.bundbanner); 
     final LinearLayout start = (LinearLayout) findViewById(R.id.start); 
     final LinearLayout afspil = (LinearLayout) findViewById(R.id.afspilmain); 
     final LinearLayout spilstop = (LinearLayout) findViewById(R.id.spilstopmain); 
     final LinearLayout indstil = (LinearLayout) findViewById(R.id.indstil); 
     final LinearLayout topbannerindstil = (LinearLayout) findViewById(R.id.topbannerindstil); 
     final LinearLayout bundbannerindstil = (LinearLayout) findViewById(R.id.bundbannerindstil); 

     ImageView btnstart = (ImageView) findViewById(R.id.btnstart); 
     ImageView btnindstil = (ImageView) findViewById(R.id.btnindstil); 
     @SuppressWarnings("unused") 
     TextView textnowpl = (TextView) findViewById(R.id.textnowpl); 

     Button btnscor = (Button) findViewById(R.id.btnscor); 
     Button btntimeout = (Button) findViewById(R.id.btntimeout); 
     Button btnudvisning = (Button) findViewById(R.id.btnudvisning); 
     Button btnstraffe = (Button) findViewById(R.id.btnstraffe); 
     Button btnindlob = (Button) findViewById(R.id.btnindlob); 
     Button btnopvarmning = (Button) findViewById(R.id.btnopvarmning); 
     Button btnhalvleg = (Button) findViewById(R.id.btnhalvleg); 
     Button btnnextsong = (Button) findViewById(R.id.btnnextsong); 
     Button btnspilstop = (Button) findViewById(R.id.btnspilstop); 

     Button btnbasic = (Button) findViewById(R.id.btnbasic); 
     Button btnspilswitchstop = (Button) findViewById(R.id.btnspilswitchstop); 
     Button btnfadeud = (Button) findViewById(R.id.btnfadeud); 
     Button btnstop = (Button) findViewById(R.id.btnstop); 

     Button spilstop1 = (Button) findViewById(R.id.spilstop1); 
     Button spilstop2 = (Button) findViewById(R.id.spilstop2); 
     Button spilstop3 = (Button) findViewById(R.id.spilstop3); 
     Button spilstop4 = (Button) findViewById(R.id.spilstop4); 
     Button spilstop5 = (Button) findViewById(R.id.spilstop5); 
     Button spilstop6 = (Button) findViewById(R.id.spilstop6); 
     Button spilstop7 = (Button) findViewById(R.id.spilstop7); 
     Button spilstop8 = (Button) findViewById(R.id.spilstop8); 
     Button spilstop9 = (Button) findViewById(R.id.spilstop9); 
     Button spilstop10 = (Button) findViewById(R.id.spilstop10); 
     Button spilstop11 = (Button) findViewById(R.id.spilstop11); 
     Button spilstop12 = (Button) findViewById(R.id.spilstop12); 
     Button spilstop13 = (Button) findViewById(R.id.spilstop13); 
     Button spilstop14 = (Button) findViewById(R.id.spilstop14); 
     Button spilstop15 = (Button) findViewById(R.id.spilstop15); 
     Button spilstop16 = (Button) findViewById(R.id.spilstop16); 




     top.setVisibility(View.GONE); 
     topbannerafspil.setVisibility(View.GONE); 
     topbannerindstil.setVisibility(View.GONE); 
     bund.setVisibility(View.GONE); 
     bundbannerafspil.setVisibility(View.GONE); 
     bundbannerindstil.setVisibility(View.GONE); 

     start.setVisibility(View.VISIBLE); 
     afspil.setVisibility(View.GONE); 
     spilstop.setVisibility(View.GONE); 
     indstil.setVisibility(View.GONE); 


     btnstart.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v){ 

       topbannerafspil.setVisibility(View.VISIBLE); 
       bundbannerafspil.setVisibility(View.VISIBLE); 
       start.setVisibility(View.GONE); 
       afspil.setVisibility(View.VISIBLE); 
       spilstop.setVisibility(View.GONE); 
       indstil.setVisibility(View.GONE); 
       topbannerindstil.setVisibility(View.GONE); 
       bundbannerindstil.setVisibility(View.GONE); 
       top.setVisibility(View.VISIBLE); 
       bund.setVisibility(View.VISIBLE); 
      }}); 

     btnindstil.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v){ 

       topbannerafspil.setVisibility(View.GONE); 
       bundbannerafspil.setVisibility(View.GONE); 
       start.setVisibility(View.GONE); 
       afspil.setVisibility(View.GONE); 
       spilstop.setVisibility(View.GONE); 
       indstil.setVisibility(View.VISIBLE); 
       topbannerindstil.setVisibility(View.VISIBLE); 
       bundbannerindstil.setVisibility(View.VISIBLE); 
       top.setVisibility(View.VISIBLE); 
       bund.setVisibility(View.VISIBLE); 
      }}); 

     btnbasic.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v){ 


       afspil.setVisibility(View.VISIBLE); 
       spilstop.setVisibility(View.GONE); 
      }}); 

     btnspilswitchstop.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v){ 


       afspil.setVisibility(View.GONE); 
       spilstop.setVisibility(View.VISIBLE); 
      }}); 
}} 
+0

что '269' Line в 'Start.java' –

+0

, поэтому вы объявляете и инициализируете переменные класса в начале вашего класса. Значит, вы никогда не получите нуль внутри своих методов? – bofredo

ответ

1

Ошибка возникает по строке 269? Я не могу определить, какая строка находится, когда вы предоставляете 135 строк в своем начальном действии.

Мое предположение, однако, заключается в том, что ваш метод findViewById ищет ресурс, который не существует. убедитесь, что ваш xml-тон содержит все кнопки/линейные макеты/изображения и т. д. и т. д., которые вы указываете в действии.

Если нет, то вам нужно объявить свои кнопки и т. Д. Как переменные класса, а затем инициализировать их в методе создания, позволяя доступ к дополнительным методам и внутренним классам.

+0

- это ответ? –

+1

Это потенциальное решение проблемы, нет? – doydoy

+0

Интересно, если это так ... :) –

0

Я проверил код, но линия Num не является правильным, причиной этой ошибки, безусловно, ясно, findViewById не найти вид идентификатора, пожалуйста, перепроверить код

Смежные вопросы