2

申し訳ありませんが、アプリがクラッシュする理由がわかりません。マップフラグメントとボタンを使用してアクティビティを作成したので、非常に単純ですが、アプリを起動するとクラッシュし、logcat から次のエラーが送信されます。

07-29 15:32:18.678: E/AndroidRuntime(6806): FATAL EXCEPTION: main
07-29 15:32:18.678: E/AndroidRuntime(6806): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.frank.nuova/com.frank.nuova.Online}: java.lang.NullPointerException
07-29 15:32:18.678: E/AndroidRuntime(6806):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at android.os.Handler.dispatchMessage(Handler.java:99)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at android.os.Looper.loop(Looper.java:137)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at android.app.ActivityThread.main(ActivityThread.java:5041)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at java.lang.reflect.Method.invokeNative(Native Method)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at java.lang.reflect.Method.invoke(Method.java:511)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at dalvik.system.NativeStart.main(Native Method)
07-29 15:32:18.678: E/AndroidRuntime(6806): Caused by: java.lang.NullPointerException
07-29 15:32:18.678: E/AndroidRuntime(6806):         at com.frank.nuova.Online.onCreate(Online.java:51)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at android.app.Activity.performCreate(Activity.java:5104)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-29 15:32:18.678: E/AndroidRuntime(6806):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-29 15:32:18.678: E/AndroidRuntime(6806):         ... 11 more

マニフェストは問題ありません。すべてのアクセス許可と API キーを既に入れています...アプリをデバッグして、最初のステップで提供しようとしています

ActivityThread.performLaunchActivity ソースが見つかりません

そして二段目

ZygoteInit$MethodAndArgsCaller.run() line: 799 source not found

このエラーが表示される理由がわかりません。また、このエラーとは何ですか?

これは私のコード

package com.frank.nuova;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Online extends FragmentActivity {
    GoogleMap map;
    Gps s;
    DataSource db;
    MyOpenHelper o;
    LatLng adesso;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            o=new MyOpenHelper(getApplicationContext());
            db=new DataSource(o);
            try{
                o.createDataBase();
            }catch(IOException e){
                e.printStackTrace();
            }
            try{
                o.openDataBase();
            }catch(SQLException e){
                e.printStackTrace();
            }
            double lon;
            double lat;
            s=new Gps(getApplicationContext());
            s.getLocation();
            lon=s.longitudine();
            lat=s.latitudine();
            adesso=new LatLng(lat, lon);
            map=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mappa)).getMap(); 
            Marker posizione=map.addMarker(new MarkerOptions().position(adesso).title("Sei Qui"));
            Button b=(Button) findViewById(R.id.button1);
            b.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    List<Coordinate> b=db.vicino_online(adesso, db.vediCoordinate());
                    Marker[]a=new Marker[b.size()];
                    for(int i=0;i<a.length;i++){
                        String linea=b.get(i).getLinea()+"-"+b.get(i).getVia();
                        a[i]=map.addMarker(new MarkerOptions().position(new LatLng(b.get(i).getLatitudine(), b.get(i).getLongitudine())).title(linea));

                    }
                }
            });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
    }
}

if(map==null)また、GoogleMapを開始する前に配置しようとしましたが、同じエラーが発生しました...


コード:

package com.frank.nuova;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Online extends FragmentActivity {
    GoogleMap map;
    Gps s;
    DataSource db;
    MyOpenHelper o;
    LatLng adesso;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            o=new MyOpenHelper(getApplicationContext());
            db=new DataSource(o);
            try{
                o.createDataBase();
            }catch(IOException e){
                e.printStackTrace();
            }
            try{
                o.openDataBase();
            }catch(SQLException e){
                e.printStackTrace();
            }
            double lon;
            double lat;
            s=new Gps(getApplicationContext());
            s.getLocation();
            lon=s.longitudine();
            lat=s.latitudine();
            adesso=new LatLng(lat, lon);
            map=((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mappa)).getMap();
            Button b=(Button) findViewById(R.id.button1);
            b.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    List<Coordinate> b=db.vicino_online(adesso, db.vediCoordinate());
                    Marker[]a=new Marker[b.size()];
                    for(int i=0;i<a.length;i++){
                        String linea=b.get(i).getLinea()+"-"+b.get(i).getVia();
                        a[i]=map.addMarker(new MarkerOptions().position(new LatLng(b.get(i).getLatitudine(), b.get(i).getLongitudine())).title(linea));

                    }
                }
            });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
    }
}

ログキャット:

07-30 11:02:16.289: E/AndroidRuntime(23018): FATAL EXCEPTION: main
07-30 11:02:16.289: E/AndroidRuntime(23018): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.frank.nuova/com.frank.nuova.Online}: java.lang.NullPointerException
07-30 11:02:16.289: E/AndroidRuntime(23018):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at android.os.Looper.loop(Looper.java:137)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at android.app.ActivityThread.main(ActivityThread.java:5041)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at java.lang.reflect.Method.invokeNative(Native Method)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at java.lang.reflect.Method.invoke(Method.java:511)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at dalvik.system.NativeStart.main(Native Method)
07-30 11:02:16.289: E/AndroidRuntime(23018): Caused by: java.lang.NullPointerException
07-30 11:02:16.289: E/AndroidRuntime(23018):    at com.frank.nuova.Online.onCreate(Online.java:49)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at android.app.Activity.performCreate(Activity.java:5104)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-30 11:02:16.289: E/AndroidRuntime(23018):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-30 11:02:16.289: E/AndroidRuntime(23018):    ... 11 more

レイアウト:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/prima"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <fragment
        android:id="@+id/mappa"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="260dp" />

    <Button
        android:id="@+id/button1"
        android:layout_width="350dp"
        android:layout_height="wrap_content"
        android:text="@string/premi" />

</LinearLayout>
4

1 に答える 1

0

あります。レイアウトにidがある ことを確認して NullPointerExceptionくださいb.setOnClickListener
Buttonbutton1activity_main

于 2013-07-30T08:59:12.673 に答える