0

하나의 버튼으로 wake_lock을 시작하고 다른 버튼으로 끝내기 만하면됩니다. 그것은 내가 만드는 더 큰 응용 프로그램에서 사용하는 것이지만 이것은 문제가있는 부분입니다. 나는이 사이트와 다른 사람들을 쳐다 보았고 나를 위해 일하지 않는 모든 사람에게 똑같은 코드를 발견했다. - 내가 뭘 잘못하고 있니?Android : 내가 뭘 잘못하고 있니? 간단한 wake_lock 코드가 시작시 충돌합니다

내 자바 코드 :

package com.example.tester_app; 

import android.app.Activity; 
import android.content.Context; 
import android.os.Bundle; 
import android.os.PowerManager; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast; 

public class TestMain extends Activity { 

PowerManager.WakeLock wl; 
Button bstart, bstop; 

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

    //Views from xml 
    bstart = (Button) findViewById (R.id.bStart); 
    bstop = (Button) findViewById (R.id.bStop); 


    //power manager for wake lock.. 
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag"); 


    bstart.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View arg0) { 
      Toast.makeText(TestMain.this, "started", Toast.LENGTH_SHORT).show(); 
      wl.acquire(); //keeps cpu from sleeping 
     } 
    }); 

    bstop.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      Toast.makeText(TestMain.this, "stopped", Toast.LENGTH_SHORT).show(); 
      wl.release(); 
     } 
    }); 
} 
} 

내 XML 코드 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/main_layout_id" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="center" 
android:orientation="vertical" > 

<Button 
    android:id="@+id/bStart" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Start" /> 

<Button 
    android:id="@+id/bStop" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="12dp" 
    android:text="Stop" /> 

</LinearLayout> 

내 매니페스트 코드 :

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

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="15" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" ></uses-permission> 



<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".Main" 
     android:label="@string/title_activity_main" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

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

</manifest> 
+4

LogCat의 특정 오류에 대한 정보가 있습니까? – Blumer

답변

0

Activity 클래스의 이름이 매니페스트에서 지정한 이름과 다른 것 같습니다 (TestMain 대 Main). 둘 다 똑같은지 확인하십시오.

+0

thankyou. 나는 그 이름을 바꾸었고 그 명단을 잊었다! 그것은 나를 미치게했다 haha –

관련 문제