Проблема проста.
Два занятия. Один бросает намерение на другого.
Проект имеет название: "Stupidroid"
пакет: "com.examples.stupidroid"
активность: "stupidOnSteroids"
ниже - глупые стероиды .java
package com.examples.stupidroid;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class stupidOnSteroids extends Activity {
private Button buttonThatWillTakeYouPlacesButton;
private Intent intentThatwillTakeYouPlacesIntent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
InitLayouts();
InitSetOnClickListeners();
}
private void InitSetOnClickListeners() {
buttonThatWillTakeYouPlacesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
intentThatwillTakeYouPlacesIntent.setAction("");
}
});
}
private void InitLayouts() {
buttonThatWillTakeYouPlacesButton = (Button)findViewById(R.id.buttonThatWillGiveThyPowerButton);
intentThatwillTakeYouPlacesIntent = new Intent(stupidOnSteroids.this, Calc_print_codefile.class);
}
}
сейчас main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right"
>
<Button android:id="@+id/goToOtherMoronButton"
android:text="Next Activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></Button>
</LinearLayout>
теперь другой файл Java: Calc_print_codefile.java
package com.examples.stupidroid;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Calc_print_codefile extends Activity{
Button buttonThatWillHelpYouCalculateButton;
TextView textThatWillTakeTheHitText;
Button buttonThatWillTakeYouHomeButton;
Intent intentThatWillTakeYouHomeIntent;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.calc_prin_layout);
InitLayouts();
InitSetOnClickListener();
}
private void InitSetOnClickListener() {
buttonThatWillHelpYouCalculateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for(int i=0; i<32000; i++){
textThatWillTakeTheHitText.setText(i);
}
}
});
}
private void InitLayouts() {
buttonThatWillHelpYouCalculateButton = (Button)findViewById(R.id.buttonThatWillGiveThyPowerButton);
textThatWillTakeTheHitText = (TextView)findViewById(R.id.textThatWillAbsolveThyText);
intentThatWillTakeYouHomeIntent = new Intent(Calc_print_codefile.this, stupidOnSteroids.class);
}
}
соответствующий xml: calc_prin_layout.xml
<?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">
<TextView android:id="@+id/textThatWillAbsolveThyText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" "
/>
<Button android:id="@+id/buttonThatWillGiveThyPowerButton"
android:text="Press ME, hard!"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
</LinearLayout>
ниже AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.examples.stupidroid"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".stupidOnSteroids"
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="Calc_print_codefile"></activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
Вот изображения (на самом деле только одно):
![Crashing even before running](https://i.stack.imgur.com/NwCrG.png)
теперь информация от DDMS
07-29 14:13:31.344: WARN/ActivityThread(379): Application com.examples.stupidroid is waiting for the debugger on port 8100...
07-29 14:13:31.374: INFO/System.out(379): Sending WAIT chunk
07-29 14:13:31.434: INFO/dalvikvm(379): Debugger is active
07-29 14:13:31.594: INFO/System.out(379): Debugger has connected
07-29 14:13:31.604: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:31.804: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:31.824: DEBUG/dalvikvm(33): GC_EXPLICIT freed 2 objects / 64 bytes in 556ms
07-29 14:13:32.038: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:32.296: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:32.444: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{440534a8 com.examples.stupidroid/.stupidOnSteroids}
07-29 14:13:32.494: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:32.694: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:32.894: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:33.113: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:33.356: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:33.574: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:33.795: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:34.008: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:34.215: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:34.423: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:34.634: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:34.868: INFO/System.out(379): debugger has settled (1504)
07-29 14:13:40.587: WARN/ActivityManager(60): Launch timeout has expired, giving up wake lock!
07-29 14:13:41.254: WARN/ActivityManager(60): Activity idle timeout for HistoryRecord{44078b28 com.examples.stupidroid/.stupidOnSteroids}
07-29 14:13:46.454: DEBUG/dalvikvm(135): GC_EXPLICIT freed 1190 objects / 62584 bytes in 179ms
07-29 14:13:57.363: DEBUG/dalvikvm(60): GC_FOR_MALLOC freed 12320 objects / 698248 bytes in 153ms
07-29 14:13:58.423: DEBUG/AndroidRuntime(379): Shutting down VM
07-29 14:13:58.423: WARN/dalvikvm(379): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
**07-29 14:13:58.543: ERROR/AndroidRuntime(379): FATAL EXCEPTION: main
07-29 14:13:58.543: ERROR/AndroidRuntime(379): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.examples.stupidroid/com.examples.stupidroid.stupidOnSteroids}: java.lang.NullPointerException**
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at android.os.Handler.dispatchMessage(Handler.java:99)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at android.os.Looper.loop(Looper.java:123)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at java.lang.reflect.Method.invokeNative(Native Method)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at java.lang.reflect.Method.invoke(Method.java:521)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at dalvik.system.NativeStart.main(Native Method)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): Caused by: java.lang.NullPointerException
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at com.examples.stupidroid.stupidOnSteroids.InitSetOnClickListeners(stupidOnSteroids.java:20)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at com.examples.stupidroid.stupidOnSteroids.onCreate(stupidOnSteroids.java:17)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): ... 11 more
07-29 14:13:58.613: WARN/ActivityManager(60): Force finishing activity com.examples.stupidroid/.stupidOnSteroids
07-29 14:13:59.128: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{44078b28 com.examples.stupidroid/.stupidOnSteroids}
07-29 14:14:09.273: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{44078b28 com.examples.stupidroid/.stupidOnSteroids}
07-29 14:14:13.443: INFO/Process(379): Sending signal. PID: 379 SIG: 9
07-29 14:14:13.465: INFO/ActivityManager(60): Process com.examples.stupidroid (pid 379) has died.
07-29 14:14:13.483: WARN/InputManagerService(60): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43ef9a68
Пожалуйста, скажите мне, что я могу сделать? Я следовал тому же подходу, за которым следовал другой парень. Мой другой проект работает. что это может быть? это неправильная номенклатура или что?
Из моего прошлого опыта это выглядит как очень маленькая очень узкая ошибка, может быть глупой, но я все еще не могу понять, как это сделать.
Спасибо, что потратили время на чтение этого.
И, если я удалю InitSetOnClickListeners (); из файла stupidOnSteroids.java я могу хотя бы увидеть кнопку. Таким образом, может быть ошибка.